@usherlabs/cex-broker 0.2.40 → 0.2.41
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.
- package/dist/commands/cli.js +291 -42
- package/dist/helpers/broker-execution-archive/writer.d.ts +30 -0
- package/dist/index.js +291 -42
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,25 +4,43 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
22
|
for (let key of __getOwnPropNames(mod))
|
|
11
23
|
if (!__hasOwnProp.call(to, key))
|
|
12
24
|
__defProp(to, key, {
|
|
13
|
-
get: (
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
14
26
|
enumerable: true
|
|
15
27
|
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
16
30
|
return to;
|
|
17
31
|
};
|
|
18
32
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __returnValue = (v) => v;
|
|
34
|
+
function __exportSetter(name, newValue) {
|
|
35
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
36
|
+
}
|
|
19
37
|
var __export = (target, all) => {
|
|
20
38
|
for (var name in all)
|
|
21
39
|
__defProp(target, name, {
|
|
22
40
|
get: all[name],
|
|
23
41
|
enumerable: true,
|
|
24
42
|
configurable: true,
|
|
25
|
-
set: (
|
|
43
|
+
set: __exportSetter.bind(all, name)
|
|
26
44
|
});
|
|
27
45
|
};
|
|
28
46
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
@@ -26363,7 +26381,7 @@ var require_tracestate_impl = __commonJS((exports) => {
|
|
|
26363
26381
|
const value = listMember.slice(i2 + 1, part.length);
|
|
26364
26382
|
if ((0, tracestate_validators_1.validateKey)(key) && (0, tracestate_validators_1.validateValue)(value)) {
|
|
26365
26383
|
agg.set(key, value);
|
|
26366
|
-
}
|
|
26384
|
+
}
|
|
26367
26385
|
}
|
|
26368
26386
|
return agg;
|
|
26369
26387
|
}, new Map);
|
|
@@ -35496,7 +35514,7 @@ var require_TraceState = __commonJS((exports) => {
|
|
|
35496
35514
|
const value = listMember.slice(i2 + 1, part.length);
|
|
35497
35515
|
if ((0, validators_1.validateKey)(key) && (0, validators_1.validateValue)(value)) {
|
|
35498
35516
|
agg.set(key, value);
|
|
35499
|
-
}
|
|
35517
|
+
}
|
|
35500
35518
|
}
|
|
35501
35519
|
return agg;
|
|
35502
35520
|
}, new Map);
|
|
@@ -291220,7 +291238,9 @@ function buildMarketMetadataSnapshotRow(input) {
|
|
|
291220
291238
|
// src/helpers/broker-execution-archive/writer.ts
|
|
291221
291239
|
var import_api_logs2 = __toESM(require_src4(), 1);
|
|
291222
291240
|
import { closeSync, fsyncSync, openSync, writeSync } from "node:fs";
|
|
291223
|
-
import {
|
|
291241
|
+
import {
|
|
291242
|
+
request as httpRequest2
|
|
291243
|
+
} from "node:http";
|
|
291224
291244
|
import { request as httpsRequest2 } from "node:https";
|
|
291225
291245
|
var BROKER_EXECUTION_ARCHIVE_TABLES = new Set([
|
|
291226
291246
|
"broker_execution.order_events",
|
|
@@ -291293,6 +291313,7 @@ class BrokerExecutionArchiver {
|
|
|
291293
291313
|
flushIntervalMs;
|
|
291294
291314
|
forwarderTimeoutMs;
|
|
291295
291315
|
queue = [];
|
|
291316
|
+
enqueueTimes = new WeakMap;
|
|
291296
291317
|
stats = {
|
|
291297
291318
|
enqueued: 0,
|
|
291298
291319
|
shed: 0,
|
|
@@ -291301,6 +291322,16 @@ class BrokerExecutionArchiver {
|
|
|
291301
291322
|
};
|
|
291302
291323
|
flushTimer = null;
|
|
291303
291324
|
flushInFlight = null;
|
|
291325
|
+
inFlightBatch = null;
|
|
291326
|
+
inFlightStartedAtMs = null;
|
|
291327
|
+
lastFailureAtMs = null;
|
|
291328
|
+
lastShedAtMs = null;
|
|
291329
|
+
lastSuccessAtMs = null;
|
|
291330
|
+
lastFailureEventSequence = null;
|
|
291331
|
+
lastShedEventSequence = null;
|
|
291332
|
+
lastSuccessEventSequence = null;
|
|
291333
|
+
lastSinkLatencyMs = null;
|
|
291334
|
+
healthEventSequence = 0;
|
|
291304
291335
|
lastShedWarnAtMs = 0;
|
|
291305
291336
|
closing = false;
|
|
291306
291337
|
closed = false;
|
|
@@ -291334,6 +291365,7 @@ class BrokerExecutionArchiver {
|
|
|
291334
291365
|
}
|
|
291335
291366
|
try {
|
|
291336
291367
|
this.flushTimer = setInterval(() => {
|
|
291368
|
+
this.emitArchiveHealthMetrics();
|
|
291337
291369
|
this.flush();
|
|
291338
291370
|
}, this.flushIntervalMs);
|
|
291339
291371
|
this.flushTimer.unref?.();
|
|
@@ -291377,32 +291409,34 @@ class BrokerExecutionArchiver {
|
|
|
291377
291409
|
row: { ...row.row, source: this.source }
|
|
291378
291410
|
};
|
|
291379
291411
|
if (this.queue.length >= this.maxQueueSize) {
|
|
291380
|
-
const
|
|
291381
|
-
if (
|
|
291382
|
-
this.appendLossRecords([
|
|
291412
|
+
const shedEntry = this.queue[0];
|
|
291413
|
+
if (shedEntry) {
|
|
291414
|
+
this.appendLossRecords([shedEntry], "queue_shed");
|
|
291383
291415
|
this.queue.shift();
|
|
291384
291416
|
}
|
|
291385
291417
|
this.stats.shed += 1;
|
|
291418
|
+
this.recordHealthEvent("shed");
|
|
291386
291419
|
this.recordArchiveMetric("cex_archive_rows_shed_total", {
|
|
291387
|
-
table:
|
|
291420
|
+
table: shedEntry?.table ?? "unknown",
|
|
291388
291421
|
source: this.source,
|
|
291389
|
-
feed:
|
|
291422
|
+
feed: shedEntry ? archiveFeed(shedEntry) : "NON_MARKET"
|
|
291390
291423
|
});
|
|
291391
291424
|
this.recordArchiveMetric("cex_archive_queue_saturated_rows_total", {
|
|
291392
|
-
table:
|
|
291425
|
+
table: shedEntry?.table ?? "unknown",
|
|
291393
291426
|
source: this.source,
|
|
291394
|
-
feed:
|
|
291427
|
+
feed: shedEntry ? archiveFeed(shedEntry) : "NON_MARKET"
|
|
291395
291428
|
});
|
|
291396
291429
|
const now3 = Date.now();
|
|
291397
291430
|
if (now3 - this.lastShedWarnAtMs >= SHED_WARN_INTERVAL_MS) {
|
|
291398
291431
|
log.warn("Archive queue full: shedding oldest rows", {
|
|
291399
291432
|
shed_total: this.stats.shed,
|
|
291400
291433
|
queue_max: this.maxQueueSize,
|
|
291401
|
-
table:
|
|
291434
|
+
table: shedEntry?.table ?? "unknown"
|
|
291402
291435
|
});
|
|
291403
291436
|
this.lastShedWarnAtMs = now3;
|
|
291404
291437
|
}
|
|
291405
291438
|
}
|
|
291439
|
+
this.enqueueTimes.set(archiveRow, Date.now());
|
|
291406
291440
|
this.queue.push(archiveRow);
|
|
291407
291441
|
this.stats.enqueued += 1;
|
|
291408
291442
|
this.recordArchiveMetric("cex_archive_rows_enqueued_total", {
|
|
@@ -291410,6 +291444,7 @@ class BrokerExecutionArchiver {
|
|
|
291410
291444
|
source: this.source,
|
|
291411
291445
|
feed: archiveFeed(archiveRow)
|
|
291412
291446
|
});
|
|
291447
|
+
this.emitArchiveHealthMetrics();
|
|
291413
291448
|
if (this.queue.length >= this.batchSize) {
|
|
291414
291449
|
this.flush();
|
|
291415
291450
|
}
|
|
@@ -291424,14 +291459,19 @@ class BrokerExecutionArchiver {
|
|
|
291424
291459
|
if (this.flushInFlight) {
|
|
291425
291460
|
return this.flushInFlight;
|
|
291426
291461
|
}
|
|
291462
|
+
const inFlightState = {};
|
|
291427
291463
|
const inFlight = this.flushBatch().then(() => {
|
|
291428
291464
|
return;
|
|
291429
291465
|
}).finally(() => {
|
|
291466
|
+
if (this.flushInFlight !== inFlightState.promise) {
|
|
291467
|
+
return;
|
|
291468
|
+
}
|
|
291430
291469
|
this.flushInFlight = null;
|
|
291431
291470
|
if (!this.closed && !this.closing && this.enabled && this.queue.length >= this.batchSize) {
|
|
291432
291471
|
queueMicrotask(() => void this.flush());
|
|
291433
291472
|
}
|
|
291434
291473
|
});
|
|
291474
|
+
inFlightState.promise = inFlight;
|
|
291435
291475
|
this.flushInFlight = inFlight;
|
|
291436
291476
|
return inFlight;
|
|
291437
291477
|
}
|
|
@@ -291478,6 +291518,79 @@ class BrokerExecutionArchiver {
|
|
|
291478
291518
|
getQueueDepth() {
|
|
291479
291519
|
return this.queue.length;
|
|
291480
291520
|
}
|
|
291521
|
+
getHealthSnapshot() {
|
|
291522
|
+
const now3 = Date.now();
|
|
291523
|
+
const oldestPendingAtMs = this.oldestPendingEnqueueAtMs();
|
|
291524
|
+
const oldestPendingAgeMs = oldestPendingAtMs === null ? 0 : Math.max(0, now3 - oldestPendingAtMs);
|
|
291525
|
+
const inFlightAgeMs = this.inFlightStartedAtMs === null ? 0 : Math.max(0, now3 - this.inFlightStartedAtMs);
|
|
291526
|
+
const lastUnhealthyEventSequence = Math.max(this.lastFailureEventSequence ?? Number.NEGATIVE_INFINITY, this.lastShedEventSequence ?? Number.NEGATIVE_INFINITY);
|
|
291527
|
+
const recoveredFromEvents = lastUnhealthyEventSequence === Number.NEGATIVE_INFINITY || this.lastSuccessEventSequence !== null && this.lastSuccessEventSequence > lastUnhealthyEventSequence;
|
|
291528
|
+
const healthy = this.enabled && !this.closing && !this.closed && this.queue.length < this.maxQueueSize && oldestPendingAgeMs <= this.forwarderTimeoutMs && inFlightAgeMs <= this.forwarderTimeoutMs && recoveredFromEvents;
|
|
291529
|
+
return {
|
|
291530
|
+
healthy,
|
|
291531
|
+
queue_depth: this.queue.length,
|
|
291532
|
+
oldest_pending_age_ms: oldestPendingAgeMs,
|
|
291533
|
+
shed_total: this.stats.shed,
|
|
291534
|
+
last_failure_at: this.lastFailureAtMs,
|
|
291535
|
+
last_shed_at: this.lastShedAtMs,
|
|
291536
|
+
last_success_at: this.lastSuccessAtMs,
|
|
291537
|
+
sink_latency_ms: this.lastSinkLatencyMs,
|
|
291538
|
+
sink_errors_total: this.stats.forwarderFailures,
|
|
291539
|
+
in_flight: this.inFlightBatch !== null,
|
|
291540
|
+
in_flight_age_ms: inFlightAgeMs
|
|
291541
|
+
};
|
|
291542
|
+
}
|
|
291543
|
+
oldestPendingEnqueueAtMs() {
|
|
291544
|
+
let oldest = null;
|
|
291545
|
+
for (const entry of this.queue) {
|
|
291546
|
+
const enqueuedAtMs = this.enqueueTimes.get(entry);
|
|
291547
|
+
if (enqueuedAtMs === undefined) {
|
|
291548
|
+
continue;
|
|
291549
|
+
}
|
|
291550
|
+
oldest = oldest === null ? enqueuedAtMs : Math.min(oldest, enqueuedAtMs);
|
|
291551
|
+
}
|
|
291552
|
+
for (const entry of this.inFlightBatch ?? []) {
|
|
291553
|
+
const enqueuedAtMs = this.enqueueTimes.get(entry);
|
|
291554
|
+
if (enqueuedAtMs === undefined) {
|
|
291555
|
+
continue;
|
|
291556
|
+
}
|
|
291557
|
+
oldest = oldest === null ? enqueuedAtMs : Math.min(oldest, enqueuedAtMs);
|
|
291558
|
+
}
|
|
291559
|
+
return oldest;
|
|
291560
|
+
}
|
|
291561
|
+
recordHealthEvent(event) {
|
|
291562
|
+
const eventSequence = ++this.healthEventSequence;
|
|
291563
|
+
const eventTimestampMs = Date.now();
|
|
291564
|
+
switch (event) {
|
|
291565
|
+
case "failure":
|
|
291566
|
+
this.lastFailureAtMs = eventTimestampMs;
|
|
291567
|
+
this.lastFailureEventSequence = eventSequence;
|
|
291568
|
+
return;
|
|
291569
|
+
case "shed":
|
|
291570
|
+
this.lastShedAtMs = eventTimestampMs;
|
|
291571
|
+
this.lastShedEventSequence = eventSequence;
|
|
291572
|
+
return;
|
|
291573
|
+
case "success":
|
|
291574
|
+
this.lastSuccessAtMs = eventTimestampMs;
|
|
291575
|
+
this.lastSuccessEventSequence = eventSequence;
|
|
291576
|
+
return;
|
|
291577
|
+
}
|
|
291578
|
+
}
|
|
291579
|
+
emitArchiveHealthMetrics() {
|
|
291580
|
+
const snapshot = this.getHealthSnapshot();
|
|
291581
|
+
const labels = { source: this.source };
|
|
291582
|
+
this.recordArchiveObservableGauge("cex_archive_health", snapshot.healthy ? 1 : 0, labels);
|
|
291583
|
+
this.recordArchiveGauge("cex_archive_queue_depth", snapshot.queue_depth, labels);
|
|
291584
|
+
this.recordArchiveGauge("cex_archive_oldest_pending_age_ms", snapshot.oldest_pending_age_ms, labels);
|
|
291585
|
+
this.recordArchiveGauge("cex_archive_shed_total", snapshot.shed_total, labels);
|
|
291586
|
+
this.recordArchiveGauge("cex_archive_last_failure_at", snapshot.last_failure_at ?? 0, labels);
|
|
291587
|
+
this.recordArchiveGauge("cex_archive_last_shed_at", snapshot.last_shed_at ?? 0, labels);
|
|
291588
|
+
this.recordArchiveGauge("cex_archive_last_success_at", snapshot.last_success_at ?? 0, labels);
|
|
291589
|
+
this.recordArchiveGauge("cex_archive_sink_latency_ms", snapshot.sink_latency_ms ?? 0, labels);
|
|
291590
|
+
this.recordArchiveGauge("cex_archive_sink_errors_total", snapshot.sink_errors_total, labels);
|
|
291591
|
+
this.recordArchiveGauge("cex_archive_in_flight", snapshot.in_flight ? 1 : 0, labels);
|
|
291592
|
+
this.recordArchiveGauge("cex_archive_in_flight_age_ms", snapshot.in_flight_age_ms, labels);
|
|
291593
|
+
}
|
|
291481
291594
|
closeLossJournal() {
|
|
291482
291595
|
if (this.deadLetterFd === undefined) {
|
|
291483
291596
|
return;
|
|
@@ -291500,8 +291613,9 @@ class BrokerExecutionArchiver {
|
|
|
291500
291613
|
this.appendLossRecords([dropped], "queue_shed");
|
|
291501
291614
|
this.queue.shift();
|
|
291502
291615
|
this.stats.shed += 1;
|
|
291616
|
+
this.recordHealthEvent("shed");
|
|
291503
291617
|
this.recordArchiveMetric("cex_archive_rows_shed_total", {
|
|
291504
|
-
table: dropped
|
|
291618
|
+
table: dropped.table,
|
|
291505
291619
|
source: this.source,
|
|
291506
291620
|
feed: archiveFeed(dropped)
|
|
291507
291621
|
});
|
|
@@ -291560,6 +291674,8 @@ class BrokerExecutionArchiver {
|
|
|
291560
291674
|
if (batch.length === 0) {
|
|
291561
291675
|
return true;
|
|
291562
291676
|
}
|
|
291677
|
+
this.inFlightBatch = batch;
|
|
291678
|
+
this.inFlightStartedAtMs = Date.now();
|
|
291563
291679
|
for (const entry of batch) {
|
|
291564
291680
|
if (isBrokerExecutionArchiveTable(entry.table)) {
|
|
291565
291681
|
this.emitOtelLog(entry);
|
|
@@ -291570,8 +291686,15 @@ class BrokerExecutionArchiver {
|
|
|
291570
291686
|
await this.postToForwarder(batch);
|
|
291571
291687
|
} catch (error) {
|
|
291572
291688
|
this.stats.forwarderFailures += 1;
|
|
291573
|
-
this.
|
|
291574
|
-
this.
|
|
291689
|
+
this.recordHealthEvent("failure");
|
|
291690
|
+
this.lastSinkLatencyMs = Math.max(0, Date.now() - (this.inFlightStartedAtMs ?? Date.now()));
|
|
291691
|
+
this.queue.unshift(...batch);
|
|
291692
|
+
try {
|
|
291693
|
+
this.enforceQueueBound();
|
|
291694
|
+
} finally {
|
|
291695
|
+
this.clearInFlightBatch(batch);
|
|
291696
|
+
this.emitArchiveHealthMetrics();
|
|
291697
|
+
}
|
|
291575
291698
|
this.recordArchiveMetric("cex_archive_forwarder_failures_total", {
|
|
291576
291699
|
count: batch.length
|
|
291577
291700
|
});
|
|
@@ -291580,14 +291703,26 @@ class BrokerExecutionArchiver {
|
|
|
291580
291703
|
}
|
|
291581
291704
|
}
|
|
291582
291705
|
this.stats.flushed += batch.length;
|
|
291706
|
+
this.recordHealthEvent("success");
|
|
291707
|
+
this.lastSinkLatencyMs = Math.max(0, Date.now() - (this.inFlightStartedAtMs ?? Date.now()));
|
|
291708
|
+
this.clearInFlightBatch(batch);
|
|
291583
291709
|
this.recordFlushHealth(batch);
|
|
291710
|
+
this.emitArchiveHealthMetrics();
|
|
291584
291711
|
return true;
|
|
291585
291712
|
}
|
|
291713
|
+
clearInFlightBatch(batch) {
|
|
291714
|
+
if (this.inFlightBatch !== batch) {
|
|
291715
|
+
return;
|
|
291716
|
+
}
|
|
291717
|
+
this.inFlightBatch = null;
|
|
291718
|
+
this.inFlightStartedAtMs = null;
|
|
291719
|
+
}
|
|
291586
291720
|
recordFlushHealth(batch) {
|
|
291587
291721
|
const countByTable = new Map;
|
|
291588
291722
|
for (const entry of batch) {
|
|
291589
|
-
const
|
|
291590
|
-
const
|
|
291723
|
+
const row = entry;
|
|
291724
|
+
const key = `${row.table}\x00${archiveFeed(row)}`;
|
|
291725
|
+
const grouped = countByTable.get(key) ?? { row, count: 0 };
|
|
291591
291726
|
grouped.count += 1;
|
|
291592
291727
|
countByTable.set(key, grouped);
|
|
291593
291728
|
}
|
|
@@ -291605,9 +291740,14 @@ class BrokerExecutionArchiver {
|
|
|
291605
291740
|
await this.otelMetrics?.recordCounter(metricName, value, labels);
|
|
291606
291741
|
} catch {}
|
|
291607
291742
|
}
|
|
291608
|
-
async recordArchiveGauge(metricName, value) {
|
|
291743
|
+
async recordArchiveGauge(metricName, value, labels = {}) {
|
|
291609
291744
|
try {
|
|
291610
|
-
await this.otelMetrics?.recordGauge(metricName, value,
|
|
291745
|
+
await this.otelMetrics?.recordGauge(metricName, value, labels);
|
|
291746
|
+
} catch {}
|
|
291747
|
+
}
|
|
291748
|
+
async recordArchiveObservableGauge(metricName, value, labels) {
|
|
291749
|
+
try {
|
|
291750
|
+
await this.otelMetrics?.setObservableGauge(metricName, value, labels);
|
|
291611
291751
|
} catch {}
|
|
291612
291752
|
}
|
|
291613
291753
|
emitOtelLog(entry) {
|
|
@@ -291644,27 +291784,136 @@ class BrokerExecutionArchiver {
|
|
|
291644
291784
|
headers.authorization = `Bearer ${this.forwarderAuthToken}`;
|
|
291645
291785
|
}
|
|
291646
291786
|
return new Promise((resolve, reject) => {
|
|
291647
|
-
|
|
291648
|
-
|
|
291649
|
-
|
|
291650
|
-
|
|
291651
|
-
|
|
291652
|
-
|
|
291653
|
-
|
|
291654
|
-
|
|
291655
|
-
|
|
291656
|
-
|
|
291657
|
-
|
|
291658
|
-
|
|
291787
|
+
let req;
|
|
291788
|
+
let response;
|
|
291789
|
+
let settled = false;
|
|
291790
|
+
let requestClosed = false;
|
|
291791
|
+
let requestCloseFailureScheduled = false;
|
|
291792
|
+
let responseClosed = false;
|
|
291793
|
+
let responseEnded = false;
|
|
291794
|
+
let outerTimer;
|
|
291795
|
+
function cleanupRequestListeners() {
|
|
291796
|
+
req?.removeListener("error", onRequestError);
|
|
291797
|
+
req?.removeListener("timeout", onRequestTimeout);
|
|
291798
|
+
req?.removeListener("close", onRequestClose);
|
|
291799
|
+
}
|
|
291800
|
+
function cleanupResponseListeners() {
|
|
291801
|
+
response?.removeListener("data", onResponseData);
|
|
291802
|
+
response?.removeListener("end", onResponseEnd);
|
|
291803
|
+
response?.removeListener("aborted", onResponseAborted);
|
|
291804
|
+
response?.removeListener("error", onResponseError);
|
|
291805
|
+
response?.removeListener("close", onResponseClose);
|
|
291806
|
+
}
|
|
291807
|
+
function onRequestClose() {
|
|
291808
|
+
requestClosed = true;
|
|
291809
|
+
if (!settled && !response && !requestCloseFailureScheduled) {
|
|
291810
|
+
requestCloseFailureScheduled = true;
|
|
291811
|
+
queueMicrotask(() => {
|
|
291812
|
+
if (!settled && !response) {
|
|
291813
|
+
settle2(new Error("Archive forwarder request closed before response headers"), false, true);
|
|
291814
|
+
}
|
|
291815
|
+
});
|
|
291816
|
+
}
|
|
291817
|
+
if (settled) {
|
|
291818
|
+
cleanupRequestListeners();
|
|
291819
|
+
}
|
|
291820
|
+
}
|
|
291821
|
+
function onRequestError(error) {
|
|
291822
|
+
if (!settled) {
|
|
291823
|
+
settle2(error, true);
|
|
291824
|
+
} else {
|
|
291825
|
+
cleanupRequestListeners();
|
|
291826
|
+
}
|
|
291827
|
+
}
|
|
291828
|
+
function onRequestTimeout() {
|
|
291829
|
+
settle2(new Error("Archive forwarder socket timed out"), true);
|
|
291830
|
+
}
|
|
291831
|
+
function onResponseData() {}
|
|
291832
|
+
function onResponseEnd() {
|
|
291833
|
+
responseEnded = true;
|
|
291834
|
+
if (!response?.complete) {
|
|
291835
|
+
settle2(new Error("Archive forwarder response was incomplete"), true);
|
|
291836
|
+
return;
|
|
291837
|
+
}
|
|
291838
|
+
const status = response.statusCode ?? 0;
|
|
291839
|
+
if (status < 200 || status >= 300) {
|
|
291840
|
+
settle2(new Error(`Archive forwarder returned ${status} ${response.statusMessage ?? ""}`), false);
|
|
291841
|
+
return;
|
|
291842
|
+
}
|
|
291843
|
+
settle2(undefined, false);
|
|
291844
|
+
}
|
|
291845
|
+
function onResponseAborted() {
|
|
291846
|
+
settle2(new Error("Archive forwarder response was aborted"), true);
|
|
291847
|
+
}
|
|
291848
|
+
function onResponseError(error) {
|
|
291849
|
+
if (!settled) {
|
|
291850
|
+
settle2(error, true);
|
|
291851
|
+
}
|
|
291852
|
+
}
|
|
291853
|
+
function onResponseClose() {
|
|
291854
|
+
responseClosed = true;
|
|
291855
|
+
if (!settled && !responseEnded) {
|
|
291856
|
+
settle2(new Error("Archive forwarder response closed before completion"), true);
|
|
291857
|
+
return;
|
|
291858
|
+
}
|
|
291859
|
+
cleanupResponseListeners();
|
|
291860
|
+
}
|
|
291861
|
+
function settle2(error, destroyRequest, retainClosedRequestError = false) {
|
|
291862
|
+
if (settled) {
|
|
291863
|
+
return;
|
|
291864
|
+
}
|
|
291865
|
+
settled = true;
|
|
291866
|
+
if (outerTimer) {
|
|
291867
|
+
clearTimeout(outerTimer);
|
|
291868
|
+
outerTimer = undefined;
|
|
291869
|
+
}
|
|
291870
|
+
response?.removeListener("data", onResponseData);
|
|
291871
|
+
response?.removeListener("end", onResponseEnd);
|
|
291872
|
+
response?.removeListener("aborted", onResponseAborted);
|
|
291873
|
+
if (responseClosed) {
|
|
291874
|
+
cleanupResponseListeners();
|
|
291875
|
+
}
|
|
291876
|
+
if (destroyRequest && req && !requestClosed) {
|
|
291877
|
+
req.destroy(error);
|
|
291878
|
+
} else if (retainClosedRequestError && req && requestClosed) {
|
|
291879
|
+
req.removeListener("timeout", onRequestTimeout);
|
|
291880
|
+
req.removeListener("close", onRequestClose);
|
|
291881
|
+
} else if (!req || requestClosed) {
|
|
291882
|
+
cleanupRequestListeners();
|
|
291883
|
+
}
|
|
291884
|
+
if (error) {
|
|
291885
|
+
reject(error);
|
|
291886
|
+
} else {
|
|
291659
291887
|
resolve();
|
|
291888
|
+
}
|
|
291889
|
+
}
|
|
291890
|
+
outerTimer = setTimeout(() => {
|
|
291891
|
+
settle2(new Error("Archive forwarder request deadline exceeded"), true);
|
|
291892
|
+
}, this.forwarderTimeoutMs);
|
|
291893
|
+
try {
|
|
291894
|
+
req = doRequest(url2, {
|
|
291895
|
+
method: "POST",
|
|
291896
|
+
headers,
|
|
291897
|
+
timeout: this.forwarderTimeoutMs
|
|
291898
|
+
}, (nextResponse) => {
|
|
291899
|
+
response = nextResponse;
|
|
291900
|
+
response.on("data", onResponseData);
|
|
291901
|
+
response.on("end", onResponseEnd);
|
|
291902
|
+
response.on("aborted", onResponseAborted);
|
|
291903
|
+
response.on("error", onResponseError);
|
|
291904
|
+
response.on("close", onResponseClose);
|
|
291905
|
+
if (settled) {
|
|
291906
|
+
response.resume();
|
|
291907
|
+
}
|
|
291660
291908
|
});
|
|
291661
|
-
|
|
291662
|
-
|
|
291663
|
-
|
|
291664
|
-
req.
|
|
291665
|
-
|
|
291666
|
-
|
|
291667
|
-
|
|
291909
|
+
req.on("error", onRequestError);
|
|
291910
|
+
req.on("timeout", onRequestTimeout);
|
|
291911
|
+
req.on("close", onRequestClose);
|
|
291912
|
+
req.write(body);
|
|
291913
|
+
req.end();
|
|
291914
|
+
} catch (error) {
|
|
291915
|
+
settle2(error instanceof Error ? error : new Error(String(error)), true);
|
|
291916
|
+
}
|
|
291668
291917
|
});
|
|
291669
291918
|
}
|
|
291670
291919
|
}
|
|
@@ -305180,7 +305429,7 @@ function finalize(ctx, schema) {
|
|
|
305180
305429
|
result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
305181
305430
|
} else if (ctx.target === "draft-04") {
|
|
305182
305431
|
result.$schema = "http://json-schema.org/draft-04/schema#";
|
|
305183
|
-
} else if (ctx.target === "openapi-3.0") {}
|
|
305432
|
+
} else if (ctx.target === "openapi-3.0") {}
|
|
305184
305433
|
if (ctx.external?.uri) {
|
|
305185
305434
|
const id2 = ctx.external.registry.get(schema)?.id;
|
|
305186
305435
|
if (!id2)
|
|
@@ -305428,7 +305677,7 @@ var literalProcessor = (schema, ctx, json3, _params) => {
|
|
|
305428
305677
|
if (val === undefined) {
|
|
305429
305678
|
if (ctx.unrepresentable === "throw") {
|
|
305430
305679
|
throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
305431
|
-
}
|
|
305680
|
+
}
|
|
305432
305681
|
} else if (typeof val === "bigint") {
|
|
305433
305682
|
if (ctx.unrepresentable === "throw") {
|
|
305434
305683
|
throw new Error("BigInt literals cannot be represented in JSON Schema");
|
|
@@ -311860,4 +312109,4 @@ export {
|
|
|
311860
312109
|
CEXBroker as default
|
|
311861
312110
|
};
|
|
311862
312111
|
|
|
311863
|
-
//# debugId=
|
|
312112
|
+
//# debugId=14D3F8955E8B1FB864756E2164756E21
|