@gravito/zenith 1.1.1 → 1.1.2
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/CHANGELOG.md +7 -0
- package/dist/bin.js +2927 -217
- package/dist/server/index.js +2927 -217
- package/package.json +1 -1
- package/src/server/config/ServerConfigManager.ts +4 -1
- package/src/server/index.ts +4 -1
package/dist/server/index.js
CHANGED
|
@@ -78092,6 +78092,75 @@ class DatabaseDriver {
|
|
|
78092
78092
|
}
|
|
78093
78093
|
return job;
|
|
78094
78094
|
}
|
|
78095
|
+
async popMany(queue, count) {
|
|
78096
|
+
if (count <= 1) {
|
|
78097
|
+
const job = await this.pop(queue);
|
|
78098
|
+
return job ? [job] : [];
|
|
78099
|
+
}
|
|
78100
|
+
try {
|
|
78101
|
+
const result = await this.dbService.execute(`SELECT id, payload, attempts, created_at, available_at
|
|
78102
|
+
FROM ${this.tableName}
|
|
78103
|
+
WHERE queue = $1
|
|
78104
|
+
AND available_at <= NOW()
|
|
78105
|
+
AND (reserved_at IS NULL OR reserved_at < NOW() - INTERVAL '5 minutes')
|
|
78106
|
+
ORDER BY created_at ASC
|
|
78107
|
+
LIMIT ${count}
|
|
78108
|
+
FOR UPDATE SKIP LOCKED`, [queue]);
|
|
78109
|
+
const rows = Array.isArray(result) ? result : result ? [result] : [];
|
|
78110
|
+
if (!rows || rows.length === 0) {
|
|
78111
|
+
return [];
|
|
78112
|
+
}
|
|
78113
|
+
const validRows = rows.filter((r) => r?.id);
|
|
78114
|
+
if (validRows.length === 0) {
|
|
78115
|
+
return [];
|
|
78116
|
+
}
|
|
78117
|
+
const ids = validRows.map((r) => r.id);
|
|
78118
|
+
await this.dbService.execute(`UPDATE ${this.tableName}
|
|
78119
|
+
SET reserved_at = NOW()
|
|
78120
|
+
WHERE id IN (${ids.map((_, i) => `$${i + 1}`).join(", ")})`, ids);
|
|
78121
|
+
return validRows.map((row) => {
|
|
78122
|
+
const createdAt = new Date(row.created_at).getTime();
|
|
78123
|
+
try {
|
|
78124
|
+
const parsed = JSON.parse(row.payload);
|
|
78125
|
+
return {
|
|
78126
|
+
...parsed,
|
|
78127
|
+
id: row.id,
|
|
78128
|
+
attempts: row.attempts
|
|
78129
|
+
};
|
|
78130
|
+
} catch (_e) {
|
|
78131
|
+
return {
|
|
78132
|
+
id: row.id,
|
|
78133
|
+
type: "class",
|
|
78134
|
+
data: row.payload,
|
|
78135
|
+
createdAt,
|
|
78136
|
+
attempts: row.attempts
|
|
78137
|
+
};
|
|
78138
|
+
}
|
|
78139
|
+
});
|
|
78140
|
+
} catch (_e) {
|
|
78141
|
+
const firstJob = await this.pop(queue);
|
|
78142
|
+
return firstJob ? [firstJob] : [];
|
|
78143
|
+
}
|
|
78144
|
+
}
|
|
78145
|
+
async stats(queue) {
|
|
78146
|
+
const failedQueue = `failed:${queue}`;
|
|
78147
|
+
try {
|
|
78148
|
+
const pendingRes = await this.dbService.execute(`SELECT COUNT(*) as count FROM ${this.tableName} WHERE queue = $1 AND available_at <= NOW() AND reserved_at IS NULL`, [queue]);
|
|
78149
|
+
const delayedRes = await this.dbService.execute(`SELECT COUNT(*) as count FROM ${this.tableName} WHERE queue = $1 AND available_at > NOW()`, [queue]);
|
|
78150
|
+
const reservedRes = await this.dbService.execute(`SELECT COUNT(*) as count FROM ${this.tableName} WHERE queue = $1 AND reserved_at IS NOT NULL`, [queue]);
|
|
78151
|
+
const failedRes = await this.dbService.execute(`SELECT COUNT(*) as count FROM ${this.tableName} WHERE queue = $1`, [failedQueue]);
|
|
78152
|
+
return {
|
|
78153
|
+
queue,
|
|
78154
|
+
size: pendingRes[0]?.count || 0,
|
|
78155
|
+
delayed: delayedRes[0]?.count || 0,
|
|
78156
|
+
reserved: reservedRes[0]?.count || 0,
|
|
78157
|
+
failed: failedRes[0]?.count || 0
|
|
78158
|
+
};
|
|
78159
|
+
} catch (err) {
|
|
78160
|
+
console.error("[DatabaseDriver] Failed to get stats:", err);
|
|
78161
|
+
return { queue, size: 0, delayed: 0, reserved: 0, failed: 0 };
|
|
78162
|
+
}
|
|
78163
|
+
}
|
|
78095
78164
|
async size(queue) {
|
|
78096
78165
|
const result = await this.dbService.execute(`SELECT COUNT(*) as count
|
|
78097
78166
|
FROM ${this.tableName}
|
|
@@ -78103,15 +78172,33 @@ class DatabaseDriver {
|
|
|
78103
78172
|
async clear(queue) {
|
|
78104
78173
|
await this.dbService.execute(`DELETE FROM ${this.tableName} WHERE queue = $1`, [queue]);
|
|
78105
78174
|
}
|
|
78175
|
+
async popBlocking(queue, timeout) {
|
|
78176
|
+
const start = Date.now();
|
|
78177
|
+
const timeoutMs = timeout * 1000;
|
|
78178
|
+
while (true) {
|
|
78179
|
+
const job = await this.pop(queue);
|
|
78180
|
+
if (job) {
|
|
78181
|
+
return job;
|
|
78182
|
+
}
|
|
78183
|
+
if (timeout > 0 && Date.now() - start >= timeoutMs) {
|
|
78184
|
+
return null;
|
|
78185
|
+
}
|
|
78186
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
78187
|
+
}
|
|
78188
|
+
}
|
|
78106
78189
|
async pushMany(queue, jobs) {
|
|
78107
78190
|
if (jobs.length === 0) {
|
|
78108
78191
|
return;
|
|
78109
78192
|
}
|
|
78110
78193
|
await this.dbService.transaction(async (tx) => {
|
|
78111
|
-
for (
|
|
78112
|
-
const
|
|
78113
|
-
|
|
78114
|
-
|
|
78194
|
+
for (let i = 0;i < jobs.length; i += 100) {
|
|
78195
|
+
const batch = jobs.slice(i, i + 100);
|
|
78196
|
+
for (const job of batch) {
|
|
78197
|
+
const availableAt = job.delaySeconds ? new Date(Date.now() + job.delaySeconds * 1000) : new Date;
|
|
78198
|
+
const payload = JSON.stringify(job);
|
|
78199
|
+
await tx.execute(`INSERT INTO ${this.tableName} (queue, payload, attempts, available_at, created_at)
|
|
78200
|
+
VALUES ($1, $2, $3, $4, $5)`, [queue, payload, job.attempts ?? 0, availableAt.toISOString(), new Date().toISOString()]);
|
|
78201
|
+
}
|
|
78115
78202
|
}
|
|
78116
78203
|
});
|
|
78117
78204
|
}
|
|
@@ -78239,25 +78326,29 @@ class KafkaDriver {
|
|
|
78239
78326
|
await consumer.connect();
|
|
78240
78327
|
await consumer.subscribe({ topics: [queue] });
|
|
78241
78328
|
await consumer.run({
|
|
78242
|
-
|
|
78243
|
-
|
|
78244
|
-
|
|
78245
|
-
|
|
78246
|
-
|
|
78247
|
-
|
|
78248
|
-
|
|
78249
|
-
|
|
78250
|
-
|
|
78251
|
-
|
|
78252
|
-
|
|
78253
|
-
|
|
78254
|
-
|
|
78255
|
-
|
|
78256
|
-
|
|
78257
|
-
|
|
78258
|
-
|
|
78259
|
-
|
|
78260
|
-
|
|
78329
|
+
eachBatch: async ({ batch, resolveOffset, heartbeat, isRunning }) => {
|
|
78330
|
+
for (const message of batch.messages) {
|
|
78331
|
+
if (!isRunning() || !message.value) {
|
|
78332
|
+
continue;
|
|
78333
|
+
}
|
|
78334
|
+
try {
|
|
78335
|
+
const payload = JSON.parse(message.value.toString());
|
|
78336
|
+
const job = {
|
|
78337
|
+
id: payload.id,
|
|
78338
|
+
type: payload.type,
|
|
78339
|
+
data: payload.data,
|
|
78340
|
+
className: payload.className,
|
|
78341
|
+
createdAt: payload.createdAt,
|
|
78342
|
+
delaySeconds: payload.delaySeconds,
|
|
78343
|
+
attempts: payload.attempts,
|
|
78344
|
+
maxAttempts: payload.maxAttempts
|
|
78345
|
+
};
|
|
78346
|
+
await callback(job);
|
|
78347
|
+
resolveOffset(message.offset);
|
|
78348
|
+
await heartbeat();
|
|
78349
|
+
} catch (error) {
|
|
78350
|
+
console.error("[KafkaDriver] Error processing message:", error);
|
|
78351
|
+
}
|
|
78261
78352
|
}
|
|
78262
78353
|
}
|
|
78263
78354
|
});
|
|
@@ -78323,6 +78414,21 @@ class RabbitMQDriver {
|
|
|
78323
78414
|
job._raw = msg;
|
|
78324
78415
|
return job;
|
|
78325
78416
|
}
|
|
78417
|
+
async popMany(queue, count) {
|
|
78418
|
+
const channel = await this.ensureChannel();
|
|
78419
|
+
await channel.assertQueue(queue, { durable: true });
|
|
78420
|
+
const results = [];
|
|
78421
|
+
for (let i = 0;i < count; i++) {
|
|
78422
|
+
const msg = await channel.get(queue, { noAck: false });
|
|
78423
|
+
if (!msg) {
|
|
78424
|
+
break;
|
|
78425
|
+
}
|
|
78426
|
+
const job = JSON.parse(msg.content.toString());
|
|
78427
|
+
job._raw = msg;
|
|
78428
|
+
results.push(job);
|
|
78429
|
+
}
|
|
78430
|
+
return results;
|
|
78431
|
+
}
|
|
78326
78432
|
async acknowledge(messageId) {
|
|
78327
78433
|
const channel = await this.ensureChannel();
|
|
78328
78434
|
if (typeof messageId === "object") {
|
|
@@ -78340,6 +78446,9 @@ class RabbitMQDriver {
|
|
|
78340
78446
|
async subscribe(queue, callback, options = {}) {
|
|
78341
78447
|
const channel = await this.ensureChannel();
|
|
78342
78448
|
await channel.assertQueue(queue, { durable: true });
|
|
78449
|
+
if (options.prefetch) {
|
|
78450
|
+
await channel.prefetch(options.prefetch);
|
|
78451
|
+
}
|
|
78343
78452
|
if (this.exchange) {
|
|
78344
78453
|
await channel.bindQueue(queue, this.exchange, "");
|
|
78345
78454
|
}
|
|
@@ -78403,6 +78512,58 @@ class RedisDriver2 {
|
|
|
78403
78512
|
return redis.call('SREM', activeSet, groupId)
|
|
78404
78513
|
end
|
|
78405
78514
|
`;
|
|
78515
|
+
static POP_MANY_SCRIPT = `
|
|
78516
|
+
local queue = KEYS[1]
|
|
78517
|
+
local prefix = ARGV[1]
|
|
78518
|
+
local count = tonumber(ARGV[2])
|
|
78519
|
+
local now = tonumber(ARGV[3])
|
|
78520
|
+
|
|
78521
|
+
local priorities = {'critical', 'high', 'default', 'low'}
|
|
78522
|
+
local result = {}
|
|
78523
|
+
|
|
78524
|
+
for _, priority in ipairs(priorities) do
|
|
78525
|
+
if #result >= count then break end
|
|
78526
|
+
|
|
78527
|
+
local key = prefix .. queue
|
|
78528
|
+
if priority ~= 'default' then
|
|
78529
|
+
key = key .. ':' .. priority
|
|
78530
|
+
end
|
|
78531
|
+
|
|
78532
|
+
-- Check Delayed (Move to Ready if due)
|
|
78533
|
+
local delayKey = key .. ":delayed"
|
|
78534
|
+
-- Optimization: Only check delayed if we need more items
|
|
78535
|
+
-- Fetch up to (count - #result) delayed items
|
|
78536
|
+
local needed = count - #result
|
|
78537
|
+
local delayed = redis.call("ZRANGEBYSCORE", delayKey, 0, now, "LIMIT", 0, needed)
|
|
78538
|
+
|
|
78539
|
+
for _, job in ipairs(delayed) do
|
|
78540
|
+
redis.call("ZREM", delayKey, job)
|
|
78541
|
+
-- We return it directly, assuming we want to process it now.
|
|
78542
|
+
-- Alternative: LPUSH to list and RPOP? No, direct return is faster.
|
|
78543
|
+
table.insert(result, job)
|
|
78544
|
+
needed = needed - 1
|
|
78545
|
+
end
|
|
78546
|
+
|
|
78547
|
+
if #result >= count then break end
|
|
78548
|
+
|
|
78549
|
+
-- Check Paused
|
|
78550
|
+
local isPaused = redis.call("GET", key .. ":paused")
|
|
78551
|
+
if isPaused ~= "1" then
|
|
78552
|
+
needed = count - #result
|
|
78553
|
+
-- Loop RPOP to get items
|
|
78554
|
+
for i = 1, needed do
|
|
78555
|
+
local job = redis.call("RPOP", key)
|
|
78556
|
+
if job then
|
|
78557
|
+
table.insert(result, job)
|
|
78558
|
+
else
|
|
78559
|
+
break
|
|
78560
|
+
end
|
|
78561
|
+
end
|
|
78562
|
+
end
|
|
78563
|
+
end
|
|
78564
|
+
|
|
78565
|
+
return result
|
|
78566
|
+
`;
|
|
78406
78567
|
constructor(config) {
|
|
78407
78568
|
this.client = config.client;
|
|
78408
78569
|
this.prefix = config.prefix ?? "queue:";
|
|
@@ -78418,6 +78579,10 @@ class RedisDriver2 {
|
|
|
78418
78579
|
numberOfKeys: 3,
|
|
78419
78580
|
lua: RedisDriver2.COMPLETE_SCRIPT
|
|
78420
78581
|
});
|
|
78582
|
+
this.client.defineCommand("popMany", {
|
|
78583
|
+
numberOfKeys: 1,
|
|
78584
|
+
lua: RedisDriver2.POP_MANY_SCRIPT
|
|
78585
|
+
});
|
|
78421
78586
|
}
|
|
78422
78587
|
}
|
|
78423
78588
|
getKey(queue, priority) {
|
|
@@ -78474,27 +78639,63 @@ class RedisDriver2 {
|
|
|
78474
78639
|
}
|
|
78475
78640
|
}
|
|
78476
78641
|
async pop(queue) {
|
|
78642
|
+
const priorities = ["critical", "high", "default", "low"];
|
|
78643
|
+
const keys = [];
|
|
78644
|
+
for (const p of priorities) {
|
|
78645
|
+
keys.push(this.getKey(queue, p === "default" ? undefined : p));
|
|
78646
|
+
}
|
|
78647
|
+
const script = `
|
|
78648
|
+
local now = tonumber(ARGV[1])
|
|
78649
|
+
for i, key in ipairs(KEYS) do
|
|
78650
|
+
-- 1. Check delayed
|
|
78651
|
+
local delayKey = key .. ":delayed"
|
|
78652
|
+
local delayed = redis.call("ZRANGEBYSCORE", delayKey, 0, now, "LIMIT", 0, 1)
|
|
78653
|
+
if delayed[1] then
|
|
78654
|
+
redis.call("ZREM", delayKey, delayed[1])
|
|
78655
|
+
return {key, delayed[1]}
|
|
78656
|
+
end
|
|
78657
|
+
|
|
78658
|
+
-- 2. Check paused
|
|
78659
|
+
local isPaused = redis.call("GET", key .. ":paused")
|
|
78660
|
+
if isPaused ~= "1" then
|
|
78661
|
+
-- 3. RPOP
|
|
78662
|
+
local payload = redis.call("RPOP", key)
|
|
78663
|
+
if payload then
|
|
78664
|
+
return {key, payload}
|
|
78665
|
+
end
|
|
78666
|
+
end
|
|
78667
|
+
end
|
|
78668
|
+
return nil
|
|
78669
|
+
`;
|
|
78670
|
+
try {
|
|
78671
|
+
const result = await this.client.eval(script, keys.length, ...keys, Date.now().toString());
|
|
78672
|
+
if (result?.[1]) {
|
|
78673
|
+
return this.parsePayload(result[1]);
|
|
78674
|
+
}
|
|
78675
|
+
} catch (err) {
|
|
78676
|
+
console.error("[RedisDriver] Lua pop error:", err);
|
|
78677
|
+
return this.popManualFallback(queue);
|
|
78678
|
+
}
|
|
78679
|
+
return null;
|
|
78680
|
+
}
|
|
78681
|
+
async popManualFallback(queue) {
|
|
78477
78682
|
const priorities = ["critical", "high", undefined, "low"];
|
|
78478
78683
|
for (const priority of priorities) {
|
|
78479
78684
|
const key = this.getKey(queue, priority);
|
|
78480
78685
|
const delayKey = `${key}:delayed`;
|
|
78481
|
-
|
|
78482
|
-
|
|
78483
|
-
|
|
78484
|
-
|
|
78485
|
-
|
|
78486
|
-
|
|
78487
|
-
|
|
78488
|
-
|
|
78489
|
-
return this.parsePayload(payload2);
|
|
78490
|
-
}
|
|
78686
|
+
const now = Date.now();
|
|
78687
|
+
const delayedJobs = await this.client.zrange?.(delayKey, 0, 0, "WITHSCORES");
|
|
78688
|
+
if (delayedJobs && delayedJobs.length >= 2) {
|
|
78689
|
+
const score = parseFloat(delayedJobs[1]);
|
|
78690
|
+
if (score <= now) {
|
|
78691
|
+
const payload2 = delayedJobs[0];
|
|
78692
|
+
await this.client.zrem?.(delayKey, payload2);
|
|
78693
|
+
return this.parsePayload(payload2);
|
|
78491
78694
|
}
|
|
78492
78695
|
}
|
|
78493
|
-
|
|
78494
|
-
|
|
78495
|
-
|
|
78496
|
-
continue;
|
|
78497
|
-
}
|
|
78696
|
+
const isPaused = await this.client.get?.(`${key}:paused`);
|
|
78697
|
+
if (isPaused === "1") {
|
|
78698
|
+
continue;
|
|
78498
78699
|
}
|
|
78499
78700
|
const payload = await this.client.rpop(key);
|
|
78500
78701
|
if (payload) {
|
|
@@ -78503,6 +78704,26 @@ class RedisDriver2 {
|
|
|
78503
78704
|
}
|
|
78504
78705
|
return null;
|
|
78505
78706
|
}
|
|
78707
|
+
async popBlocking(queues, timeout) {
|
|
78708
|
+
const queueList = Array.isArray(queues) ? queues : [queues];
|
|
78709
|
+
const priorities = ["critical", "high", undefined, "low"];
|
|
78710
|
+
const keys = [];
|
|
78711
|
+
for (const q of queueList) {
|
|
78712
|
+
for (const p of priorities) {
|
|
78713
|
+
keys.push(this.getKey(q, p));
|
|
78714
|
+
}
|
|
78715
|
+
}
|
|
78716
|
+
if (typeof this.client.brpop !== "function") {
|
|
78717
|
+
return this.pop(queueList[0]);
|
|
78718
|
+
}
|
|
78719
|
+
try {
|
|
78720
|
+
const result = await this.client.brpop(...keys, timeout);
|
|
78721
|
+
if (result && Array.isArray(result) && result.length >= 2) {
|
|
78722
|
+
return this.parsePayload(result[1]);
|
|
78723
|
+
}
|
|
78724
|
+
} catch (_e) {}
|
|
78725
|
+
return null;
|
|
78726
|
+
}
|
|
78506
78727
|
parsePayload(payload) {
|
|
78507
78728
|
const parsed = JSON.parse(payload);
|
|
78508
78729
|
return {
|
|
@@ -78540,11 +78761,53 @@ class RedisDriver2 {
|
|
|
78540
78761
|
const delayKey = `${key}:delayed`;
|
|
78541
78762
|
const activeSetKey = `${this.prefix}active`;
|
|
78542
78763
|
await this.client.del(key);
|
|
78543
|
-
if (
|
|
78764
|
+
if (this.client.del) {
|
|
78544
78765
|
await this.client.del(delayKey);
|
|
78545
78766
|
await this.client.del(activeSetKey);
|
|
78546
78767
|
}
|
|
78547
78768
|
}
|
|
78769
|
+
async stats(queue) {
|
|
78770
|
+
const priorities = ["critical", "high", "default", "low"];
|
|
78771
|
+
const stats = {
|
|
78772
|
+
queue,
|
|
78773
|
+
size: 0,
|
|
78774
|
+
delayed: 0,
|
|
78775
|
+
failed: 0
|
|
78776
|
+
};
|
|
78777
|
+
const keys = [];
|
|
78778
|
+
for (const p of priorities) {
|
|
78779
|
+
keys.push(this.getKey(queue, p === "default" ? undefined : p));
|
|
78780
|
+
}
|
|
78781
|
+
try {
|
|
78782
|
+
if (typeof this.client.pipeline === "function") {
|
|
78783
|
+
const pipe = this.client.pipeline();
|
|
78784
|
+
for (const key of keys) {
|
|
78785
|
+
pipe.llen(key);
|
|
78786
|
+
pipe.zcard(`${key}:delayed`);
|
|
78787
|
+
}
|
|
78788
|
+
pipe.llen(`${this.getKey(queue)}:failed`);
|
|
78789
|
+
const results = await pipe.exec();
|
|
78790
|
+
if (results) {
|
|
78791
|
+
let i = 0;
|
|
78792
|
+
for (const _p of priorities) {
|
|
78793
|
+
stats.size += results[i][1] || 0;
|
|
78794
|
+
stats.delayed += results[i + 1][1] || 0;
|
|
78795
|
+
i += 2;
|
|
78796
|
+
}
|
|
78797
|
+
stats.failed = results[i][1] || 0;
|
|
78798
|
+
}
|
|
78799
|
+
} else {
|
|
78800
|
+
for (const key of keys) {
|
|
78801
|
+
stats.size += await this.client.llen?.(key) || 0;
|
|
78802
|
+
stats.delayed += await this.client.zcard?.(`${key}:delayed`) || 0;
|
|
78803
|
+
}
|
|
78804
|
+
stats.failed = await this.client.llen?.(`${this.getKey(queue)}:failed`) || 0;
|
|
78805
|
+
}
|
|
78806
|
+
} catch (err) {
|
|
78807
|
+
console.error("[RedisDriver] Failed to get stats:", err);
|
|
78808
|
+
}
|
|
78809
|
+
return stats;
|
|
78810
|
+
}
|
|
78548
78811
|
async pushMany(queue, jobs) {
|
|
78549
78812
|
if (jobs.length === 0) {
|
|
78550
78813
|
return;
|
|
@@ -78552,6 +78815,43 @@ class RedisDriver2 {
|
|
|
78552
78815
|
const hasGroup = jobs.some((j) => j.groupId);
|
|
78553
78816
|
const hasPriority = jobs.some((j) => j.priority);
|
|
78554
78817
|
if (hasGroup || hasPriority) {
|
|
78818
|
+
if (typeof this.client.pipeline === "function") {
|
|
78819
|
+
const pipe = this.client.pipeline();
|
|
78820
|
+
for (const job of jobs) {
|
|
78821
|
+
const priority = job.priority;
|
|
78822
|
+
const key2 = this.getKey(queue, priority);
|
|
78823
|
+
const groupId = job.groupId;
|
|
78824
|
+
const payload = JSON.stringify({
|
|
78825
|
+
id: job.id,
|
|
78826
|
+
type: job.type,
|
|
78827
|
+
data: job.data,
|
|
78828
|
+
className: job.className,
|
|
78829
|
+
createdAt: job.createdAt,
|
|
78830
|
+
delaySeconds: job.delaySeconds,
|
|
78831
|
+
attempts: job.attempts,
|
|
78832
|
+
maxAttempts: job.maxAttempts,
|
|
78833
|
+
groupId,
|
|
78834
|
+
priority,
|
|
78835
|
+
error: job.error,
|
|
78836
|
+
failedAt: job.failedAt
|
|
78837
|
+
});
|
|
78838
|
+
if (groupId) {
|
|
78839
|
+
const activeSetKey = `${this.prefix}active`;
|
|
78840
|
+
const pendingListKey = `${this.prefix}pending:${groupId}`;
|
|
78841
|
+
pipe.pushGroupJob(key2, activeSetKey, pendingListKey, groupId, payload);
|
|
78842
|
+
} else {
|
|
78843
|
+
if (job.delaySeconds && job.delaySeconds > 0) {
|
|
78844
|
+
const delayKey = `${key2}:delayed`;
|
|
78845
|
+
const score = Date.now() + job.delaySeconds * 1000;
|
|
78846
|
+
pipe.zadd(delayKey, score, payload);
|
|
78847
|
+
} else {
|
|
78848
|
+
pipe.lpush(key2, payload);
|
|
78849
|
+
}
|
|
78850
|
+
}
|
|
78851
|
+
}
|
|
78852
|
+
await pipe.exec();
|
|
78853
|
+
return;
|
|
78854
|
+
}
|
|
78555
78855
|
for (const job of jobs) {
|
|
78556
78856
|
await this.push(queue, job, {
|
|
78557
78857
|
groupId: job.groupId,
|
|
@@ -78576,15 +78876,75 @@ class RedisDriver2 {
|
|
|
78576
78876
|
await this.client.lpush(key, ...payloads);
|
|
78577
78877
|
}
|
|
78578
78878
|
async popMany(queue, count) {
|
|
78579
|
-
|
|
78879
|
+
if (count <= 0) {
|
|
78880
|
+
return [];
|
|
78881
|
+
}
|
|
78882
|
+
if (count === 1) {
|
|
78883
|
+
const job = await this.pop(queue);
|
|
78884
|
+
return job ? [job] : [];
|
|
78885
|
+
}
|
|
78886
|
+
if (typeof this.client.popMany === "function") {
|
|
78887
|
+
try {
|
|
78888
|
+
const result = await this.client.popMany(queue, this.prefix, count, Date.now().toString());
|
|
78889
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
78890
|
+
return result.map((p) => this.parsePayload(p));
|
|
78891
|
+
} else if (Array.isArray(result) && result.length === 0) {} else {}
|
|
78892
|
+
if (Array.isArray(result)) {
|
|
78893
|
+
return result.map((p) => this.parsePayload(p));
|
|
78894
|
+
}
|
|
78895
|
+
} catch (err) {
|
|
78896
|
+
console.error("[RedisDriver] Lua popMany error:", err);
|
|
78897
|
+
}
|
|
78898
|
+
}
|
|
78899
|
+
const priorities = ["critical", "high", "default", "low"];
|
|
78580
78900
|
const results = [];
|
|
78581
|
-
|
|
78582
|
-
|
|
78583
|
-
if (
|
|
78584
|
-
results.push(this.parsePayload(payload));
|
|
78585
|
-
} else {
|
|
78901
|
+
let remaining = count;
|
|
78902
|
+
for (const priority of priorities) {
|
|
78903
|
+
if (remaining <= 0) {
|
|
78586
78904
|
break;
|
|
78587
78905
|
}
|
|
78906
|
+
const key = this.getKey(queue, priority === "default" ? undefined : priority);
|
|
78907
|
+
const isPaused = await this.client.get?.(`${key}:paused`);
|
|
78908
|
+
if (isPaused === "1") {
|
|
78909
|
+
continue;
|
|
78910
|
+
}
|
|
78911
|
+
let fetched = [];
|
|
78912
|
+
try {
|
|
78913
|
+
const reply = await this.client.rpop(key, remaining);
|
|
78914
|
+
if (reply) {
|
|
78915
|
+
fetched = Array.isArray(reply) ? reply : [reply];
|
|
78916
|
+
}
|
|
78917
|
+
} catch (_e) {
|
|
78918
|
+
if (typeof this.client.pipeline === "function") {
|
|
78919
|
+
const pipeline = this.client.pipeline();
|
|
78920
|
+
for (let i = 0;i < remaining; i++) {
|
|
78921
|
+
pipeline.rpop(key);
|
|
78922
|
+
}
|
|
78923
|
+
const replies = await pipeline.exec();
|
|
78924
|
+
if (replies) {
|
|
78925
|
+
fetched = replies.map((r) => r[1]).filter((r) => r !== null);
|
|
78926
|
+
}
|
|
78927
|
+
} else {
|
|
78928
|
+
for (let i = 0;i < remaining; i++) {
|
|
78929
|
+
const res = await this.client.rpop(key);
|
|
78930
|
+
if (res) {
|
|
78931
|
+
fetched.push(res);
|
|
78932
|
+
} else {
|
|
78933
|
+
break;
|
|
78934
|
+
}
|
|
78935
|
+
}
|
|
78936
|
+
}
|
|
78937
|
+
}
|
|
78938
|
+
if (fetched.length > 0) {
|
|
78939
|
+
for (const payload of fetched) {
|
|
78940
|
+
try {
|
|
78941
|
+
results.push(this.parsePayload(payload));
|
|
78942
|
+
} catch (e) {
|
|
78943
|
+
console.error("[RedisDriver] Failed to parse job payload:", e);
|
|
78944
|
+
}
|
|
78945
|
+
}
|
|
78946
|
+
remaining -= fetched.length;
|
|
78947
|
+
}
|
|
78588
78948
|
}
|
|
78589
78949
|
return results;
|
|
78590
78950
|
}
|
|
@@ -78618,7 +78978,7 @@ class RedisDriver2 {
|
|
|
78618
78978
|
const client = this.client;
|
|
78619
78979
|
if (typeof client.incr === "function") {
|
|
78620
78980
|
const current = await client.incr(windowKey);
|
|
78621
|
-
if (current === 1) {
|
|
78981
|
+
if (current === 1 && client.expire) {
|
|
78622
78982
|
await client.expire(windowKey, Math.ceil(config.duration / 1000) + 1);
|
|
78623
78983
|
}
|
|
78624
78984
|
return current <= config.max;
|
|
@@ -78627,6 +78987,9 @@ class RedisDriver2 {
|
|
|
78627
78987
|
}
|
|
78628
78988
|
async getFailed(queue, start = 0, end = -1) {
|
|
78629
78989
|
const key = `${this.getKey(queue)}:failed`;
|
|
78990
|
+
if (typeof this.client.lrange !== "function") {
|
|
78991
|
+
return [];
|
|
78992
|
+
}
|
|
78630
78993
|
const payloads = await this.client.lrange(key, start, end);
|
|
78631
78994
|
return payloads.map((p) => this.parsePayload(p));
|
|
78632
78995
|
}
|
|
@@ -78634,6 +78997,9 @@ class RedisDriver2 {
|
|
|
78634
78997
|
const failedKey = `${this.getKey(queue)}:failed`;
|
|
78635
78998
|
let retried = 0;
|
|
78636
78999
|
for (let i = 0;i < count; i++) {
|
|
79000
|
+
if (typeof this.client.rpop !== "function") {
|
|
79001
|
+
break;
|
|
79002
|
+
}
|
|
78637
79003
|
const payload = await this.client.rpop(failedKey);
|
|
78638
79004
|
if (!payload) {
|
|
78639
79005
|
break;
|
|
@@ -102358,6 +102724,34 @@ class SQSDriver {
|
|
|
102358
102724
|
...message.ReceiptHandle && { receiptHandle: message.ReceiptHandle }
|
|
102359
102725
|
};
|
|
102360
102726
|
}
|
|
102727
|
+
async popMany(queue, count) {
|
|
102728
|
+
const { ReceiveMessageCommand: ReceiveMessageCommand3 } = await Promise.resolve().then(() => (init_dist_es13(), exports_dist_es8));
|
|
102729
|
+
const queueUrl = await this.getQueueUrl(queue);
|
|
102730
|
+
const limit = Math.min(count, 10);
|
|
102731
|
+
const response = await this.client.send(new ReceiveMessageCommand3({
|
|
102732
|
+
QueueUrl: queueUrl,
|
|
102733
|
+
MaxNumberOfMessages: limit,
|
|
102734
|
+
WaitTimeSeconds: this.waitTimeSeconds,
|
|
102735
|
+
VisibilityTimeout: this.visibilityTimeout
|
|
102736
|
+
}));
|
|
102737
|
+
if (!response.Messages || response.Messages.length === 0) {
|
|
102738
|
+
return [];
|
|
102739
|
+
}
|
|
102740
|
+
return response.Messages.map((message) => {
|
|
102741
|
+
const payload = JSON.parse(message.Body ?? "{}");
|
|
102742
|
+
return {
|
|
102743
|
+
id: payload.id ?? message.MessageId,
|
|
102744
|
+
type: payload.type,
|
|
102745
|
+
data: payload.data,
|
|
102746
|
+
className: payload.className,
|
|
102747
|
+
createdAt: payload.createdAt,
|
|
102748
|
+
delaySeconds: payload.delaySeconds,
|
|
102749
|
+
attempts: payload.attempts,
|
|
102750
|
+
maxAttempts: payload.maxAttempts,
|
|
102751
|
+
receiptHandle: message.ReceiptHandle
|
|
102752
|
+
};
|
|
102753
|
+
});
|
|
102754
|
+
}
|
|
102361
102755
|
async size(queue) {
|
|
102362
102756
|
const { GetQueueAttributesCommand: GetQueueAttributesCommand3 } = await Promise.resolve().then(() => (init_dist_es13(), exports_dist_es8));
|
|
102363
102757
|
const queueUrl = await this.getQueueUrl(queue);
|
|
@@ -102433,6 +102827,1829 @@ class SQSDriver {
|
|
|
102433
102827
|
}
|
|
102434
102828
|
}
|
|
102435
102829
|
|
|
102830
|
+
// ../stream/src/persistence/BufferedPersistence.ts
|
|
102831
|
+
var exports_BufferedPersistence = {};
|
|
102832
|
+
__export(exports_BufferedPersistence, {
|
|
102833
|
+
BufferedPersistence: () => BufferedPersistence
|
|
102834
|
+
});
|
|
102835
|
+
|
|
102836
|
+
class BufferedPersistence {
|
|
102837
|
+
adapter;
|
|
102838
|
+
jobBuffer = [];
|
|
102839
|
+
logBuffer = [];
|
|
102840
|
+
flushTimer = null;
|
|
102841
|
+
maxBufferSize;
|
|
102842
|
+
flushInterval;
|
|
102843
|
+
constructor(adapter, options = {}) {
|
|
102844
|
+
this.adapter = adapter;
|
|
102845
|
+
this.maxBufferSize = options.maxBufferSize ?? 50;
|
|
102846
|
+
this.flushInterval = options.flushInterval ?? 5000;
|
|
102847
|
+
}
|
|
102848
|
+
async archive(queue, job, status) {
|
|
102849
|
+
this.jobBuffer.push({ queue, job, status });
|
|
102850
|
+
if (this.jobBuffer.length >= this.maxBufferSize) {
|
|
102851
|
+
this.flush().catch((err) => {
|
|
102852
|
+
console.error("[BufferedPersistence] Auto-flush failed (jobs):", err.message || err);
|
|
102853
|
+
});
|
|
102854
|
+
} else {
|
|
102855
|
+
this.ensureFlushTimer();
|
|
102856
|
+
}
|
|
102857
|
+
}
|
|
102858
|
+
async find(queue, id) {
|
|
102859
|
+
return this.adapter.find(queue, id);
|
|
102860
|
+
}
|
|
102861
|
+
async list(queue, options) {
|
|
102862
|
+
return this.adapter.list(queue, options);
|
|
102863
|
+
}
|
|
102864
|
+
async archiveMany(jobs) {
|
|
102865
|
+
if (this.adapter.archiveMany) {
|
|
102866
|
+
return this.adapter.archiveMany(jobs);
|
|
102867
|
+
}
|
|
102868
|
+
for (const item of jobs) {
|
|
102869
|
+
await this.adapter.archive(item.queue, item.job, item.status);
|
|
102870
|
+
}
|
|
102871
|
+
}
|
|
102872
|
+
async cleanup(days) {
|
|
102873
|
+
return this.adapter.cleanup(days);
|
|
102874
|
+
}
|
|
102875
|
+
async flush() {
|
|
102876
|
+
if (this.flushTimer) {
|
|
102877
|
+
clearTimeout(this.flushTimer);
|
|
102878
|
+
this.flushTimer = null;
|
|
102879
|
+
}
|
|
102880
|
+
const jobs = [...this.jobBuffer];
|
|
102881
|
+
const logs = [...this.logBuffer];
|
|
102882
|
+
this.jobBuffer = [];
|
|
102883
|
+
this.logBuffer = [];
|
|
102884
|
+
const promises = [];
|
|
102885
|
+
if (jobs.length > 0) {
|
|
102886
|
+
if (this.adapter.archiveMany) {
|
|
102887
|
+
promises.push(this.adapter.archiveMany(jobs));
|
|
102888
|
+
} else {
|
|
102889
|
+
promises.push((async () => {
|
|
102890
|
+
for (const item of jobs) {
|
|
102891
|
+
await this.adapter.archive(item.queue, item.job, item.status);
|
|
102892
|
+
}
|
|
102893
|
+
})());
|
|
102894
|
+
}
|
|
102895
|
+
}
|
|
102896
|
+
if (logs.length > 0) {
|
|
102897
|
+
if (this.adapter.archiveLogMany) {
|
|
102898
|
+
promises.push(this.adapter.archiveLogMany(logs));
|
|
102899
|
+
} else {
|
|
102900
|
+
promises.push((async () => {
|
|
102901
|
+
for (const log of logs) {
|
|
102902
|
+
await this.adapter.archiveLog(log);
|
|
102903
|
+
}
|
|
102904
|
+
})());
|
|
102905
|
+
}
|
|
102906
|
+
}
|
|
102907
|
+
await Promise.all(promises);
|
|
102908
|
+
}
|
|
102909
|
+
async count(queue, options) {
|
|
102910
|
+
return this.adapter.count(queue, options);
|
|
102911
|
+
}
|
|
102912
|
+
async archiveLog(log) {
|
|
102913
|
+
this.logBuffer.push(log);
|
|
102914
|
+
if (this.logBuffer.length >= this.maxBufferSize) {
|
|
102915
|
+
this.flush().catch((err) => {
|
|
102916
|
+
console.error("[BufferedPersistence] Auto-flush failed (logs):", err.message || err);
|
|
102917
|
+
});
|
|
102918
|
+
} else {
|
|
102919
|
+
this.ensureFlushTimer();
|
|
102920
|
+
}
|
|
102921
|
+
}
|
|
102922
|
+
async archiveLogMany(logs) {
|
|
102923
|
+
if (this.adapter.archiveLogMany) {
|
|
102924
|
+
return this.adapter.archiveLogMany(logs);
|
|
102925
|
+
}
|
|
102926
|
+
for (const log of logs) {
|
|
102927
|
+
await this.adapter.archiveLog(log);
|
|
102928
|
+
}
|
|
102929
|
+
}
|
|
102930
|
+
async listLogs(options) {
|
|
102931
|
+
return this.adapter.listLogs(options);
|
|
102932
|
+
}
|
|
102933
|
+
async countLogs(options) {
|
|
102934
|
+
return this.adapter.countLogs(options);
|
|
102935
|
+
}
|
|
102936
|
+
ensureFlushTimer() {
|
|
102937
|
+
if (this.flushTimer) {
|
|
102938
|
+
return;
|
|
102939
|
+
}
|
|
102940
|
+
this.flushTimer = setTimeout(() => {
|
|
102941
|
+
this.flush().catch((err) => {
|
|
102942
|
+
console.error("[BufferedPersistence] Interval flush failed:", err.message || err);
|
|
102943
|
+
});
|
|
102944
|
+
}, this.flushInterval);
|
|
102945
|
+
}
|
|
102946
|
+
}
|
|
102947
|
+
|
|
102948
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/utils/utf8.cjs
|
|
102949
|
+
var require_utf8 = __commonJS((exports) => {
|
|
102950
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
102951
|
+
exports.utf8Count = utf8Count;
|
|
102952
|
+
exports.utf8EncodeJs = utf8EncodeJs;
|
|
102953
|
+
exports.utf8EncodeTE = utf8EncodeTE;
|
|
102954
|
+
exports.utf8Encode = utf8Encode;
|
|
102955
|
+
exports.utf8DecodeJs = utf8DecodeJs;
|
|
102956
|
+
exports.utf8DecodeTD = utf8DecodeTD;
|
|
102957
|
+
exports.utf8Decode = utf8Decode;
|
|
102958
|
+
function utf8Count(str) {
|
|
102959
|
+
const strLength = str.length;
|
|
102960
|
+
let byteLength = 0;
|
|
102961
|
+
let pos = 0;
|
|
102962
|
+
while (pos < strLength) {
|
|
102963
|
+
let value = str.charCodeAt(pos++);
|
|
102964
|
+
if ((value & 4294967168) === 0) {
|
|
102965
|
+
byteLength++;
|
|
102966
|
+
continue;
|
|
102967
|
+
} else if ((value & 4294965248) === 0) {
|
|
102968
|
+
byteLength += 2;
|
|
102969
|
+
} else {
|
|
102970
|
+
if (value >= 55296 && value <= 56319) {
|
|
102971
|
+
if (pos < strLength) {
|
|
102972
|
+
const extra = str.charCodeAt(pos);
|
|
102973
|
+
if ((extra & 64512) === 56320) {
|
|
102974
|
+
++pos;
|
|
102975
|
+
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
102976
|
+
}
|
|
102977
|
+
}
|
|
102978
|
+
}
|
|
102979
|
+
if ((value & 4294901760) === 0) {
|
|
102980
|
+
byteLength += 3;
|
|
102981
|
+
} else {
|
|
102982
|
+
byteLength += 4;
|
|
102983
|
+
}
|
|
102984
|
+
}
|
|
102985
|
+
}
|
|
102986
|
+
return byteLength;
|
|
102987
|
+
}
|
|
102988
|
+
function utf8EncodeJs(str, output, outputOffset) {
|
|
102989
|
+
const strLength = str.length;
|
|
102990
|
+
let offset = outputOffset;
|
|
102991
|
+
let pos = 0;
|
|
102992
|
+
while (pos < strLength) {
|
|
102993
|
+
let value = str.charCodeAt(pos++);
|
|
102994
|
+
if ((value & 4294967168) === 0) {
|
|
102995
|
+
output[offset++] = value;
|
|
102996
|
+
continue;
|
|
102997
|
+
} else if ((value & 4294965248) === 0) {
|
|
102998
|
+
output[offset++] = value >> 6 & 31 | 192;
|
|
102999
|
+
} else {
|
|
103000
|
+
if (value >= 55296 && value <= 56319) {
|
|
103001
|
+
if (pos < strLength) {
|
|
103002
|
+
const extra = str.charCodeAt(pos);
|
|
103003
|
+
if ((extra & 64512) === 56320) {
|
|
103004
|
+
++pos;
|
|
103005
|
+
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
103006
|
+
}
|
|
103007
|
+
}
|
|
103008
|
+
}
|
|
103009
|
+
if ((value & 4294901760) === 0) {
|
|
103010
|
+
output[offset++] = value >> 12 & 15 | 224;
|
|
103011
|
+
output[offset++] = value >> 6 & 63 | 128;
|
|
103012
|
+
} else {
|
|
103013
|
+
output[offset++] = value >> 18 & 7 | 240;
|
|
103014
|
+
output[offset++] = value >> 12 & 63 | 128;
|
|
103015
|
+
output[offset++] = value >> 6 & 63 | 128;
|
|
103016
|
+
}
|
|
103017
|
+
}
|
|
103018
|
+
output[offset++] = value & 63 | 128;
|
|
103019
|
+
}
|
|
103020
|
+
}
|
|
103021
|
+
var sharedTextEncoder = new TextEncoder;
|
|
103022
|
+
var TEXT_ENCODER_THRESHOLD = 50;
|
|
103023
|
+
function utf8EncodeTE(str, output, outputOffset) {
|
|
103024
|
+
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
103025
|
+
}
|
|
103026
|
+
function utf8Encode(str, output, outputOffset) {
|
|
103027
|
+
if (str.length > TEXT_ENCODER_THRESHOLD) {
|
|
103028
|
+
utf8EncodeTE(str, output, outputOffset);
|
|
103029
|
+
} else {
|
|
103030
|
+
utf8EncodeJs(str, output, outputOffset);
|
|
103031
|
+
}
|
|
103032
|
+
}
|
|
103033
|
+
var CHUNK_SIZE = 4096;
|
|
103034
|
+
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
103035
|
+
let offset = inputOffset;
|
|
103036
|
+
const end = offset + byteLength;
|
|
103037
|
+
const units = [];
|
|
103038
|
+
let result = "";
|
|
103039
|
+
while (offset < end) {
|
|
103040
|
+
const byte1 = bytes[offset++];
|
|
103041
|
+
if ((byte1 & 128) === 0) {
|
|
103042
|
+
units.push(byte1);
|
|
103043
|
+
} else if ((byte1 & 224) === 192) {
|
|
103044
|
+
const byte2 = bytes[offset++] & 63;
|
|
103045
|
+
units.push((byte1 & 31) << 6 | byte2);
|
|
103046
|
+
} else if ((byte1 & 240) === 224) {
|
|
103047
|
+
const byte2 = bytes[offset++] & 63;
|
|
103048
|
+
const byte3 = bytes[offset++] & 63;
|
|
103049
|
+
units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
|
|
103050
|
+
} else if ((byte1 & 248) === 240) {
|
|
103051
|
+
const byte2 = bytes[offset++] & 63;
|
|
103052
|
+
const byte3 = bytes[offset++] & 63;
|
|
103053
|
+
const byte4 = bytes[offset++] & 63;
|
|
103054
|
+
let unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
|
|
103055
|
+
if (unit > 65535) {
|
|
103056
|
+
unit -= 65536;
|
|
103057
|
+
units.push(unit >>> 10 & 1023 | 55296);
|
|
103058
|
+
unit = 56320 | unit & 1023;
|
|
103059
|
+
}
|
|
103060
|
+
units.push(unit);
|
|
103061
|
+
} else {
|
|
103062
|
+
units.push(byte1);
|
|
103063
|
+
}
|
|
103064
|
+
if (units.length >= CHUNK_SIZE) {
|
|
103065
|
+
result += String.fromCharCode(...units);
|
|
103066
|
+
units.length = 0;
|
|
103067
|
+
}
|
|
103068
|
+
}
|
|
103069
|
+
if (units.length > 0) {
|
|
103070
|
+
result += String.fromCharCode(...units);
|
|
103071
|
+
}
|
|
103072
|
+
return result;
|
|
103073
|
+
}
|
|
103074
|
+
var sharedTextDecoder = new TextDecoder;
|
|
103075
|
+
var TEXT_DECODER_THRESHOLD = 200;
|
|
103076
|
+
function utf8DecodeTD(bytes, inputOffset, byteLength) {
|
|
103077
|
+
const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
|
|
103078
|
+
return sharedTextDecoder.decode(stringBytes);
|
|
103079
|
+
}
|
|
103080
|
+
function utf8Decode(bytes, inputOffset, byteLength) {
|
|
103081
|
+
if (byteLength > TEXT_DECODER_THRESHOLD) {
|
|
103082
|
+
return utf8DecodeTD(bytes, inputOffset, byteLength);
|
|
103083
|
+
} else {
|
|
103084
|
+
return utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
103085
|
+
}
|
|
103086
|
+
}
|
|
103087
|
+
});
|
|
103088
|
+
|
|
103089
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/ExtData.cjs
|
|
103090
|
+
var require_ExtData = __commonJS((exports) => {
|
|
103091
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103092
|
+
exports.ExtData = undefined;
|
|
103093
|
+
|
|
103094
|
+
class ExtData {
|
|
103095
|
+
type;
|
|
103096
|
+
data;
|
|
103097
|
+
constructor(type, data) {
|
|
103098
|
+
this.type = type;
|
|
103099
|
+
this.data = data;
|
|
103100
|
+
}
|
|
103101
|
+
}
|
|
103102
|
+
exports.ExtData = ExtData;
|
|
103103
|
+
});
|
|
103104
|
+
|
|
103105
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/DecodeError.cjs
|
|
103106
|
+
var require_DecodeError = __commonJS((exports) => {
|
|
103107
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103108
|
+
exports.DecodeError = undefined;
|
|
103109
|
+
|
|
103110
|
+
class DecodeError extends Error {
|
|
103111
|
+
constructor(message) {
|
|
103112
|
+
super(message);
|
|
103113
|
+
const proto = Object.create(DecodeError.prototype);
|
|
103114
|
+
Object.setPrototypeOf(this, proto);
|
|
103115
|
+
Object.defineProperty(this, "name", {
|
|
103116
|
+
configurable: true,
|
|
103117
|
+
enumerable: false,
|
|
103118
|
+
value: DecodeError.name
|
|
103119
|
+
});
|
|
103120
|
+
}
|
|
103121
|
+
}
|
|
103122
|
+
exports.DecodeError = DecodeError;
|
|
103123
|
+
});
|
|
103124
|
+
|
|
103125
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/utils/int.cjs
|
|
103126
|
+
var require_int = __commonJS((exports) => {
|
|
103127
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103128
|
+
exports.UINT32_MAX = undefined;
|
|
103129
|
+
exports.setUint64 = setUint64;
|
|
103130
|
+
exports.setInt64 = setInt64;
|
|
103131
|
+
exports.getInt64 = getInt64;
|
|
103132
|
+
exports.getUint64 = getUint64;
|
|
103133
|
+
exports.UINT32_MAX = 4294967295;
|
|
103134
|
+
function setUint64(view, offset, value) {
|
|
103135
|
+
const high = value / 4294967296;
|
|
103136
|
+
const low = value;
|
|
103137
|
+
view.setUint32(offset, high);
|
|
103138
|
+
view.setUint32(offset + 4, low);
|
|
103139
|
+
}
|
|
103140
|
+
function setInt64(view, offset, value) {
|
|
103141
|
+
const high = Math.floor(value / 4294967296);
|
|
103142
|
+
const low = value;
|
|
103143
|
+
view.setUint32(offset, high);
|
|
103144
|
+
view.setUint32(offset + 4, low);
|
|
103145
|
+
}
|
|
103146
|
+
function getInt64(view, offset) {
|
|
103147
|
+
const high = view.getInt32(offset);
|
|
103148
|
+
const low = view.getUint32(offset + 4);
|
|
103149
|
+
return high * 4294967296 + low;
|
|
103150
|
+
}
|
|
103151
|
+
function getUint64(view, offset) {
|
|
103152
|
+
const high = view.getUint32(offset);
|
|
103153
|
+
const low = view.getUint32(offset + 4);
|
|
103154
|
+
return high * 4294967296 + low;
|
|
103155
|
+
}
|
|
103156
|
+
});
|
|
103157
|
+
|
|
103158
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/timestamp.cjs
|
|
103159
|
+
var require_timestamp = __commonJS((exports) => {
|
|
103160
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103161
|
+
exports.timestampExtension = exports.EXT_TIMESTAMP = undefined;
|
|
103162
|
+
exports.encodeTimeSpecToTimestamp = encodeTimeSpecToTimestamp;
|
|
103163
|
+
exports.encodeDateToTimeSpec = encodeDateToTimeSpec;
|
|
103164
|
+
exports.encodeTimestampExtension = encodeTimestampExtension;
|
|
103165
|
+
exports.decodeTimestampToTimeSpec = decodeTimestampToTimeSpec;
|
|
103166
|
+
exports.decodeTimestampExtension = decodeTimestampExtension;
|
|
103167
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
103168
|
+
var int_ts_1 = require_int();
|
|
103169
|
+
exports.EXT_TIMESTAMP = -1;
|
|
103170
|
+
var TIMESTAMP32_MAX_SEC = 4294967296 - 1;
|
|
103171
|
+
var TIMESTAMP64_MAX_SEC = 17179869184 - 1;
|
|
103172
|
+
function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
103173
|
+
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
103174
|
+
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
103175
|
+
const rv = new Uint8Array(4);
|
|
103176
|
+
const view = new DataView(rv.buffer);
|
|
103177
|
+
view.setUint32(0, sec);
|
|
103178
|
+
return rv;
|
|
103179
|
+
} else {
|
|
103180
|
+
const secHigh = sec / 4294967296;
|
|
103181
|
+
const secLow = sec & 4294967295;
|
|
103182
|
+
const rv = new Uint8Array(8);
|
|
103183
|
+
const view = new DataView(rv.buffer);
|
|
103184
|
+
view.setUint32(0, nsec << 2 | secHigh & 3);
|
|
103185
|
+
view.setUint32(4, secLow);
|
|
103186
|
+
return rv;
|
|
103187
|
+
}
|
|
103188
|
+
} else {
|
|
103189
|
+
const rv = new Uint8Array(12);
|
|
103190
|
+
const view = new DataView(rv.buffer);
|
|
103191
|
+
view.setUint32(0, nsec);
|
|
103192
|
+
(0, int_ts_1.setInt64)(view, 4, sec);
|
|
103193
|
+
return rv;
|
|
103194
|
+
}
|
|
103195
|
+
}
|
|
103196
|
+
function encodeDateToTimeSpec(date) {
|
|
103197
|
+
const msec = date.getTime();
|
|
103198
|
+
const sec = Math.floor(msec / 1000);
|
|
103199
|
+
const nsec = (msec - sec * 1000) * 1e6;
|
|
103200
|
+
const nsecInSec = Math.floor(nsec / 1e9);
|
|
103201
|
+
return {
|
|
103202
|
+
sec: sec + nsecInSec,
|
|
103203
|
+
nsec: nsec - nsecInSec * 1e9
|
|
103204
|
+
};
|
|
103205
|
+
}
|
|
103206
|
+
function encodeTimestampExtension(object) {
|
|
103207
|
+
if (object instanceof Date) {
|
|
103208
|
+
const timeSpec = encodeDateToTimeSpec(object);
|
|
103209
|
+
return encodeTimeSpecToTimestamp(timeSpec);
|
|
103210
|
+
} else {
|
|
103211
|
+
return null;
|
|
103212
|
+
}
|
|
103213
|
+
}
|
|
103214
|
+
function decodeTimestampToTimeSpec(data) {
|
|
103215
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
103216
|
+
switch (data.byteLength) {
|
|
103217
|
+
case 4: {
|
|
103218
|
+
const sec = view.getUint32(0);
|
|
103219
|
+
const nsec = 0;
|
|
103220
|
+
return { sec, nsec };
|
|
103221
|
+
}
|
|
103222
|
+
case 8: {
|
|
103223
|
+
const nsec30AndSecHigh2 = view.getUint32(0);
|
|
103224
|
+
const secLow32 = view.getUint32(4);
|
|
103225
|
+
const sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
|
|
103226
|
+
const nsec = nsec30AndSecHigh2 >>> 2;
|
|
103227
|
+
return { sec, nsec };
|
|
103228
|
+
}
|
|
103229
|
+
case 12: {
|
|
103230
|
+
const sec = (0, int_ts_1.getInt64)(view, 4);
|
|
103231
|
+
const nsec = view.getUint32(0);
|
|
103232
|
+
return { sec, nsec };
|
|
103233
|
+
}
|
|
103234
|
+
default:
|
|
103235
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
|
|
103236
|
+
}
|
|
103237
|
+
}
|
|
103238
|
+
function decodeTimestampExtension(data) {
|
|
103239
|
+
const timeSpec = decodeTimestampToTimeSpec(data);
|
|
103240
|
+
return new Date(timeSpec.sec * 1000 + timeSpec.nsec / 1e6);
|
|
103241
|
+
}
|
|
103242
|
+
exports.timestampExtension = {
|
|
103243
|
+
type: exports.EXT_TIMESTAMP,
|
|
103244
|
+
encode: encodeTimestampExtension,
|
|
103245
|
+
decode: decodeTimestampExtension
|
|
103246
|
+
};
|
|
103247
|
+
});
|
|
103248
|
+
|
|
103249
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/ExtensionCodec.cjs
|
|
103250
|
+
var require_ExtensionCodec = __commonJS((exports) => {
|
|
103251
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103252
|
+
exports.ExtensionCodec = undefined;
|
|
103253
|
+
var ExtData_ts_1 = require_ExtData();
|
|
103254
|
+
var timestamp_ts_1 = require_timestamp();
|
|
103255
|
+
|
|
103256
|
+
class ExtensionCodec {
|
|
103257
|
+
static defaultCodec = new ExtensionCodec;
|
|
103258
|
+
__brand;
|
|
103259
|
+
builtInEncoders = [];
|
|
103260
|
+
builtInDecoders = [];
|
|
103261
|
+
encoders = [];
|
|
103262
|
+
decoders = [];
|
|
103263
|
+
constructor() {
|
|
103264
|
+
this.register(timestamp_ts_1.timestampExtension);
|
|
103265
|
+
}
|
|
103266
|
+
register({ type, encode, decode }) {
|
|
103267
|
+
if (type >= 0) {
|
|
103268
|
+
this.encoders[type] = encode;
|
|
103269
|
+
this.decoders[type] = decode;
|
|
103270
|
+
} else {
|
|
103271
|
+
const index = -1 - type;
|
|
103272
|
+
this.builtInEncoders[index] = encode;
|
|
103273
|
+
this.builtInDecoders[index] = decode;
|
|
103274
|
+
}
|
|
103275
|
+
}
|
|
103276
|
+
tryToEncode(object, context) {
|
|
103277
|
+
for (let i3 = 0;i3 < this.builtInEncoders.length; i3++) {
|
|
103278
|
+
const encodeExt = this.builtInEncoders[i3];
|
|
103279
|
+
if (encodeExt != null) {
|
|
103280
|
+
const data = encodeExt(object, context);
|
|
103281
|
+
if (data != null) {
|
|
103282
|
+
const type = -1 - i3;
|
|
103283
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
103284
|
+
}
|
|
103285
|
+
}
|
|
103286
|
+
}
|
|
103287
|
+
for (let i3 = 0;i3 < this.encoders.length; i3++) {
|
|
103288
|
+
const encodeExt = this.encoders[i3];
|
|
103289
|
+
if (encodeExt != null) {
|
|
103290
|
+
const data = encodeExt(object, context);
|
|
103291
|
+
if (data != null) {
|
|
103292
|
+
const type = i3;
|
|
103293
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
103294
|
+
}
|
|
103295
|
+
}
|
|
103296
|
+
}
|
|
103297
|
+
if (object instanceof ExtData_ts_1.ExtData) {
|
|
103298
|
+
return object;
|
|
103299
|
+
}
|
|
103300
|
+
return null;
|
|
103301
|
+
}
|
|
103302
|
+
decode(data, type, context) {
|
|
103303
|
+
const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
103304
|
+
if (decodeExt) {
|
|
103305
|
+
return decodeExt(data, type, context);
|
|
103306
|
+
} else {
|
|
103307
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
103308
|
+
}
|
|
103309
|
+
}
|
|
103310
|
+
}
|
|
103311
|
+
exports.ExtensionCodec = ExtensionCodec;
|
|
103312
|
+
});
|
|
103313
|
+
|
|
103314
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/utils/typedArrays.cjs
|
|
103315
|
+
var require_typedArrays = __commonJS((exports) => {
|
|
103316
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103317
|
+
exports.ensureUint8Array = ensureUint8Array;
|
|
103318
|
+
function isArrayBufferLike(buffer2) {
|
|
103319
|
+
return buffer2 instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer2 instanceof SharedArrayBuffer;
|
|
103320
|
+
}
|
|
103321
|
+
function ensureUint8Array(buffer2) {
|
|
103322
|
+
if (buffer2 instanceof Uint8Array) {
|
|
103323
|
+
return buffer2;
|
|
103324
|
+
} else if (ArrayBuffer.isView(buffer2)) {
|
|
103325
|
+
return new Uint8Array(buffer2.buffer, buffer2.byteOffset, buffer2.byteLength);
|
|
103326
|
+
} else if (isArrayBufferLike(buffer2)) {
|
|
103327
|
+
return new Uint8Array(buffer2);
|
|
103328
|
+
} else {
|
|
103329
|
+
return Uint8Array.from(buffer2);
|
|
103330
|
+
}
|
|
103331
|
+
}
|
|
103332
|
+
});
|
|
103333
|
+
|
|
103334
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/Encoder.cjs
|
|
103335
|
+
var require_Encoder = __commonJS((exports) => {
|
|
103336
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103337
|
+
exports.Encoder = exports.DEFAULT_INITIAL_BUFFER_SIZE = exports.DEFAULT_MAX_DEPTH = undefined;
|
|
103338
|
+
var utf8_ts_1 = require_utf8();
|
|
103339
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
103340
|
+
var int_ts_1 = require_int();
|
|
103341
|
+
var typedArrays_ts_1 = require_typedArrays();
|
|
103342
|
+
exports.DEFAULT_MAX_DEPTH = 100;
|
|
103343
|
+
exports.DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
103344
|
+
|
|
103345
|
+
class Encoder {
|
|
103346
|
+
extensionCodec;
|
|
103347
|
+
context;
|
|
103348
|
+
useBigInt64;
|
|
103349
|
+
maxDepth;
|
|
103350
|
+
initialBufferSize;
|
|
103351
|
+
sortKeys;
|
|
103352
|
+
forceFloat32;
|
|
103353
|
+
ignoreUndefined;
|
|
103354
|
+
forceIntegerToFloat;
|
|
103355
|
+
pos;
|
|
103356
|
+
view;
|
|
103357
|
+
bytes;
|
|
103358
|
+
entered = false;
|
|
103359
|
+
constructor(options) {
|
|
103360
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec;
|
|
103361
|
+
this.context = options?.context;
|
|
103362
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
103363
|
+
this.maxDepth = options?.maxDepth ?? exports.DEFAULT_MAX_DEPTH;
|
|
103364
|
+
this.initialBufferSize = options?.initialBufferSize ?? exports.DEFAULT_INITIAL_BUFFER_SIZE;
|
|
103365
|
+
this.sortKeys = options?.sortKeys ?? false;
|
|
103366
|
+
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
103367
|
+
this.ignoreUndefined = options?.ignoreUndefined ?? false;
|
|
103368
|
+
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
|
|
103369
|
+
this.pos = 0;
|
|
103370
|
+
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
103371
|
+
this.bytes = new Uint8Array(this.view.buffer);
|
|
103372
|
+
}
|
|
103373
|
+
clone() {
|
|
103374
|
+
return new Encoder({
|
|
103375
|
+
extensionCodec: this.extensionCodec,
|
|
103376
|
+
context: this.context,
|
|
103377
|
+
useBigInt64: this.useBigInt64,
|
|
103378
|
+
maxDepth: this.maxDepth,
|
|
103379
|
+
initialBufferSize: this.initialBufferSize,
|
|
103380
|
+
sortKeys: this.sortKeys,
|
|
103381
|
+
forceFloat32: this.forceFloat32,
|
|
103382
|
+
ignoreUndefined: this.ignoreUndefined,
|
|
103383
|
+
forceIntegerToFloat: this.forceIntegerToFloat
|
|
103384
|
+
});
|
|
103385
|
+
}
|
|
103386
|
+
reinitializeState() {
|
|
103387
|
+
this.pos = 0;
|
|
103388
|
+
}
|
|
103389
|
+
encodeSharedRef(object) {
|
|
103390
|
+
if (this.entered) {
|
|
103391
|
+
const instance = this.clone();
|
|
103392
|
+
return instance.encodeSharedRef(object);
|
|
103393
|
+
}
|
|
103394
|
+
try {
|
|
103395
|
+
this.entered = true;
|
|
103396
|
+
this.reinitializeState();
|
|
103397
|
+
this.doEncode(object, 1);
|
|
103398
|
+
return this.bytes.subarray(0, this.pos);
|
|
103399
|
+
} finally {
|
|
103400
|
+
this.entered = false;
|
|
103401
|
+
}
|
|
103402
|
+
}
|
|
103403
|
+
encode(object) {
|
|
103404
|
+
if (this.entered) {
|
|
103405
|
+
const instance = this.clone();
|
|
103406
|
+
return instance.encode(object);
|
|
103407
|
+
}
|
|
103408
|
+
try {
|
|
103409
|
+
this.entered = true;
|
|
103410
|
+
this.reinitializeState();
|
|
103411
|
+
this.doEncode(object, 1);
|
|
103412
|
+
return this.bytes.slice(0, this.pos);
|
|
103413
|
+
} finally {
|
|
103414
|
+
this.entered = false;
|
|
103415
|
+
}
|
|
103416
|
+
}
|
|
103417
|
+
doEncode(object, depth) {
|
|
103418
|
+
if (depth > this.maxDepth) {
|
|
103419
|
+
throw new Error(`Too deep objects in depth ${depth}`);
|
|
103420
|
+
}
|
|
103421
|
+
if (object == null) {
|
|
103422
|
+
this.encodeNil();
|
|
103423
|
+
} else if (typeof object === "boolean") {
|
|
103424
|
+
this.encodeBoolean(object);
|
|
103425
|
+
} else if (typeof object === "number") {
|
|
103426
|
+
if (!this.forceIntegerToFloat) {
|
|
103427
|
+
this.encodeNumber(object);
|
|
103428
|
+
} else {
|
|
103429
|
+
this.encodeNumberAsFloat(object);
|
|
103430
|
+
}
|
|
103431
|
+
} else if (typeof object === "string") {
|
|
103432
|
+
this.encodeString(object);
|
|
103433
|
+
} else if (this.useBigInt64 && typeof object === "bigint") {
|
|
103434
|
+
this.encodeBigInt64(object);
|
|
103435
|
+
} else {
|
|
103436
|
+
this.encodeObject(object, depth);
|
|
103437
|
+
}
|
|
103438
|
+
}
|
|
103439
|
+
ensureBufferSizeToWrite(sizeToWrite) {
|
|
103440
|
+
const requiredSize = this.pos + sizeToWrite;
|
|
103441
|
+
if (this.view.byteLength < requiredSize) {
|
|
103442
|
+
this.resizeBuffer(requiredSize * 2);
|
|
103443
|
+
}
|
|
103444
|
+
}
|
|
103445
|
+
resizeBuffer(newSize) {
|
|
103446
|
+
const newBuffer = new ArrayBuffer(newSize);
|
|
103447
|
+
const newBytes = new Uint8Array(newBuffer);
|
|
103448
|
+
const newView = new DataView(newBuffer);
|
|
103449
|
+
newBytes.set(this.bytes);
|
|
103450
|
+
this.view = newView;
|
|
103451
|
+
this.bytes = newBytes;
|
|
103452
|
+
}
|
|
103453
|
+
encodeNil() {
|
|
103454
|
+
this.writeU8(192);
|
|
103455
|
+
}
|
|
103456
|
+
encodeBoolean(object) {
|
|
103457
|
+
if (object === false) {
|
|
103458
|
+
this.writeU8(194);
|
|
103459
|
+
} else {
|
|
103460
|
+
this.writeU8(195);
|
|
103461
|
+
}
|
|
103462
|
+
}
|
|
103463
|
+
encodeNumber(object) {
|
|
103464
|
+
if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) {
|
|
103465
|
+
if (object >= 0) {
|
|
103466
|
+
if (object < 128) {
|
|
103467
|
+
this.writeU8(object);
|
|
103468
|
+
} else if (object < 256) {
|
|
103469
|
+
this.writeU8(204);
|
|
103470
|
+
this.writeU8(object);
|
|
103471
|
+
} else if (object < 65536) {
|
|
103472
|
+
this.writeU8(205);
|
|
103473
|
+
this.writeU16(object);
|
|
103474
|
+
} else if (object < 4294967296) {
|
|
103475
|
+
this.writeU8(206);
|
|
103476
|
+
this.writeU32(object);
|
|
103477
|
+
} else if (!this.useBigInt64) {
|
|
103478
|
+
this.writeU8(207);
|
|
103479
|
+
this.writeU64(object);
|
|
103480
|
+
} else {
|
|
103481
|
+
this.encodeNumberAsFloat(object);
|
|
103482
|
+
}
|
|
103483
|
+
} else {
|
|
103484
|
+
if (object >= -32) {
|
|
103485
|
+
this.writeU8(224 | object + 32);
|
|
103486
|
+
} else if (object >= -128) {
|
|
103487
|
+
this.writeU8(208);
|
|
103488
|
+
this.writeI8(object);
|
|
103489
|
+
} else if (object >= -32768) {
|
|
103490
|
+
this.writeU8(209);
|
|
103491
|
+
this.writeI16(object);
|
|
103492
|
+
} else if (object >= -2147483648) {
|
|
103493
|
+
this.writeU8(210);
|
|
103494
|
+
this.writeI32(object);
|
|
103495
|
+
} else if (!this.useBigInt64) {
|
|
103496
|
+
this.writeU8(211);
|
|
103497
|
+
this.writeI64(object);
|
|
103498
|
+
} else {
|
|
103499
|
+
this.encodeNumberAsFloat(object);
|
|
103500
|
+
}
|
|
103501
|
+
}
|
|
103502
|
+
} else {
|
|
103503
|
+
this.encodeNumberAsFloat(object);
|
|
103504
|
+
}
|
|
103505
|
+
}
|
|
103506
|
+
encodeNumberAsFloat(object) {
|
|
103507
|
+
if (this.forceFloat32) {
|
|
103508
|
+
this.writeU8(202);
|
|
103509
|
+
this.writeF32(object);
|
|
103510
|
+
} else {
|
|
103511
|
+
this.writeU8(203);
|
|
103512
|
+
this.writeF64(object);
|
|
103513
|
+
}
|
|
103514
|
+
}
|
|
103515
|
+
encodeBigInt64(object) {
|
|
103516
|
+
if (object >= BigInt(0)) {
|
|
103517
|
+
this.writeU8(207);
|
|
103518
|
+
this.writeBigUint64(object);
|
|
103519
|
+
} else {
|
|
103520
|
+
this.writeU8(211);
|
|
103521
|
+
this.writeBigInt64(object);
|
|
103522
|
+
}
|
|
103523
|
+
}
|
|
103524
|
+
writeStringHeader(byteLength) {
|
|
103525
|
+
if (byteLength < 32) {
|
|
103526
|
+
this.writeU8(160 + byteLength);
|
|
103527
|
+
} else if (byteLength < 256) {
|
|
103528
|
+
this.writeU8(217);
|
|
103529
|
+
this.writeU8(byteLength);
|
|
103530
|
+
} else if (byteLength < 65536) {
|
|
103531
|
+
this.writeU8(218);
|
|
103532
|
+
this.writeU16(byteLength);
|
|
103533
|
+
} else if (byteLength < 4294967296) {
|
|
103534
|
+
this.writeU8(219);
|
|
103535
|
+
this.writeU32(byteLength);
|
|
103536
|
+
} else {
|
|
103537
|
+
throw new Error(`Too long string: ${byteLength} bytes in UTF-8`);
|
|
103538
|
+
}
|
|
103539
|
+
}
|
|
103540
|
+
encodeString(object) {
|
|
103541
|
+
const maxHeaderSize = 1 + 4;
|
|
103542
|
+
const byteLength = (0, utf8_ts_1.utf8Count)(object);
|
|
103543
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
103544
|
+
this.writeStringHeader(byteLength);
|
|
103545
|
+
(0, utf8_ts_1.utf8Encode)(object, this.bytes, this.pos);
|
|
103546
|
+
this.pos += byteLength;
|
|
103547
|
+
}
|
|
103548
|
+
encodeObject(object, depth) {
|
|
103549
|
+
const ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
103550
|
+
if (ext != null) {
|
|
103551
|
+
this.encodeExtension(ext);
|
|
103552
|
+
} else if (Array.isArray(object)) {
|
|
103553
|
+
this.encodeArray(object, depth);
|
|
103554
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
103555
|
+
this.encodeBinary(object);
|
|
103556
|
+
} else if (typeof object === "object") {
|
|
103557
|
+
this.encodeMap(object, depth);
|
|
103558
|
+
} else {
|
|
103559
|
+
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`);
|
|
103560
|
+
}
|
|
103561
|
+
}
|
|
103562
|
+
encodeBinary(object) {
|
|
103563
|
+
const size = object.byteLength;
|
|
103564
|
+
if (size < 256) {
|
|
103565
|
+
this.writeU8(196);
|
|
103566
|
+
this.writeU8(size);
|
|
103567
|
+
} else if (size < 65536) {
|
|
103568
|
+
this.writeU8(197);
|
|
103569
|
+
this.writeU16(size);
|
|
103570
|
+
} else if (size < 4294967296) {
|
|
103571
|
+
this.writeU8(198);
|
|
103572
|
+
this.writeU32(size);
|
|
103573
|
+
} else {
|
|
103574
|
+
throw new Error(`Too large binary: ${size}`);
|
|
103575
|
+
}
|
|
103576
|
+
const bytes = (0, typedArrays_ts_1.ensureUint8Array)(object);
|
|
103577
|
+
this.writeU8a(bytes);
|
|
103578
|
+
}
|
|
103579
|
+
encodeArray(object, depth) {
|
|
103580
|
+
const size = object.length;
|
|
103581
|
+
if (size < 16) {
|
|
103582
|
+
this.writeU8(144 + size);
|
|
103583
|
+
} else if (size < 65536) {
|
|
103584
|
+
this.writeU8(220);
|
|
103585
|
+
this.writeU16(size);
|
|
103586
|
+
} else if (size < 4294967296) {
|
|
103587
|
+
this.writeU8(221);
|
|
103588
|
+
this.writeU32(size);
|
|
103589
|
+
} else {
|
|
103590
|
+
throw new Error(`Too large array: ${size}`);
|
|
103591
|
+
}
|
|
103592
|
+
for (const item of object) {
|
|
103593
|
+
this.doEncode(item, depth + 1);
|
|
103594
|
+
}
|
|
103595
|
+
}
|
|
103596
|
+
countWithoutUndefined(object, keys) {
|
|
103597
|
+
let count = 0;
|
|
103598
|
+
for (const key of keys) {
|
|
103599
|
+
if (object[key] !== undefined) {
|
|
103600
|
+
count++;
|
|
103601
|
+
}
|
|
103602
|
+
}
|
|
103603
|
+
return count;
|
|
103604
|
+
}
|
|
103605
|
+
encodeMap(object, depth) {
|
|
103606
|
+
const keys = Object.keys(object);
|
|
103607
|
+
if (this.sortKeys) {
|
|
103608
|
+
keys.sort();
|
|
103609
|
+
}
|
|
103610
|
+
const size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
|
|
103611
|
+
if (size < 16) {
|
|
103612
|
+
this.writeU8(128 + size);
|
|
103613
|
+
} else if (size < 65536) {
|
|
103614
|
+
this.writeU8(222);
|
|
103615
|
+
this.writeU16(size);
|
|
103616
|
+
} else if (size < 4294967296) {
|
|
103617
|
+
this.writeU8(223);
|
|
103618
|
+
this.writeU32(size);
|
|
103619
|
+
} else {
|
|
103620
|
+
throw new Error(`Too large map object: ${size}`);
|
|
103621
|
+
}
|
|
103622
|
+
for (const key of keys) {
|
|
103623
|
+
const value = object[key];
|
|
103624
|
+
if (!(this.ignoreUndefined && value === undefined)) {
|
|
103625
|
+
this.encodeString(key);
|
|
103626
|
+
this.doEncode(value, depth + 1);
|
|
103627
|
+
}
|
|
103628
|
+
}
|
|
103629
|
+
}
|
|
103630
|
+
encodeExtension(ext) {
|
|
103631
|
+
if (typeof ext.data === "function") {
|
|
103632
|
+
const data = ext.data(this.pos + 6);
|
|
103633
|
+
const size2 = data.length;
|
|
103634
|
+
if (size2 >= 4294967296) {
|
|
103635
|
+
throw new Error(`Too large extension object: ${size2}`);
|
|
103636
|
+
}
|
|
103637
|
+
this.writeU8(201);
|
|
103638
|
+
this.writeU32(size2);
|
|
103639
|
+
this.writeI8(ext.type);
|
|
103640
|
+
this.writeU8a(data);
|
|
103641
|
+
return;
|
|
103642
|
+
}
|
|
103643
|
+
const size = ext.data.length;
|
|
103644
|
+
if (size === 1) {
|
|
103645
|
+
this.writeU8(212);
|
|
103646
|
+
} else if (size === 2) {
|
|
103647
|
+
this.writeU8(213);
|
|
103648
|
+
} else if (size === 4) {
|
|
103649
|
+
this.writeU8(214);
|
|
103650
|
+
} else if (size === 8) {
|
|
103651
|
+
this.writeU8(215);
|
|
103652
|
+
} else if (size === 16) {
|
|
103653
|
+
this.writeU8(216);
|
|
103654
|
+
} else if (size < 256) {
|
|
103655
|
+
this.writeU8(199);
|
|
103656
|
+
this.writeU8(size);
|
|
103657
|
+
} else if (size < 65536) {
|
|
103658
|
+
this.writeU8(200);
|
|
103659
|
+
this.writeU16(size);
|
|
103660
|
+
} else if (size < 4294967296) {
|
|
103661
|
+
this.writeU8(201);
|
|
103662
|
+
this.writeU32(size);
|
|
103663
|
+
} else {
|
|
103664
|
+
throw new Error(`Too large extension object: ${size}`);
|
|
103665
|
+
}
|
|
103666
|
+
this.writeI8(ext.type);
|
|
103667
|
+
this.writeU8a(ext.data);
|
|
103668
|
+
}
|
|
103669
|
+
writeU8(value) {
|
|
103670
|
+
this.ensureBufferSizeToWrite(1);
|
|
103671
|
+
this.view.setUint8(this.pos, value);
|
|
103672
|
+
this.pos++;
|
|
103673
|
+
}
|
|
103674
|
+
writeU8a(values) {
|
|
103675
|
+
const size = values.length;
|
|
103676
|
+
this.ensureBufferSizeToWrite(size);
|
|
103677
|
+
this.bytes.set(values, this.pos);
|
|
103678
|
+
this.pos += size;
|
|
103679
|
+
}
|
|
103680
|
+
writeI8(value) {
|
|
103681
|
+
this.ensureBufferSizeToWrite(1);
|
|
103682
|
+
this.view.setInt8(this.pos, value);
|
|
103683
|
+
this.pos++;
|
|
103684
|
+
}
|
|
103685
|
+
writeU16(value) {
|
|
103686
|
+
this.ensureBufferSizeToWrite(2);
|
|
103687
|
+
this.view.setUint16(this.pos, value);
|
|
103688
|
+
this.pos += 2;
|
|
103689
|
+
}
|
|
103690
|
+
writeI16(value) {
|
|
103691
|
+
this.ensureBufferSizeToWrite(2);
|
|
103692
|
+
this.view.setInt16(this.pos, value);
|
|
103693
|
+
this.pos += 2;
|
|
103694
|
+
}
|
|
103695
|
+
writeU32(value) {
|
|
103696
|
+
this.ensureBufferSizeToWrite(4);
|
|
103697
|
+
this.view.setUint32(this.pos, value);
|
|
103698
|
+
this.pos += 4;
|
|
103699
|
+
}
|
|
103700
|
+
writeI32(value) {
|
|
103701
|
+
this.ensureBufferSizeToWrite(4);
|
|
103702
|
+
this.view.setInt32(this.pos, value);
|
|
103703
|
+
this.pos += 4;
|
|
103704
|
+
}
|
|
103705
|
+
writeF32(value) {
|
|
103706
|
+
this.ensureBufferSizeToWrite(4);
|
|
103707
|
+
this.view.setFloat32(this.pos, value);
|
|
103708
|
+
this.pos += 4;
|
|
103709
|
+
}
|
|
103710
|
+
writeF64(value) {
|
|
103711
|
+
this.ensureBufferSizeToWrite(8);
|
|
103712
|
+
this.view.setFloat64(this.pos, value);
|
|
103713
|
+
this.pos += 8;
|
|
103714
|
+
}
|
|
103715
|
+
writeU64(value) {
|
|
103716
|
+
this.ensureBufferSizeToWrite(8);
|
|
103717
|
+
(0, int_ts_1.setUint64)(this.view, this.pos, value);
|
|
103718
|
+
this.pos += 8;
|
|
103719
|
+
}
|
|
103720
|
+
writeI64(value) {
|
|
103721
|
+
this.ensureBufferSizeToWrite(8);
|
|
103722
|
+
(0, int_ts_1.setInt64)(this.view, this.pos, value);
|
|
103723
|
+
this.pos += 8;
|
|
103724
|
+
}
|
|
103725
|
+
writeBigUint64(value) {
|
|
103726
|
+
this.ensureBufferSizeToWrite(8);
|
|
103727
|
+
this.view.setBigUint64(this.pos, value);
|
|
103728
|
+
this.pos += 8;
|
|
103729
|
+
}
|
|
103730
|
+
writeBigInt64(value) {
|
|
103731
|
+
this.ensureBufferSizeToWrite(8);
|
|
103732
|
+
this.view.setBigInt64(this.pos, value);
|
|
103733
|
+
this.pos += 8;
|
|
103734
|
+
}
|
|
103735
|
+
}
|
|
103736
|
+
exports.Encoder = Encoder;
|
|
103737
|
+
});
|
|
103738
|
+
|
|
103739
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/encode.cjs
|
|
103740
|
+
var require_encode = __commonJS((exports) => {
|
|
103741
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103742
|
+
exports.encode = encode;
|
|
103743
|
+
var Encoder_ts_1 = require_Encoder();
|
|
103744
|
+
function encode(value, options) {
|
|
103745
|
+
const encoder = new Encoder_ts_1.Encoder(options);
|
|
103746
|
+
return encoder.encodeSharedRef(value);
|
|
103747
|
+
}
|
|
103748
|
+
});
|
|
103749
|
+
|
|
103750
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/utils/prettyByte.cjs
|
|
103751
|
+
var require_prettyByte = __commonJS((exports) => {
|
|
103752
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103753
|
+
exports.prettyByte = prettyByte;
|
|
103754
|
+
function prettyByte(byte) {
|
|
103755
|
+
return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`;
|
|
103756
|
+
}
|
|
103757
|
+
});
|
|
103758
|
+
|
|
103759
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/CachedKeyDecoder.cjs
|
|
103760
|
+
var require_CachedKeyDecoder = __commonJS((exports) => {
|
|
103761
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103762
|
+
exports.CachedKeyDecoder = undefined;
|
|
103763
|
+
var utf8_ts_1 = require_utf8();
|
|
103764
|
+
var DEFAULT_MAX_KEY_LENGTH = 16;
|
|
103765
|
+
var DEFAULT_MAX_LENGTH_PER_KEY = 16;
|
|
103766
|
+
|
|
103767
|
+
class CachedKeyDecoder {
|
|
103768
|
+
hit = 0;
|
|
103769
|
+
miss = 0;
|
|
103770
|
+
caches;
|
|
103771
|
+
maxKeyLength;
|
|
103772
|
+
maxLengthPerKey;
|
|
103773
|
+
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
|
|
103774
|
+
this.maxKeyLength = maxKeyLength;
|
|
103775
|
+
this.maxLengthPerKey = maxLengthPerKey;
|
|
103776
|
+
this.caches = [];
|
|
103777
|
+
for (let i3 = 0;i3 < this.maxKeyLength; i3++) {
|
|
103778
|
+
this.caches.push([]);
|
|
103779
|
+
}
|
|
103780
|
+
}
|
|
103781
|
+
canBeCached(byteLength) {
|
|
103782
|
+
return byteLength > 0 && byteLength <= this.maxKeyLength;
|
|
103783
|
+
}
|
|
103784
|
+
find(bytes, inputOffset, byteLength) {
|
|
103785
|
+
const records = this.caches[byteLength - 1];
|
|
103786
|
+
FIND_CHUNK:
|
|
103787
|
+
for (const record of records) {
|
|
103788
|
+
const recordBytes = record.bytes;
|
|
103789
|
+
for (let j3 = 0;j3 < byteLength; j3++) {
|
|
103790
|
+
if (recordBytes[j3] !== bytes[inputOffset + j3]) {
|
|
103791
|
+
continue FIND_CHUNK;
|
|
103792
|
+
}
|
|
103793
|
+
}
|
|
103794
|
+
return record.str;
|
|
103795
|
+
}
|
|
103796
|
+
return null;
|
|
103797
|
+
}
|
|
103798
|
+
store(bytes, value) {
|
|
103799
|
+
const records = this.caches[bytes.length - 1];
|
|
103800
|
+
const record = { bytes, str: value };
|
|
103801
|
+
if (records.length >= this.maxLengthPerKey) {
|
|
103802
|
+
records[Math.random() * records.length | 0] = record;
|
|
103803
|
+
} else {
|
|
103804
|
+
records.push(record);
|
|
103805
|
+
}
|
|
103806
|
+
}
|
|
103807
|
+
decode(bytes, inputOffset, byteLength) {
|
|
103808
|
+
const cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
103809
|
+
if (cachedValue != null) {
|
|
103810
|
+
this.hit++;
|
|
103811
|
+
return cachedValue;
|
|
103812
|
+
}
|
|
103813
|
+
this.miss++;
|
|
103814
|
+
const str = (0, utf8_ts_1.utf8DecodeJs)(bytes, inputOffset, byteLength);
|
|
103815
|
+
const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
103816
|
+
this.store(slicedCopyOfBytes, str);
|
|
103817
|
+
return str;
|
|
103818
|
+
}
|
|
103819
|
+
}
|
|
103820
|
+
exports.CachedKeyDecoder = CachedKeyDecoder;
|
|
103821
|
+
});
|
|
103822
|
+
|
|
103823
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/Decoder.cjs
|
|
103824
|
+
var require_Decoder = __commonJS((exports) => {
|
|
103825
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103826
|
+
exports.Decoder = undefined;
|
|
103827
|
+
var prettyByte_ts_1 = require_prettyByte();
|
|
103828
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
103829
|
+
var int_ts_1 = require_int();
|
|
103830
|
+
var utf8_ts_1 = require_utf8();
|
|
103831
|
+
var typedArrays_ts_1 = require_typedArrays();
|
|
103832
|
+
var CachedKeyDecoder_ts_1 = require_CachedKeyDecoder();
|
|
103833
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
103834
|
+
var STATE_ARRAY = "array";
|
|
103835
|
+
var STATE_MAP_KEY = "map_key";
|
|
103836
|
+
var STATE_MAP_VALUE = "map_value";
|
|
103837
|
+
var mapKeyConverter = (key) => {
|
|
103838
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
103839
|
+
return key;
|
|
103840
|
+
}
|
|
103841
|
+
throw new DecodeError_ts_1.DecodeError("The type of key must be string or number but " + typeof key);
|
|
103842
|
+
};
|
|
103843
|
+
|
|
103844
|
+
class StackPool {
|
|
103845
|
+
stack = [];
|
|
103846
|
+
stackHeadPosition = -1;
|
|
103847
|
+
get length() {
|
|
103848
|
+
return this.stackHeadPosition + 1;
|
|
103849
|
+
}
|
|
103850
|
+
top() {
|
|
103851
|
+
return this.stack[this.stackHeadPosition];
|
|
103852
|
+
}
|
|
103853
|
+
pushArrayState(size) {
|
|
103854
|
+
const state = this.getUninitializedStateFromPool();
|
|
103855
|
+
state.type = STATE_ARRAY;
|
|
103856
|
+
state.position = 0;
|
|
103857
|
+
state.size = size;
|
|
103858
|
+
state.array = new Array(size);
|
|
103859
|
+
}
|
|
103860
|
+
pushMapState(size) {
|
|
103861
|
+
const state = this.getUninitializedStateFromPool();
|
|
103862
|
+
state.type = STATE_MAP_KEY;
|
|
103863
|
+
state.readCount = 0;
|
|
103864
|
+
state.size = size;
|
|
103865
|
+
state.map = {};
|
|
103866
|
+
}
|
|
103867
|
+
getUninitializedStateFromPool() {
|
|
103868
|
+
this.stackHeadPosition++;
|
|
103869
|
+
if (this.stackHeadPosition === this.stack.length) {
|
|
103870
|
+
const partialState = {
|
|
103871
|
+
type: undefined,
|
|
103872
|
+
size: 0,
|
|
103873
|
+
array: undefined,
|
|
103874
|
+
position: 0,
|
|
103875
|
+
readCount: 0,
|
|
103876
|
+
map: undefined,
|
|
103877
|
+
key: null
|
|
103878
|
+
};
|
|
103879
|
+
this.stack.push(partialState);
|
|
103880
|
+
}
|
|
103881
|
+
return this.stack[this.stackHeadPosition];
|
|
103882
|
+
}
|
|
103883
|
+
release(state) {
|
|
103884
|
+
const topStackState = this.stack[this.stackHeadPosition];
|
|
103885
|
+
if (topStackState !== state) {
|
|
103886
|
+
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
103887
|
+
}
|
|
103888
|
+
if (state.type === STATE_ARRAY) {
|
|
103889
|
+
const partialState = state;
|
|
103890
|
+
partialState.size = 0;
|
|
103891
|
+
partialState.array = undefined;
|
|
103892
|
+
partialState.position = 0;
|
|
103893
|
+
partialState.type = undefined;
|
|
103894
|
+
}
|
|
103895
|
+
if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
|
|
103896
|
+
const partialState = state;
|
|
103897
|
+
partialState.size = 0;
|
|
103898
|
+
partialState.map = undefined;
|
|
103899
|
+
partialState.readCount = 0;
|
|
103900
|
+
partialState.type = undefined;
|
|
103901
|
+
}
|
|
103902
|
+
this.stackHeadPosition--;
|
|
103903
|
+
}
|
|
103904
|
+
reset() {
|
|
103905
|
+
this.stack.length = 0;
|
|
103906
|
+
this.stackHeadPosition = -1;
|
|
103907
|
+
}
|
|
103908
|
+
}
|
|
103909
|
+
var HEAD_BYTE_REQUIRED = -1;
|
|
103910
|
+
var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
103911
|
+
var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
103912
|
+
try {
|
|
103913
|
+
EMPTY_VIEW.getInt8(0);
|
|
103914
|
+
} catch (e3) {
|
|
103915
|
+
if (!(e3 instanceof RangeError)) {
|
|
103916
|
+
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
103917
|
+
}
|
|
103918
|
+
}
|
|
103919
|
+
var MORE_DATA = new RangeError("Insufficient data");
|
|
103920
|
+
var sharedCachedKeyDecoder = new CachedKeyDecoder_ts_1.CachedKeyDecoder;
|
|
103921
|
+
|
|
103922
|
+
class Decoder {
|
|
103923
|
+
extensionCodec;
|
|
103924
|
+
context;
|
|
103925
|
+
useBigInt64;
|
|
103926
|
+
rawStrings;
|
|
103927
|
+
maxStrLength;
|
|
103928
|
+
maxBinLength;
|
|
103929
|
+
maxArrayLength;
|
|
103930
|
+
maxMapLength;
|
|
103931
|
+
maxExtLength;
|
|
103932
|
+
keyDecoder;
|
|
103933
|
+
mapKeyConverter;
|
|
103934
|
+
totalPos = 0;
|
|
103935
|
+
pos = 0;
|
|
103936
|
+
view = EMPTY_VIEW;
|
|
103937
|
+
bytes = EMPTY_BYTES;
|
|
103938
|
+
headByte = HEAD_BYTE_REQUIRED;
|
|
103939
|
+
stack = new StackPool;
|
|
103940
|
+
entered = false;
|
|
103941
|
+
constructor(options) {
|
|
103942
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec;
|
|
103943
|
+
this.context = options?.context;
|
|
103944
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
103945
|
+
this.rawStrings = options?.rawStrings ?? false;
|
|
103946
|
+
this.maxStrLength = options?.maxStrLength ?? int_ts_1.UINT32_MAX;
|
|
103947
|
+
this.maxBinLength = options?.maxBinLength ?? int_ts_1.UINT32_MAX;
|
|
103948
|
+
this.maxArrayLength = options?.maxArrayLength ?? int_ts_1.UINT32_MAX;
|
|
103949
|
+
this.maxMapLength = options?.maxMapLength ?? int_ts_1.UINT32_MAX;
|
|
103950
|
+
this.maxExtLength = options?.maxExtLength ?? int_ts_1.UINT32_MAX;
|
|
103951
|
+
this.keyDecoder = options?.keyDecoder !== undefined ? options.keyDecoder : sharedCachedKeyDecoder;
|
|
103952
|
+
this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
|
|
103953
|
+
}
|
|
103954
|
+
clone() {
|
|
103955
|
+
return new Decoder({
|
|
103956
|
+
extensionCodec: this.extensionCodec,
|
|
103957
|
+
context: this.context,
|
|
103958
|
+
useBigInt64: this.useBigInt64,
|
|
103959
|
+
rawStrings: this.rawStrings,
|
|
103960
|
+
maxStrLength: this.maxStrLength,
|
|
103961
|
+
maxBinLength: this.maxBinLength,
|
|
103962
|
+
maxArrayLength: this.maxArrayLength,
|
|
103963
|
+
maxMapLength: this.maxMapLength,
|
|
103964
|
+
maxExtLength: this.maxExtLength,
|
|
103965
|
+
keyDecoder: this.keyDecoder
|
|
103966
|
+
});
|
|
103967
|
+
}
|
|
103968
|
+
reinitializeState() {
|
|
103969
|
+
this.totalPos = 0;
|
|
103970
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
103971
|
+
this.stack.reset();
|
|
103972
|
+
}
|
|
103973
|
+
setBuffer(buffer2) {
|
|
103974
|
+
const bytes = (0, typedArrays_ts_1.ensureUint8Array)(buffer2);
|
|
103975
|
+
this.bytes = bytes;
|
|
103976
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
103977
|
+
this.pos = 0;
|
|
103978
|
+
}
|
|
103979
|
+
appendBuffer(buffer2) {
|
|
103980
|
+
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
|
|
103981
|
+
this.setBuffer(buffer2);
|
|
103982
|
+
} else {
|
|
103983
|
+
const remainingData = this.bytes.subarray(this.pos);
|
|
103984
|
+
const newData = (0, typedArrays_ts_1.ensureUint8Array)(buffer2);
|
|
103985
|
+
const newBuffer = new Uint8Array(remainingData.length + newData.length);
|
|
103986
|
+
newBuffer.set(remainingData);
|
|
103987
|
+
newBuffer.set(newData, remainingData.length);
|
|
103988
|
+
this.setBuffer(newBuffer);
|
|
103989
|
+
}
|
|
103990
|
+
}
|
|
103991
|
+
hasRemaining(size) {
|
|
103992
|
+
return this.view.byteLength - this.pos >= size;
|
|
103993
|
+
}
|
|
103994
|
+
createExtraByteError(posToShow) {
|
|
103995
|
+
const { view, pos } = this;
|
|
103996
|
+
return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
|
|
103997
|
+
}
|
|
103998
|
+
decode(buffer2) {
|
|
103999
|
+
if (this.entered) {
|
|
104000
|
+
const instance = this.clone();
|
|
104001
|
+
return instance.decode(buffer2);
|
|
104002
|
+
}
|
|
104003
|
+
try {
|
|
104004
|
+
this.entered = true;
|
|
104005
|
+
this.reinitializeState();
|
|
104006
|
+
this.setBuffer(buffer2);
|
|
104007
|
+
const object = this.doDecodeSync();
|
|
104008
|
+
if (this.hasRemaining(1)) {
|
|
104009
|
+
throw this.createExtraByteError(this.pos);
|
|
104010
|
+
}
|
|
104011
|
+
return object;
|
|
104012
|
+
} finally {
|
|
104013
|
+
this.entered = false;
|
|
104014
|
+
}
|
|
104015
|
+
}
|
|
104016
|
+
*decodeMulti(buffer2) {
|
|
104017
|
+
if (this.entered) {
|
|
104018
|
+
const instance = this.clone();
|
|
104019
|
+
yield* instance.decodeMulti(buffer2);
|
|
104020
|
+
return;
|
|
104021
|
+
}
|
|
104022
|
+
try {
|
|
104023
|
+
this.entered = true;
|
|
104024
|
+
this.reinitializeState();
|
|
104025
|
+
this.setBuffer(buffer2);
|
|
104026
|
+
while (this.hasRemaining(1)) {
|
|
104027
|
+
yield this.doDecodeSync();
|
|
104028
|
+
}
|
|
104029
|
+
} finally {
|
|
104030
|
+
this.entered = false;
|
|
104031
|
+
}
|
|
104032
|
+
}
|
|
104033
|
+
async decodeAsync(stream) {
|
|
104034
|
+
if (this.entered) {
|
|
104035
|
+
const instance = this.clone();
|
|
104036
|
+
return instance.decodeAsync(stream);
|
|
104037
|
+
}
|
|
104038
|
+
try {
|
|
104039
|
+
this.entered = true;
|
|
104040
|
+
let decoded = false;
|
|
104041
|
+
let object;
|
|
104042
|
+
for await (const buffer2 of stream) {
|
|
104043
|
+
if (decoded) {
|
|
104044
|
+
this.entered = false;
|
|
104045
|
+
throw this.createExtraByteError(this.totalPos);
|
|
104046
|
+
}
|
|
104047
|
+
this.appendBuffer(buffer2);
|
|
104048
|
+
try {
|
|
104049
|
+
object = this.doDecodeSync();
|
|
104050
|
+
decoded = true;
|
|
104051
|
+
} catch (e3) {
|
|
104052
|
+
if (!(e3 instanceof RangeError)) {
|
|
104053
|
+
throw e3;
|
|
104054
|
+
}
|
|
104055
|
+
}
|
|
104056
|
+
this.totalPos += this.pos;
|
|
104057
|
+
}
|
|
104058
|
+
if (decoded) {
|
|
104059
|
+
if (this.hasRemaining(1)) {
|
|
104060
|
+
throw this.createExtraByteError(this.totalPos);
|
|
104061
|
+
}
|
|
104062
|
+
return object;
|
|
104063
|
+
}
|
|
104064
|
+
const { headByte, pos, totalPos } = this;
|
|
104065
|
+
throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_ts_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`);
|
|
104066
|
+
} finally {
|
|
104067
|
+
this.entered = false;
|
|
104068
|
+
}
|
|
104069
|
+
}
|
|
104070
|
+
decodeArrayStream(stream) {
|
|
104071
|
+
return this.decodeMultiAsync(stream, true);
|
|
104072
|
+
}
|
|
104073
|
+
decodeStream(stream) {
|
|
104074
|
+
return this.decodeMultiAsync(stream, false);
|
|
104075
|
+
}
|
|
104076
|
+
async* decodeMultiAsync(stream, isArray) {
|
|
104077
|
+
if (this.entered) {
|
|
104078
|
+
const instance = this.clone();
|
|
104079
|
+
yield* instance.decodeMultiAsync(stream, isArray);
|
|
104080
|
+
return;
|
|
104081
|
+
}
|
|
104082
|
+
try {
|
|
104083
|
+
this.entered = true;
|
|
104084
|
+
let isArrayHeaderRequired = isArray;
|
|
104085
|
+
let arrayItemsLeft = -1;
|
|
104086
|
+
for await (const buffer2 of stream) {
|
|
104087
|
+
if (isArray && arrayItemsLeft === 0) {
|
|
104088
|
+
throw this.createExtraByteError(this.totalPos);
|
|
104089
|
+
}
|
|
104090
|
+
this.appendBuffer(buffer2);
|
|
104091
|
+
if (isArrayHeaderRequired) {
|
|
104092
|
+
arrayItemsLeft = this.readArraySize();
|
|
104093
|
+
isArrayHeaderRequired = false;
|
|
104094
|
+
this.complete();
|
|
104095
|
+
}
|
|
104096
|
+
try {
|
|
104097
|
+
while (true) {
|
|
104098
|
+
yield this.doDecodeSync();
|
|
104099
|
+
if (--arrayItemsLeft === 0) {
|
|
104100
|
+
break;
|
|
104101
|
+
}
|
|
104102
|
+
}
|
|
104103
|
+
} catch (e3) {
|
|
104104
|
+
if (!(e3 instanceof RangeError)) {
|
|
104105
|
+
throw e3;
|
|
104106
|
+
}
|
|
104107
|
+
}
|
|
104108
|
+
this.totalPos += this.pos;
|
|
104109
|
+
}
|
|
104110
|
+
} finally {
|
|
104111
|
+
this.entered = false;
|
|
104112
|
+
}
|
|
104113
|
+
}
|
|
104114
|
+
doDecodeSync() {
|
|
104115
|
+
DECODE:
|
|
104116
|
+
while (true) {
|
|
104117
|
+
const headByte = this.readHeadByte();
|
|
104118
|
+
let object;
|
|
104119
|
+
if (headByte >= 224) {
|
|
104120
|
+
object = headByte - 256;
|
|
104121
|
+
} else if (headByte < 192) {
|
|
104122
|
+
if (headByte < 128) {
|
|
104123
|
+
object = headByte;
|
|
104124
|
+
} else if (headByte < 144) {
|
|
104125
|
+
const size = headByte - 128;
|
|
104126
|
+
if (size !== 0) {
|
|
104127
|
+
this.pushMapState(size);
|
|
104128
|
+
this.complete();
|
|
104129
|
+
continue DECODE;
|
|
104130
|
+
} else {
|
|
104131
|
+
object = {};
|
|
104132
|
+
}
|
|
104133
|
+
} else if (headByte < 160) {
|
|
104134
|
+
const size = headByte - 144;
|
|
104135
|
+
if (size !== 0) {
|
|
104136
|
+
this.pushArrayState(size);
|
|
104137
|
+
this.complete();
|
|
104138
|
+
continue DECODE;
|
|
104139
|
+
} else {
|
|
104140
|
+
object = [];
|
|
104141
|
+
}
|
|
104142
|
+
} else {
|
|
104143
|
+
const byteLength = headByte - 160;
|
|
104144
|
+
object = this.decodeString(byteLength, 0);
|
|
104145
|
+
}
|
|
104146
|
+
} else if (headByte === 192) {
|
|
104147
|
+
object = null;
|
|
104148
|
+
} else if (headByte === 194) {
|
|
104149
|
+
object = false;
|
|
104150
|
+
} else if (headByte === 195) {
|
|
104151
|
+
object = true;
|
|
104152
|
+
} else if (headByte === 202) {
|
|
104153
|
+
object = this.readF32();
|
|
104154
|
+
} else if (headByte === 203) {
|
|
104155
|
+
object = this.readF64();
|
|
104156
|
+
} else if (headByte === 204) {
|
|
104157
|
+
object = this.readU8();
|
|
104158
|
+
} else if (headByte === 205) {
|
|
104159
|
+
object = this.readU16();
|
|
104160
|
+
} else if (headByte === 206) {
|
|
104161
|
+
object = this.readU32();
|
|
104162
|
+
} else if (headByte === 207) {
|
|
104163
|
+
if (this.useBigInt64) {
|
|
104164
|
+
object = this.readU64AsBigInt();
|
|
104165
|
+
} else {
|
|
104166
|
+
object = this.readU64();
|
|
104167
|
+
}
|
|
104168
|
+
} else if (headByte === 208) {
|
|
104169
|
+
object = this.readI8();
|
|
104170
|
+
} else if (headByte === 209) {
|
|
104171
|
+
object = this.readI16();
|
|
104172
|
+
} else if (headByte === 210) {
|
|
104173
|
+
object = this.readI32();
|
|
104174
|
+
} else if (headByte === 211) {
|
|
104175
|
+
if (this.useBigInt64) {
|
|
104176
|
+
object = this.readI64AsBigInt();
|
|
104177
|
+
} else {
|
|
104178
|
+
object = this.readI64();
|
|
104179
|
+
}
|
|
104180
|
+
} else if (headByte === 217) {
|
|
104181
|
+
const byteLength = this.lookU8();
|
|
104182
|
+
object = this.decodeString(byteLength, 1);
|
|
104183
|
+
} else if (headByte === 218) {
|
|
104184
|
+
const byteLength = this.lookU16();
|
|
104185
|
+
object = this.decodeString(byteLength, 2);
|
|
104186
|
+
} else if (headByte === 219) {
|
|
104187
|
+
const byteLength = this.lookU32();
|
|
104188
|
+
object = this.decodeString(byteLength, 4);
|
|
104189
|
+
} else if (headByte === 220) {
|
|
104190
|
+
const size = this.readU16();
|
|
104191
|
+
if (size !== 0) {
|
|
104192
|
+
this.pushArrayState(size);
|
|
104193
|
+
this.complete();
|
|
104194
|
+
continue DECODE;
|
|
104195
|
+
} else {
|
|
104196
|
+
object = [];
|
|
104197
|
+
}
|
|
104198
|
+
} else if (headByte === 221) {
|
|
104199
|
+
const size = this.readU32();
|
|
104200
|
+
if (size !== 0) {
|
|
104201
|
+
this.pushArrayState(size);
|
|
104202
|
+
this.complete();
|
|
104203
|
+
continue DECODE;
|
|
104204
|
+
} else {
|
|
104205
|
+
object = [];
|
|
104206
|
+
}
|
|
104207
|
+
} else if (headByte === 222) {
|
|
104208
|
+
const size = this.readU16();
|
|
104209
|
+
if (size !== 0) {
|
|
104210
|
+
this.pushMapState(size);
|
|
104211
|
+
this.complete();
|
|
104212
|
+
continue DECODE;
|
|
104213
|
+
} else {
|
|
104214
|
+
object = {};
|
|
104215
|
+
}
|
|
104216
|
+
} else if (headByte === 223) {
|
|
104217
|
+
const size = this.readU32();
|
|
104218
|
+
if (size !== 0) {
|
|
104219
|
+
this.pushMapState(size);
|
|
104220
|
+
this.complete();
|
|
104221
|
+
continue DECODE;
|
|
104222
|
+
} else {
|
|
104223
|
+
object = {};
|
|
104224
|
+
}
|
|
104225
|
+
} else if (headByte === 196) {
|
|
104226
|
+
const size = this.lookU8();
|
|
104227
|
+
object = this.decodeBinary(size, 1);
|
|
104228
|
+
} else if (headByte === 197) {
|
|
104229
|
+
const size = this.lookU16();
|
|
104230
|
+
object = this.decodeBinary(size, 2);
|
|
104231
|
+
} else if (headByte === 198) {
|
|
104232
|
+
const size = this.lookU32();
|
|
104233
|
+
object = this.decodeBinary(size, 4);
|
|
104234
|
+
} else if (headByte === 212) {
|
|
104235
|
+
object = this.decodeExtension(1, 0);
|
|
104236
|
+
} else if (headByte === 213) {
|
|
104237
|
+
object = this.decodeExtension(2, 0);
|
|
104238
|
+
} else if (headByte === 214) {
|
|
104239
|
+
object = this.decodeExtension(4, 0);
|
|
104240
|
+
} else if (headByte === 215) {
|
|
104241
|
+
object = this.decodeExtension(8, 0);
|
|
104242
|
+
} else if (headByte === 216) {
|
|
104243
|
+
object = this.decodeExtension(16, 0);
|
|
104244
|
+
} else if (headByte === 199) {
|
|
104245
|
+
const size = this.lookU8();
|
|
104246
|
+
object = this.decodeExtension(size, 1);
|
|
104247
|
+
} else if (headByte === 200) {
|
|
104248
|
+
const size = this.lookU16();
|
|
104249
|
+
object = this.decodeExtension(size, 2);
|
|
104250
|
+
} else if (headByte === 201) {
|
|
104251
|
+
const size = this.lookU32();
|
|
104252
|
+
object = this.decodeExtension(size, 4);
|
|
104253
|
+
} else {
|
|
104254
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`);
|
|
104255
|
+
}
|
|
104256
|
+
this.complete();
|
|
104257
|
+
const stack = this.stack;
|
|
104258
|
+
while (stack.length > 0) {
|
|
104259
|
+
const state = stack.top();
|
|
104260
|
+
if (state.type === STATE_ARRAY) {
|
|
104261
|
+
state.array[state.position] = object;
|
|
104262
|
+
state.position++;
|
|
104263
|
+
if (state.position === state.size) {
|
|
104264
|
+
object = state.array;
|
|
104265
|
+
stack.release(state);
|
|
104266
|
+
} else {
|
|
104267
|
+
continue DECODE;
|
|
104268
|
+
}
|
|
104269
|
+
} else if (state.type === STATE_MAP_KEY) {
|
|
104270
|
+
if (object === "__proto__") {
|
|
104271
|
+
throw new DecodeError_ts_1.DecodeError("The key __proto__ is not allowed");
|
|
104272
|
+
}
|
|
104273
|
+
state.key = this.mapKeyConverter(object);
|
|
104274
|
+
state.type = STATE_MAP_VALUE;
|
|
104275
|
+
continue DECODE;
|
|
104276
|
+
} else {
|
|
104277
|
+
state.map[state.key] = object;
|
|
104278
|
+
state.readCount++;
|
|
104279
|
+
if (state.readCount === state.size) {
|
|
104280
|
+
object = state.map;
|
|
104281
|
+
stack.release(state);
|
|
104282
|
+
} else {
|
|
104283
|
+
state.key = null;
|
|
104284
|
+
state.type = STATE_MAP_KEY;
|
|
104285
|
+
continue DECODE;
|
|
104286
|
+
}
|
|
104287
|
+
}
|
|
104288
|
+
}
|
|
104289
|
+
return object;
|
|
104290
|
+
}
|
|
104291
|
+
}
|
|
104292
|
+
readHeadByte() {
|
|
104293
|
+
if (this.headByte === HEAD_BYTE_REQUIRED) {
|
|
104294
|
+
this.headByte = this.readU8();
|
|
104295
|
+
}
|
|
104296
|
+
return this.headByte;
|
|
104297
|
+
}
|
|
104298
|
+
complete() {
|
|
104299
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
104300
|
+
}
|
|
104301
|
+
readArraySize() {
|
|
104302
|
+
const headByte = this.readHeadByte();
|
|
104303
|
+
switch (headByte) {
|
|
104304
|
+
case 220:
|
|
104305
|
+
return this.readU16();
|
|
104306
|
+
case 221:
|
|
104307
|
+
return this.readU32();
|
|
104308
|
+
default: {
|
|
104309
|
+
if (headByte < 160) {
|
|
104310
|
+
return headByte - 144;
|
|
104311
|
+
} else {
|
|
104312
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized array type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`);
|
|
104313
|
+
}
|
|
104314
|
+
}
|
|
104315
|
+
}
|
|
104316
|
+
}
|
|
104317
|
+
pushMapState(size) {
|
|
104318
|
+
if (size > this.maxMapLength) {
|
|
104319
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
104320
|
+
}
|
|
104321
|
+
this.stack.pushMapState(size);
|
|
104322
|
+
}
|
|
104323
|
+
pushArrayState(size) {
|
|
104324
|
+
if (size > this.maxArrayLength) {
|
|
104325
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`);
|
|
104326
|
+
}
|
|
104327
|
+
this.stack.pushArrayState(size);
|
|
104328
|
+
}
|
|
104329
|
+
decodeString(byteLength, headerOffset) {
|
|
104330
|
+
if (!this.rawStrings || this.stateIsMapKey()) {
|
|
104331
|
+
return this.decodeUtf8String(byteLength, headerOffset);
|
|
104332
|
+
}
|
|
104333
|
+
return this.decodeBinary(byteLength, headerOffset);
|
|
104334
|
+
}
|
|
104335
|
+
decodeUtf8String(byteLength, headerOffset) {
|
|
104336
|
+
if (byteLength > this.maxStrLength) {
|
|
104337
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
|
|
104338
|
+
}
|
|
104339
|
+
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
104340
|
+
throw MORE_DATA;
|
|
104341
|
+
}
|
|
104342
|
+
const offset = this.pos + headerOffset;
|
|
104343
|
+
let object;
|
|
104344
|
+
if (this.stateIsMapKey() && this.keyDecoder?.canBeCached(byteLength)) {
|
|
104345
|
+
object = this.keyDecoder.decode(this.bytes, offset, byteLength);
|
|
104346
|
+
} else {
|
|
104347
|
+
object = (0, utf8_ts_1.utf8Decode)(this.bytes, offset, byteLength);
|
|
104348
|
+
}
|
|
104349
|
+
this.pos += headerOffset + byteLength;
|
|
104350
|
+
return object;
|
|
104351
|
+
}
|
|
104352
|
+
stateIsMapKey() {
|
|
104353
|
+
if (this.stack.length > 0) {
|
|
104354
|
+
const state = this.stack.top();
|
|
104355
|
+
return state.type === STATE_MAP_KEY;
|
|
104356
|
+
}
|
|
104357
|
+
return false;
|
|
104358
|
+
}
|
|
104359
|
+
decodeBinary(byteLength, headOffset) {
|
|
104360
|
+
if (byteLength > this.maxBinLength) {
|
|
104361
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
|
|
104362
|
+
}
|
|
104363
|
+
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
104364
|
+
throw MORE_DATA;
|
|
104365
|
+
}
|
|
104366
|
+
const offset = this.pos + headOffset;
|
|
104367
|
+
const object = this.bytes.subarray(offset, offset + byteLength);
|
|
104368
|
+
this.pos += headOffset + byteLength;
|
|
104369
|
+
return object;
|
|
104370
|
+
}
|
|
104371
|
+
decodeExtension(size, headOffset) {
|
|
104372
|
+
if (size > this.maxExtLength) {
|
|
104373
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: ext length (${size}) > maxExtLength (${this.maxExtLength})`);
|
|
104374
|
+
}
|
|
104375
|
+
const extType = this.view.getInt8(this.pos + headOffset);
|
|
104376
|
+
const data = this.decodeBinary(size, headOffset + 1);
|
|
104377
|
+
return this.extensionCodec.decode(data, extType, this.context);
|
|
104378
|
+
}
|
|
104379
|
+
lookU8() {
|
|
104380
|
+
return this.view.getUint8(this.pos);
|
|
104381
|
+
}
|
|
104382
|
+
lookU16() {
|
|
104383
|
+
return this.view.getUint16(this.pos);
|
|
104384
|
+
}
|
|
104385
|
+
lookU32() {
|
|
104386
|
+
return this.view.getUint32(this.pos);
|
|
104387
|
+
}
|
|
104388
|
+
readU8() {
|
|
104389
|
+
const value = this.view.getUint8(this.pos);
|
|
104390
|
+
this.pos++;
|
|
104391
|
+
return value;
|
|
104392
|
+
}
|
|
104393
|
+
readI8() {
|
|
104394
|
+
const value = this.view.getInt8(this.pos);
|
|
104395
|
+
this.pos++;
|
|
104396
|
+
return value;
|
|
104397
|
+
}
|
|
104398
|
+
readU16() {
|
|
104399
|
+
const value = this.view.getUint16(this.pos);
|
|
104400
|
+
this.pos += 2;
|
|
104401
|
+
return value;
|
|
104402
|
+
}
|
|
104403
|
+
readI16() {
|
|
104404
|
+
const value = this.view.getInt16(this.pos);
|
|
104405
|
+
this.pos += 2;
|
|
104406
|
+
return value;
|
|
104407
|
+
}
|
|
104408
|
+
readU32() {
|
|
104409
|
+
const value = this.view.getUint32(this.pos);
|
|
104410
|
+
this.pos += 4;
|
|
104411
|
+
return value;
|
|
104412
|
+
}
|
|
104413
|
+
readI32() {
|
|
104414
|
+
const value = this.view.getInt32(this.pos);
|
|
104415
|
+
this.pos += 4;
|
|
104416
|
+
return value;
|
|
104417
|
+
}
|
|
104418
|
+
readU64() {
|
|
104419
|
+
const value = (0, int_ts_1.getUint64)(this.view, this.pos);
|
|
104420
|
+
this.pos += 8;
|
|
104421
|
+
return value;
|
|
104422
|
+
}
|
|
104423
|
+
readI64() {
|
|
104424
|
+
const value = (0, int_ts_1.getInt64)(this.view, this.pos);
|
|
104425
|
+
this.pos += 8;
|
|
104426
|
+
return value;
|
|
104427
|
+
}
|
|
104428
|
+
readU64AsBigInt() {
|
|
104429
|
+
const value = this.view.getBigUint64(this.pos);
|
|
104430
|
+
this.pos += 8;
|
|
104431
|
+
return value;
|
|
104432
|
+
}
|
|
104433
|
+
readI64AsBigInt() {
|
|
104434
|
+
const value = this.view.getBigInt64(this.pos);
|
|
104435
|
+
this.pos += 8;
|
|
104436
|
+
return value;
|
|
104437
|
+
}
|
|
104438
|
+
readF32() {
|
|
104439
|
+
const value = this.view.getFloat32(this.pos);
|
|
104440
|
+
this.pos += 4;
|
|
104441
|
+
return value;
|
|
104442
|
+
}
|
|
104443
|
+
readF64() {
|
|
104444
|
+
const value = this.view.getFloat64(this.pos);
|
|
104445
|
+
this.pos += 8;
|
|
104446
|
+
return value;
|
|
104447
|
+
}
|
|
104448
|
+
}
|
|
104449
|
+
exports.Decoder = Decoder;
|
|
104450
|
+
});
|
|
104451
|
+
|
|
104452
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/decode.cjs
|
|
104453
|
+
var require_decode = __commonJS((exports) => {
|
|
104454
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104455
|
+
exports.decode = decode;
|
|
104456
|
+
exports.decodeMulti = decodeMulti;
|
|
104457
|
+
var Decoder_ts_1 = require_Decoder();
|
|
104458
|
+
function decode(buffer2, options) {
|
|
104459
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
104460
|
+
return decoder.decode(buffer2);
|
|
104461
|
+
}
|
|
104462
|
+
function decodeMulti(buffer2, options) {
|
|
104463
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
104464
|
+
return decoder.decodeMulti(buffer2);
|
|
104465
|
+
}
|
|
104466
|
+
});
|
|
104467
|
+
|
|
104468
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/utils/stream.cjs
|
|
104469
|
+
var require_stream2 = __commonJS((exports) => {
|
|
104470
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104471
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
104472
|
+
exports.asyncIterableFromStream = asyncIterableFromStream;
|
|
104473
|
+
exports.ensureAsyncIterable = ensureAsyncIterable;
|
|
104474
|
+
function isAsyncIterable(object) {
|
|
104475
|
+
return object[Symbol.asyncIterator] != null;
|
|
104476
|
+
}
|
|
104477
|
+
async function* asyncIterableFromStream(stream) {
|
|
104478
|
+
const reader = stream.getReader();
|
|
104479
|
+
try {
|
|
104480
|
+
while (true) {
|
|
104481
|
+
const { done, value } = await reader.read();
|
|
104482
|
+
if (done) {
|
|
104483
|
+
return;
|
|
104484
|
+
}
|
|
104485
|
+
yield value;
|
|
104486
|
+
}
|
|
104487
|
+
} finally {
|
|
104488
|
+
reader.releaseLock();
|
|
104489
|
+
}
|
|
104490
|
+
}
|
|
104491
|
+
function ensureAsyncIterable(streamLike) {
|
|
104492
|
+
if (isAsyncIterable(streamLike)) {
|
|
104493
|
+
return streamLike;
|
|
104494
|
+
} else {
|
|
104495
|
+
return asyncIterableFromStream(streamLike);
|
|
104496
|
+
}
|
|
104497
|
+
}
|
|
104498
|
+
});
|
|
104499
|
+
|
|
104500
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/decodeAsync.cjs
|
|
104501
|
+
var require_decodeAsync = __commonJS((exports) => {
|
|
104502
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104503
|
+
exports.decodeAsync = decodeAsync;
|
|
104504
|
+
exports.decodeArrayStream = decodeArrayStream;
|
|
104505
|
+
exports.decodeMultiStream = decodeMultiStream;
|
|
104506
|
+
var Decoder_ts_1 = require_Decoder();
|
|
104507
|
+
var stream_ts_1 = require_stream2();
|
|
104508
|
+
async function decodeAsync(streamLike, options) {
|
|
104509
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
104510
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
104511
|
+
return decoder.decodeAsync(stream);
|
|
104512
|
+
}
|
|
104513
|
+
function decodeArrayStream(streamLike, options) {
|
|
104514
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
104515
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
104516
|
+
return decoder.decodeArrayStream(stream);
|
|
104517
|
+
}
|
|
104518
|
+
function decodeMultiStream(streamLike, options) {
|
|
104519
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
104520
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
104521
|
+
return decoder.decodeStream(stream);
|
|
104522
|
+
}
|
|
104523
|
+
});
|
|
104524
|
+
|
|
104525
|
+
// ../../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.cjs/index.cjs
|
|
104526
|
+
var require_dist6 = __commonJS((exports) => {
|
|
104527
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104528
|
+
exports.decodeTimestampExtension = exports.encodeTimestampExtension = exports.decodeTimestampToTimeSpec = exports.encodeTimeSpecToTimestamp = exports.encodeDateToTimeSpec = exports.EXT_TIMESTAMP = exports.ExtData = exports.ExtensionCodec = exports.Encoder = exports.DecodeError = exports.Decoder = exports.decodeMultiStream = exports.decodeArrayStream = exports.decodeAsync = exports.decodeMulti = exports.decode = exports.encode = undefined;
|
|
104529
|
+
var encode_ts_1 = require_encode();
|
|
104530
|
+
Object.defineProperty(exports, "encode", { enumerable: true, get: function() {
|
|
104531
|
+
return encode_ts_1.encode;
|
|
104532
|
+
} });
|
|
104533
|
+
var decode_ts_1 = require_decode();
|
|
104534
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function() {
|
|
104535
|
+
return decode_ts_1.decode;
|
|
104536
|
+
} });
|
|
104537
|
+
Object.defineProperty(exports, "decodeMulti", { enumerable: true, get: function() {
|
|
104538
|
+
return decode_ts_1.decodeMulti;
|
|
104539
|
+
} });
|
|
104540
|
+
var decodeAsync_ts_1 = require_decodeAsync();
|
|
104541
|
+
Object.defineProperty(exports, "decodeAsync", { enumerable: true, get: function() {
|
|
104542
|
+
return decodeAsync_ts_1.decodeAsync;
|
|
104543
|
+
} });
|
|
104544
|
+
Object.defineProperty(exports, "decodeArrayStream", { enumerable: true, get: function() {
|
|
104545
|
+
return decodeAsync_ts_1.decodeArrayStream;
|
|
104546
|
+
} });
|
|
104547
|
+
Object.defineProperty(exports, "decodeMultiStream", { enumerable: true, get: function() {
|
|
104548
|
+
return decodeAsync_ts_1.decodeMultiStream;
|
|
104549
|
+
} });
|
|
104550
|
+
var Decoder_ts_1 = require_Decoder();
|
|
104551
|
+
Object.defineProperty(exports, "Decoder", { enumerable: true, get: function() {
|
|
104552
|
+
return Decoder_ts_1.Decoder;
|
|
104553
|
+
} });
|
|
104554
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
104555
|
+
Object.defineProperty(exports, "DecodeError", { enumerable: true, get: function() {
|
|
104556
|
+
return DecodeError_ts_1.DecodeError;
|
|
104557
|
+
} });
|
|
104558
|
+
var Encoder_ts_1 = require_Encoder();
|
|
104559
|
+
Object.defineProperty(exports, "Encoder", { enumerable: true, get: function() {
|
|
104560
|
+
return Encoder_ts_1.Encoder;
|
|
104561
|
+
} });
|
|
104562
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
104563
|
+
Object.defineProperty(exports, "ExtensionCodec", { enumerable: true, get: function() {
|
|
104564
|
+
return ExtensionCodec_ts_1.ExtensionCodec;
|
|
104565
|
+
} });
|
|
104566
|
+
var ExtData_ts_1 = require_ExtData();
|
|
104567
|
+
Object.defineProperty(exports, "ExtData", { enumerable: true, get: function() {
|
|
104568
|
+
return ExtData_ts_1.ExtData;
|
|
104569
|
+
} });
|
|
104570
|
+
var timestamp_ts_1 = require_timestamp();
|
|
104571
|
+
Object.defineProperty(exports, "EXT_TIMESTAMP", { enumerable: true, get: function() {
|
|
104572
|
+
return timestamp_ts_1.EXT_TIMESTAMP;
|
|
104573
|
+
} });
|
|
104574
|
+
Object.defineProperty(exports, "encodeDateToTimeSpec", { enumerable: true, get: function() {
|
|
104575
|
+
return timestamp_ts_1.encodeDateToTimeSpec;
|
|
104576
|
+
} });
|
|
104577
|
+
Object.defineProperty(exports, "encodeTimeSpecToTimestamp", { enumerable: true, get: function() {
|
|
104578
|
+
return timestamp_ts_1.encodeTimeSpecToTimestamp;
|
|
104579
|
+
} });
|
|
104580
|
+
Object.defineProperty(exports, "decodeTimestampToTimeSpec", { enumerable: true, get: function() {
|
|
104581
|
+
return timestamp_ts_1.decodeTimestampToTimeSpec;
|
|
104582
|
+
} });
|
|
104583
|
+
Object.defineProperty(exports, "encodeTimestampExtension", { enumerable: true, get: function() {
|
|
104584
|
+
return timestamp_ts_1.encodeTimestampExtension;
|
|
104585
|
+
} });
|
|
104586
|
+
Object.defineProperty(exports, "decodeTimestampExtension", { enumerable: true, get: function() {
|
|
104587
|
+
return timestamp_ts_1.decodeTimestampExtension;
|
|
104588
|
+
} });
|
|
104589
|
+
});
|
|
104590
|
+
|
|
104591
|
+
// ../stream/src/serializers/MessagePackSerializer.ts
|
|
104592
|
+
var exports_MessagePackSerializer = {};
|
|
104593
|
+
__export(exports_MessagePackSerializer, {
|
|
104594
|
+
MessagePackSerializer: () => MessagePackSerializer
|
|
104595
|
+
});
|
|
104596
|
+
|
|
104597
|
+
class MessagePackSerializer {
|
|
104598
|
+
msgpack;
|
|
104599
|
+
constructor() {
|
|
104600
|
+
try {
|
|
104601
|
+
this.msgpack = require_dist6();
|
|
104602
|
+
} catch (_e3) {
|
|
104603
|
+
throw new Error("MessagePackSerializer requires @msgpack/msgpack. Please install it: bun add @msgpack/msgpack");
|
|
104604
|
+
}
|
|
104605
|
+
}
|
|
104606
|
+
serialize(job) {
|
|
104607
|
+
const id = job.id || `${Date.now()}-${crypto.randomUUID()}`;
|
|
104608
|
+
const properties = {};
|
|
104609
|
+
for (const key in job) {
|
|
104610
|
+
if (Object.hasOwn(job, key) && typeof job[key] !== "function") {
|
|
104611
|
+
properties[key] = job[key];
|
|
104612
|
+
}
|
|
104613
|
+
}
|
|
104614
|
+
const encoded = this.msgpack.encode(properties);
|
|
104615
|
+
const data = Buffer.from(encoded).toString("base64");
|
|
104616
|
+
return {
|
|
104617
|
+
id,
|
|
104618
|
+
type: "msgpack",
|
|
104619
|
+
data,
|
|
104620
|
+
createdAt: Date.now(),
|
|
104621
|
+
...job.delaySeconds !== undefined ? { delaySeconds: job.delaySeconds } : {},
|
|
104622
|
+
attempts: job.attempts ?? 0,
|
|
104623
|
+
...job.maxAttempts !== undefined ? { maxAttempts: job.maxAttempts } : {},
|
|
104624
|
+
...job.groupId ? { groupId: job.groupId } : {},
|
|
104625
|
+
...job.priority ? { priority: job.priority } : {}
|
|
104626
|
+
};
|
|
104627
|
+
}
|
|
104628
|
+
deserialize(serialized) {
|
|
104629
|
+
if (serialized.type !== "msgpack") {
|
|
104630
|
+
throw new Error('Invalid serialization type: expected "msgpack"');
|
|
104631
|
+
}
|
|
104632
|
+
const buffer2 = Buffer.from(serialized.data, "base64");
|
|
104633
|
+
const properties = this.msgpack.decode(buffer2);
|
|
104634
|
+
const job = Object.create({});
|
|
104635
|
+
Object.assign(job, properties);
|
|
104636
|
+
job.id = serialized.id;
|
|
104637
|
+
if (serialized.groupId) {
|
|
104638
|
+
job.groupId = serialized.groupId;
|
|
104639
|
+
}
|
|
104640
|
+
if (serialized.priority) {
|
|
104641
|
+
job.priority = serialized.priority;
|
|
104642
|
+
}
|
|
104643
|
+
if (serialized.delaySeconds !== undefined) {
|
|
104644
|
+
job.delaySeconds = serialized.delaySeconds;
|
|
104645
|
+
}
|
|
104646
|
+
if (serialized.attempts !== undefined) {
|
|
104647
|
+
job.attempts = serialized.attempts;
|
|
104648
|
+
}
|
|
104649
|
+
return job;
|
|
104650
|
+
}
|
|
104651
|
+
}
|
|
104652
|
+
|
|
102436
104653
|
// ../../node_modules/.bun/cron-parser@5.4.0/node_modules/cron-parser/dist/fields/types.js
|
|
102437
104654
|
var require_types2 = __commonJS((exports) => {
|
|
102438
104655
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -108756,7 +110973,7 @@ var require_CronFileParser = __commonJS((exports) => {
|
|
|
108756
110973
|
});
|
|
108757
110974
|
|
|
108758
110975
|
// ../../node_modules/.bun/cron-parser@5.4.0/node_modules/cron-parser/dist/index.js
|
|
108759
|
-
var
|
|
110976
|
+
var require_dist7 = __commonJS((exports) => {
|
|
108760
110977
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o3, m3, k3, k22) {
|
|
108761
110978
|
if (k22 === undefined)
|
|
108762
110979
|
k22 = k3;
|
|
@@ -108819,6 +111036,9 @@ class Scheduler {
|
|
|
108819
111036
|
}
|
|
108820
111037
|
get client() {
|
|
108821
111038
|
const driver = this.manager.getDriver(this.manager.getDefaultConnection());
|
|
111039
|
+
if (!driver || !("client" in driver)) {
|
|
111040
|
+
throw new Error("[Scheduler] Driver does not support Redis client access");
|
|
111041
|
+
}
|
|
108822
111042
|
return driver.client;
|
|
108823
111043
|
}
|
|
108824
111044
|
async register(config) {
|
|
@@ -108828,7 +111048,11 @@ class Scheduler {
|
|
|
108828
111048
|
nextRun,
|
|
108829
111049
|
enabled: true
|
|
108830
111050
|
};
|
|
108831
|
-
const
|
|
111051
|
+
const client = this.client;
|
|
111052
|
+
if (typeof client.pipeline !== "function") {
|
|
111053
|
+
throw new Error("[Scheduler] Redis client does not support pipeline");
|
|
111054
|
+
}
|
|
111055
|
+
const pipe = client.pipeline();
|
|
108832
111056
|
pipe.hset(`${this.prefix}schedule:${config.id}`, {
|
|
108833
111057
|
...fullConfig,
|
|
108834
111058
|
job: JSON.stringify(fullConfig.job)
|
|
@@ -108837,16 +111061,24 @@ class Scheduler {
|
|
|
108837
111061
|
await pipe.exec();
|
|
108838
111062
|
}
|
|
108839
111063
|
async remove(id) {
|
|
108840
|
-
const
|
|
111064
|
+
const client = this.client;
|
|
111065
|
+
if (typeof client.pipeline !== "function") {
|
|
111066
|
+
throw new Error("[Scheduler] Redis client does not support pipeline");
|
|
111067
|
+
}
|
|
111068
|
+
const pipe = client.pipeline();
|
|
108841
111069
|
pipe.del(`${this.prefix}schedule:${id}`);
|
|
108842
111070
|
pipe.zrem(`${this.prefix}schedules`, id);
|
|
108843
111071
|
await pipe.exec();
|
|
108844
111072
|
}
|
|
108845
111073
|
async list() {
|
|
108846
|
-
const
|
|
111074
|
+
const client = this.client;
|
|
111075
|
+
if (typeof client.zrange !== "function") {
|
|
111076
|
+
throw new Error("[Scheduler] Redis client does not support zrange");
|
|
111077
|
+
}
|
|
111078
|
+
const ids = await client.zrange(`${this.prefix}schedules`, 0, -1);
|
|
108847
111079
|
const configs = [];
|
|
108848
111080
|
for (const id of ids) {
|
|
108849
|
-
const data = await
|
|
111081
|
+
const data = await client.hgetall?.(`${this.prefix}schedule:${id}`);
|
|
108850
111082
|
if (data?.id) {
|
|
108851
111083
|
configs.push({
|
|
108852
111084
|
...data,
|
|
@@ -108860,7 +111092,8 @@ class Scheduler {
|
|
|
108860
111092
|
return configs;
|
|
108861
111093
|
}
|
|
108862
111094
|
async runNow(id) {
|
|
108863
|
-
const
|
|
111095
|
+
const client = this.client;
|
|
111096
|
+
const data = await client.hgetall?.(`${this.prefix}schedule:${id}`);
|
|
108864
111097
|
if (data?.id) {
|
|
108865
111098
|
const serialized = JSON.parse(data.job);
|
|
108866
111099
|
const serializer = this.manager.getSerializer();
|
|
@@ -108869,14 +111102,21 @@ class Scheduler {
|
|
|
108869
111102
|
}
|
|
108870
111103
|
}
|
|
108871
111104
|
async tick() {
|
|
111105
|
+
const client = this.client;
|
|
111106
|
+
if (typeof client.zrangebyscore !== "function") {
|
|
111107
|
+
throw new Error("[Scheduler] Redis client does not support zrangebyscore");
|
|
111108
|
+
}
|
|
108872
111109
|
const now = Date.now();
|
|
108873
|
-
const dueIds = await
|
|
111110
|
+
const dueIds = await client.zrangebyscore(`${this.prefix}schedules`, 0, now);
|
|
108874
111111
|
let fired = 0;
|
|
108875
111112
|
for (const id of dueIds) {
|
|
108876
111113
|
const lockKey = `${this.prefix}lock:schedule:${id}:${Math.floor(now / 1000)}`;
|
|
108877
|
-
|
|
111114
|
+
if (typeof client.set !== "function") {
|
|
111115
|
+
continue;
|
|
111116
|
+
}
|
|
111117
|
+
const lock = await client.set(lockKey, "1", "EX", 10, "NX");
|
|
108878
111118
|
if (lock === "OK") {
|
|
108879
|
-
const data = await
|
|
111119
|
+
const data = await client.hgetall?.(`${this.prefix}schedule:${id}`);
|
|
108880
111120
|
if (data?.id && data.enabled === "true") {
|
|
108881
111121
|
try {
|
|
108882
111122
|
const serializedJob = JSON.parse(data.job);
|
|
@@ -108884,16 +111124,19 @@ class Scheduler {
|
|
|
108884
111124
|
const driver = this.manager.getDriver(connection);
|
|
108885
111125
|
await driver.push(data.queue, serializedJob);
|
|
108886
111126
|
const nextRun = import_cron_parser.default.parse(data.cron).next().getTime();
|
|
108887
|
-
|
|
108888
|
-
|
|
108889
|
-
|
|
108890
|
-
|
|
108891
|
-
|
|
108892
|
-
|
|
108893
|
-
|
|
111127
|
+
if (typeof client.pipeline === "function") {
|
|
111128
|
+
const pipe = client.pipeline();
|
|
111129
|
+
pipe.hset(`${this.prefix}schedule:${id}`, {
|
|
111130
|
+
lastRun: now,
|
|
111131
|
+
nextRun
|
|
111132
|
+
});
|
|
111133
|
+
pipe.zadd(`${this.prefix}schedules`, nextRun, id);
|
|
111134
|
+
await pipe.exec();
|
|
111135
|
+
}
|
|
108894
111136
|
fired++;
|
|
108895
111137
|
} catch (err) {
|
|
108896
|
-
|
|
111138
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
111139
|
+
console.error(`[Scheduler] Failed to process schedule ${id}:`, error.message);
|
|
108897
111140
|
}
|
|
108898
111141
|
}
|
|
108899
111142
|
}
|
|
@@ -108903,7 +111146,7 @@ class Scheduler {
|
|
|
108903
111146
|
}
|
|
108904
111147
|
var import_cron_parser;
|
|
108905
111148
|
var init_Scheduler = __esm(() => {
|
|
108906
|
-
import_cron_parser = __toESM(
|
|
111149
|
+
import_cron_parser = __toESM(require_dist7(), 1);
|
|
108907
111150
|
});
|
|
108908
111151
|
|
|
108909
111152
|
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/utils/url.js
|
|
@@ -115596,7 +117839,7 @@ var require_mail_message = __commonJS((exports, module) => {
|
|
|
115596
117839
|
|
|
115597
117840
|
// ../../node_modules/.bun/nodemailer@7.0.12/node_modules/nodemailer/lib/mailer/index.js
|
|
115598
117841
|
var require_mailer = __commonJS((exports, module) => {
|
|
115599
|
-
var
|
|
117842
|
+
var EventEmitter2 = __require("events");
|
|
115600
117843
|
var shared = require_shared2();
|
|
115601
117844
|
var mimeTypes = require_mime_types();
|
|
115602
117845
|
var MailComposer = require_mail_composer();
|
|
@@ -115610,7 +117853,7 @@ var require_mailer = __commonJS((exports, module) => {
|
|
|
115610
117853
|
var dns = __require("dns");
|
|
115611
117854
|
var crypto2 = __require("crypto");
|
|
115612
117855
|
|
|
115613
|
-
class Mail extends
|
|
117856
|
+
class Mail extends EventEmitter2 {
|
|
115614
117857
|
constructor(transporter, options, defaults2) {
|
|
115615
117858
|
super();
|
|
115616
117859
|
this.options = options || {};
|
|
@@ -115999,7 +118242,7 @@ var require_data_stream = __commonJS((exports, module) => {
|
|
|
115999
118242
|
// ../../node_modules/.bun/nodemailer@7.0.12/node_modules/nodemailer/lib/smtp-connection/index.js
|
|
116000
118243
|
var require_smtp_connection = __commonJS((exports, module) => {
|
|
116001
118244
|
var packageInfo = require_package5();
|
|
116002
|
-
var
|
|
118245
|
+
var EventEmitter2 = __require("events").EventEmitter;
|
|
116003
118246
|
var net = __require("net");
|
|
116004
118247
|
var tls = __require("tls");
|
|
116005
118248
|
var os2 = __require("os");
|
|
@@ -116012,7 +118255,7 @@ var require_smtp_connection = __commonJS((exports, module) => {
|
|
|
116012
118255
|
var GREETING_TIMEOUT = 30 * 1000;
|
|
116013
118256
|
var DNS_TIMEOUT = 30 * 1000;
|
|
116014
118257
|
|
|
116015
|
-
class SMTPConnection extends
|
|
118258
|
+
class SMTPConnection extends EventEmitter2 {
|
|
116016
118259
|
constructor(options) {
|
|
116017
118260
|
super(options);
|
|
116018
118261
|
this.id = crypto2.randomBytes(8).toString("base64").replace(/\W/g, "");
|
|
@@ -117394,9 +119637,9 @@ var require_pool_resource = __commonJS((exports, module) => {
|
|
|
117394
119637
|
var SMTPConnection = require_smtp_connection();
|
|
117395
119638
|
var assign = require_shared2().assign;
|
|
117396
119639
|
var XOAuth2 = require_xoauth2();
|
|
117397
|
-
var
|
|
119640
|
+
var EventEmitter2 = __require("events");
|
|
117398
119641
|
|
|
117399
|
-
class PoolResource extends
|
|
119642
|
+
class PoolResource extends EventEmitter2 {
|
|
117400
119643
|
constructor(pool) {
|
|
117401
119644
|
super();
|
|
117402
119645
|
this.pool = pool;
|
|
@@ -118149,14 +120392,14 @@ var require_well_known = __commonJS((exports, module) => {
|
|
|
118149
120392
|
|
|
118150
120393
|
// ../../node_modules/.bun/nodemailer@7.0.12/node_modules/nodemailer/lib/smtp-pool/index.js
|
|
118151
120394
|
var require_smtp_pool = __commonJS((exports, module) => {
|
|
118152
|
-
var
|
|
120395
|
+
var EventEmitter2 = __require("events");
|
|
118153
120396
|
var PoolResource = require_pool_resource();
|
|
118154
120397
|
var SMTPConnection = require_smtp_connection();
|
|
118155
120398
|
var wellKnown = require_well_known();
|
|
118156
120399
|
var shared = require_shared2();
|
|
118157
120400
|
var packageData = require_package5();
|
|
118158
120401
|
|
|
118159
|
-
class SMTPPool extends
|
|
120402
|
+
class SMTPPool extends EventEmitter2 {
|
|
118160
120403
|
constructor(options) {
|
|
118161
120404
|
super();
|
|
118162
120405
|
options = options || {};
|
|
@@ -118568,14 +120811,14 @@ var require_smtp_pool = __commonJS((exports, module) => {
|
|
|
118568
120811
|
|
|
118569
120812
|
// ../../node_modules/.bun/nodemailer@7.0.12/node_modules/nodemailer/lib/smtp-transport/index.js
|
|
118570
120813
|
var require_smtp_transport = __commonJS((exports, module) => {
|
|
118571
|
-
var
|
|
120814
|
+
var EventEmitter2 = __require("events");
|
|
118572
120815
|
var SMTPConnection = require_smtp_connection();
|
|
118573
120816
|
var wellKnown = require_well_known();
|
|
118574
120817
|
var shared = require_shared2();
|
|
118575
120818
|
var XOAuth2 = require_xoauth2();
|
|
118576
120819
|
var packageData = require_package5();
|
|
118577
120820
|
|
|
118578
|
-
class SMTPTransport extends
|
|
120821
|
+
class SMTPTransport extends EventEmitter2 {
|
|
118579
120822
|
constructor(options) {
|
|
118580
120823
|
super();
|
|
118581
120824
|
options = options || {};
|
|
@@ -119140,13 +121383,13 @@ var require_json_transport = __commonJS((exports, module) => {
|
|
|
119140
121383
|
|
|
119141
121384
|
// ../../node_modules/.bun/nodemailer@7.0.12/node_modules/nodemailer/lib/ses-transport/index.js
|
|
119142
121385
|
var require_ses_transport = __commonJS((exports, module) => {
|
|
119143
|
-
var
|
|
121386
|
+
var EventEmitter2 = __require("events");
|
|
119144
121387
|
var packageData = require_package5();
|
|
119145
121388
|
var shared = require_shared2();
|
|
119146
121389
|
var LeWindows = require_le_windows();
|
|
119147
121390
|
var MimeNode = require_mime_node();
|
|
119148
121391
|
|
|
119149
|
-
class SESTransport extends
|
|
121392
|
+
class SESTransport extends EventEmitter2 {
|
|
119150
121393
|
constructor(options) {
|
|
119151
121394
|
super();
|
|
119152
121395
|
options = options || {};
|
|
@@ -123894,6 +126137,127 @@ class QuasarAgent {
|
|
|
123894
126137
|
}
|
|
123895
126138
|
}
|
|
123896
126139
|
}
|
|
126140
|
+
// ../stream/src/Consumer.ts
|
|
126141
|
+
import { EventEmitter } from "events";
|
|
126142
|
+
|
|
126143
|
+
// ../../node_modules/.bun/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
126144
|
+
class Node3 {
|
|
126145
|
+
value;
|
|
126146
|
+
next;
|
|
126147
|
+
constructor(value) {
|
|
126148
|
+
this.value = value;
|
|
126149
|
+
}
|
|
126150
|
+
}
|
|
126151
|
+
|
|
126152
|
+
class Queue {
|
|
126153
|
+
#head;
|
|
126154
|
+
#tail;
|
|
126155
|
+
#size;
|
|
126156
|
+
constructor() {
|
|
126157
|
+
this.clear();
|
|
126158
|
+
}
|
|
126159
|
+
enqueue(value) {
|
|
126160
|
+
const node = new Node3(value);
|
|
126161
|
+
if (this.#head) {
|
|
126162
|
+
this.#tail.next = node;
|
|
126163
|
+
this.#tail = node;
|
|
126164
|
+
} else {
|
|
126165
|
+
this.#head = node;
|
|
126166
|
+
this.#tail = node;
|
|
126167
|
+
}
|
|
126168
|
+
this.#size++;
|
|
126169
|
+
}
|
|
126170
|
+
dequeue() {
|
|
126171
|
+
const current = this.#head;
|
|
126172
|
+
if (!current) {
|
|
126173
|
+
return;
|
|
126174
|
+
}
|
|
126175
|
+
this.#head = this.#head.next;
|
|
126176
|
+
this.#size--;
|
|
126177
|
+
if (!this.#head) {
|
|
126178
|
+
this.#tail = undefined;
|
|
126179
|
+
}
|
|
126180
|
+
return current.value;
|
|
126181
|
+
}
|
|
126182
|
+
peek() {
|
|
126183
|
+
if (!this.#head) {
|
|
126184
|
+
return;
|
|
126185
|
+
}
|
|
126186
|
+
return this.#head.value;
|
|
126187
|
+
}
|
|
126188
|
+
clear() {
|
|
126189
|
+
this.#head = undefined;
|
|
126190
|
+
this.#tail = undefined;
|
|
126191
|
+
this.#size = 0;
|
|
126192
|
+
}
|
|
126193
|
+
get size() {
|
|
126194
|
+
return this.#size;
|
|
126195
|
+
}
|
|
126196
|
+
*[Symbol.iterator]() {
|
|
126197
|
+
let current = this.#head;
|
|
126198
|
+
while (current) {
|
|
126199
|
+
yield current.value;
|
|
126200
|
+
current = current.next;
|
|
126201
|
+
}
|
|
126202
|
+
}
|
|
126203
|
+
*drain() {
|
|
126204
|
+
while (this.#head) {
|
|
126205
|
+
yield this.dequeue();
|
|
126206
|
+
}
|
|
126207
|
+
}
|
|
126208
|
+
}
|
|
126209
|
+
|
|
126210
|
+
// ../../node_modules/.bun/p-limit@5.0.0/node_modules/p-limit/index.js
|
|
126211
|
+
import { AsyncResource } from "node:async_hooks";
|
|
126212
|
+
function pLimit(concurrency) {
|
|
126213
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
126214
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
126215
|
+
}
|
|
126216
|
+
const queue = new Queue;
|
|
126217
|
+
let activeCount = 0;
|
|
126218
|
+
const next = () => {
|
|
126219
|
+
activeCount--;
|
|
126220
|
+
if (queue.size > 0) {
|
|
126221
|
+
queue.dequeue()();
|
|
126222
|
+
}
|
|
126223
|
+
};
|
|
126224
|
+
const run = async (function_, resolve, arguments_) => {
|
|
126225
|
+
activeCount++;
|
|
126226
|
+
const result = (async () => function_(...arguments_))();
|
|
126227
|
+
resolve(result);
|
|
126228
|
+
try {
|
|
126229
|
+
await result;
|
|
126230
|
+
} catch {}
|
|
126231
|
+
next();
|
|
126232
|
+
};
|
|
126233
|
+
const enqueue = (function_, resolve, arguments_) => {
|
|
126234
|
+
queue.enqueue(AsyncResource.bind(run.bind(undefined, function_, resolve, arguments_)));
|
|
126235
|
+
(async () => {
|
|
126236
|
+
await Promise.resolve();
|
|
126237
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
126238
|
+
queue.dequeue()();
|
|
126239
|
+
}
|
|
126240
|
+
})();
|
|
126241
|
+
};
|
|
126242
|
+
const generator = (function_, ...arguments_) => new Promise((resolve) => {
|
|
126243
|
+
enqueue(function_, resolve, arguments_);
|
|
126244
|
+
});
|
|
126245
|
+
Object.defineProperties(generator, {
|
|
126246
|
+
activeCount: {
|
|
126247
|
+
get: () => activeCount
|
|
126248
|
+
},
|
|
126249
|
+
pendingCount: {
|
|
126250
|
+
get: () => queue.size
|
|
126251
|
+
},
|
|
126252
|
+
clearQueue: {
|
|
126253
|
+
value() {
|
|
126254
|
+
queue.clear();
|
|
126255
|
+
}
|
|
126256
|
+
}
|
|
126257
|
+
});
|
|
126258
|
+
return generator;
|
|
126259
|
+
}
|
|
126260
|
+
|
|
123897
126261
|
// ../stream/src/Worker.ts
|
|
123898
126262
|
class Worker {
|
|
123899
126263
|
options;
|
|
@@ -123940,20 +126304,39 @@ class Worker {
|
|
|
123940
126304
|
}
|
|
123941
126305
|
|
|
123942
126306
|
// ../stream/src/Consumer.ts
|
|
123943
|
-
class Consumer {
|
|
126307
|
+
class Consumer extends EventEmitter {
|
|
123944
126308
|
queueManager;
|
|
123945
126309
|
options;
|
|
123946
126310
|
running = false;
|
|
123947
126311
|
stopRequested = false;
|
|
123948
|
-
workerId = `worker-${
|
|
126312
|
+
workerId = `worker-${crypto.randomUUID()}`;
|
|
123949
126313
|
heartbeatTimer = null;
|
|
126314
|
+
groupLimiters = new Map;
|
|
126315
|
+
stats = {
|
|
126316
|
+
processed: 0,
|
|
126317
|
+
failed: 0,
|
|
126318
|
+
retried: 0,
|
|
126319
|
+
active: 0
|
|
126320
|
+
};
|
|
123950
126321
|
constructor(queueManager, options) {
|
|
126322
|
+
super();
|
|
123951
126323
|
this.queueManager = queueManager;
|
|
123952
126324
|
this.options = options;
|
|
123953
126325
|
}
|
|
123954
126326
|
get connectionName() {
|
|
123955
126327
|
return this.options.connection ?? this.queueManager.getDefaultConnection();
|
|
123956
126328
|
}
|
|
126329
|
+
log(message, data) {
|
|
126330
|
+
if (this.options.debug) {
|
|
126331
|
+
const timestamp = new Date().toISOString();
|
|
126332
|
+
const prefix = `[Consumer:${this.workerId}] [${timestamp}]`;
|
|
126333
|
+
if (data) {
|
|
126334
|
+
console.log(prefix, message, data);
|
|
126335
|
+
} else {
|
|
126336
|
+
console.log(prefix, message);
|
|
126337
|
+
}
|
|
126338
|
+
}
|
|
126339
|
+
}
|
|
123957
126340
|
async start() {
|
|
123958
126341
|
if (this.running) {
|
|
123959
126342
|
throw new Error("Consumer is already running");
|
|
@@ -123961,19 +126344,33 @@ class Consumer {
|
|
|
123961
126344
|
this.running = true;
|
|
123962
126345
|
this.stopRequested = false;
|
|
123963
126346
|
const worker = new Worker(this.options.workerOptions);
|
|
123964
|
-
|
|
126347
|
+
let currentPollInterval = this.options.pollInterval ?? 1000;
|
|
126348
|
+
const minPollInterval = this.options.minPollInterval ?? 100;
|
|
126349
|
+
const maxPollInterval = this.options.maxPollInterval ?? 5000;
|
|
126350
|
+
const backoffMultiplier = this.options.backoffMultiplier ?? 1.5;
|
|
123965
126351
|
const keepAlive = this.options.keepAlive ?? true;
|
|
123966
|
-
|
|
126352
|
+
const concurrency = this.options.concurrency ?? 1;
|
|
126353
|
+
const batchSize = this.options.batchSize ?? 1;
|
|
126354
|
+
const useBlocking = this.options.useBlocking ?? true;
|
|
126355
|
+
const blockingTimeout = this.options.blockingTimeout ?? 5;
|
|
126356
|
+
this.log("Started", {
|
|
123967
126357
|
queues: this.options.queues,
|
|
123968
126358
|
connection: this.options.connection,
|
|
123969
|
-
workerId: this.workerId
|
|
126359
|
+
workerId: this.workerId,
|
|
126360
|
+
concurrency,
|
|
126361
|
+
batchSize
|
|
123970
126362
|
});
|
|
123971
126363
|
if (this.options.monitor) {
|
|
123972
126364
|
this.startHeartbeat();
|
|
123973
|
-
await this.publishLog("info", `Consumer started on [${this.options.queues.join(", ")}]`);
|
|
126365
|
+
await this.publishLog("info", `Consumer started on [${this.options.queues.join(", ")}] with concurrency ${concurrency}`);
|
|
123974
126366
|
}
|
|
123975
126367
|
while (this.running && !this.stopRequested) {
|
|
123976
|
-
|
|
126368
|
+
const capacity = concurrency - this.stats.active;
|
|
126369
|
+
if (capacity <= 0) {
|
|
126370
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
126371
|
+
continue;
|
|
126372
|
+
}
|
|
126373
|
+
const eligibleQueues = [];
|
|
123977
126374
|
for (const queue of this.options.queues) {
|
|
123978
126375
|
if (this.options.rateLimits?.[queue]) {
|
|
123979
126376
|
const limit = this.options.rateLimits[queue];
|
|
@@ -123989,56 +126386,66 @@ class Consumer {
|
|
|
123989
126386
|
console.error(`[Consumer] Error checking rate limit for "${queue}":`, err);
|
|
123990
126387
|
}
|
|
123991
126388
|
}
|
|
123992
|
-
|
|
123993
|
-
|
|
123994
|
-
|
|
123995
|
-
|
|
123996
|
-
|
|
123997
|
-
|
|
126389
|
+
eligibleQueues.push(queue);
|
|
126390
|
+
}
|
|
126391
|
+
if (eligibleQueues.length === 0) {
|
|
126392
|
+
await new Promise((resolve) => setTimeout(resolve, currentPollInterval));
|
|
126393
|
+
continue;
|
|
126394
|
+
}
|
|
126395
|
+
let jobs = [];
|
|
126396
|
+
let didBlock = false;
|
|
126397
|
+
try {
|
|
126398
|
+
const currentBatchSize = Math.min(batchSize, capacity);
|
|
126399
|
+
const driver = this.queueManager.getDriver(this.connectionName);
|
|
126400
|
+
if (currentBatchSize > 1) {
|
|
126401
|
+
for (const queue of eligibleQueues) {
|
|
126402
|
+
const fetched = await this.queueManager.popMany(queue, currentBatchSize, this.connectionName);
|
|
126403
|
+
if (fetched.length > 0) {
|
|
126404
|
+
jobs = fetched;
|
|
126405
|
+
break;
|
|
123998
126406
|
}
|
|
123999
|
-
|
|
124000
|
-
|
|
124001
|
-
|
|
124002
|
-
|
|
124003
|
-
|
|
124004
|
-
|
|
124005
|
-
|
|
124006
|
-
|
|
124007
|
-
|
|
124008
|
-
|
|
124009
|
-
const
|
|
124010
|
-
|
|
124011
|
-
|
|
124012
|
-
|
|
124013
|
-
const delayMs = job.getRetryDelay(job.attempts);
|
|
124014
|
-
const delaySec = Math.ceil(delayMs / 1000);
|
|
124015
|
-
job.delay(delaySec);
|
|
124016
|
-
await this.queueManager.push(job);
|
|
124017
|
-
if (this.options.monitor) {
|
|
124018
|
-
await this.publishLog("warning", `Job retrying in ${delaySec}s (Attempt ${job.attempts}/${maxAttempts})`, job.id);
|
|
124019
|
-
}
|
|
124020
|
-
} else {
|
|
124021
|
-
await this.queueManager.fail(job, err).catch((dlqErr) => {
|
|
124022
|
-
console.error(`[Consumer] Error moving job to DLQ:`, dlqErr);
|
|
124023
|
-
});
|
|
126407
|
+
}
|
|
126408
|
+
} else {
|
|
126409
|
+
if (useBlocking && driver.popBlocking) {
|
|
126410
|
+
didBlock = true;
|
|
126411
|
+
const job = await this.queueManager.popBlocking(eligibleQueues, blockingTimeout, this.connectionName);
|
|
126412
|
+
if (job) {
|
|
126413
|
+
jobs.push(job);
|
|
126414
|
+
}
|
|
126415
|
+
} else {
|
|
126416
|
+
for (const queue of eligibleQueues) {
|
|
126417
|
+
const job = await this.queueManager.pop(queue, this.connectionName);
|
|
126418
|
+
if (job) {
|
|
126419
|
+
jobs.push(job);
|
|
126420
|
+
break;
|
|
124024
126421
|
}
|
|
124025
|
-
} finally {
|
|
124026
|
-
await this.queueManager.complete(job).catch((err) => {
|
|
124027
|
-
console.error(`[Consumer] Error completing job in queue "${queue}":`, err);
|
|
124028
|
-
});
|
|
124029
126422
|
}
|
|
124030
126423
|
}
|
|
124031
|
-
} catch (error) {
|
|
124032
|
-
console.error(`[Consumer] Error polling queue "${queue}":`, error);
|
|
124033
126424
|
}
|
|
126425
|
+
if (jobs.length > 0) {
|
|
126426
|
+
this.stats.active += jobs.length;
|
|
126427
|
+
currentPollInterval = minPollInterval;
|
|
126428
|
+
for (const job of jobs) {
|
|
126429
|
+
this.runJob(job, worker).finally(() => {
|
|
126430
|
+
this.stats.active--;
|
|
126431
|
+
});
|
|
126432
|
+
}
|
|
126433
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
126434
|
+
continue;
|
|
126435
|
+
}
|
|
126436
|
+
} catch (error) {
|
|
126437
|
+
console.error("[Consumer] Loop error:", error);
|
|
124034
126438
|
}
|
|
124035
|
-
if (
|
|
126439
|
+
if (this.stats.active === 0 && !keepAlive) {
|
|
124036
126440
|
break;
|
|
124037
126441
|
}
|
|
124038
|
-
if (!this.stopRequested
|
|
124039
|
-
|
|
124040
|
-
|
|
124041
|
-
|
|
126442
|
+
if (!this.stopRequested) {
|
|
126443
|
+
if (!didBlock) {
|
|
126444
|
+
await new Promise((resolve) => setTimeout(resolve, currentPollInterval));
|
|
126445
|
+
currentPollInterval = Math.min(currentPollInterval * backoffMultiplier, maxPollInterval);
|
|
126446
|
+
}
|
|
126447
|
+
} else {
|
|
126448
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
124042
126449
|
}
|
|
124043
126450
|
}
|
|
124044
126451
|
this.running = false;
|
|
@@ -124046,7 +126453,79 @@ class Consumer {
|
|
|
124046
126453
|
if (this.options.monitor) {
|
|
124047
126454
|
await this.publishLog("info", "Consumer stopped");
|
|
124048
126455
|
}
|
|
124049
|
-
|
|
126456
|
+
this.log("Stopped");
|
|
126457
|
+
}
|
|
126458
|
+
async runJob(job, worker) {
|
|
126459
|
+
if (!job.groupId || this.options.groupJobsSequential === false) {
|
|
126460
|
+
return this.handleJob(job, worker);
|
|
126461
|
+
}
|
|
126462
|
+
let limiter = this.groupLimiters.get(job.groupId);
|
|
126463
|
+
if (!limiter) {
|
|
126464
|
+
limiter = pLimit(1);
|
|
126465
|
+
this.groupLimiters.set(job.groupId, limiter);
|
|
126466
|
+
}
|
|
126467
|
+
if (limiter.pendingCount > 0) {
|
|
126468
|
+
this.log(`Job ${job.id} queued behind group ${job.groupId}`);
|
|
126469
|
+
}
|
|
126470
|
+
await limiter(async () => {
|
|
126471
|
+
await this.handleJob(job, worker);
|
|
126472
|
+
});
|
|
126473
|
+
if (limiter.activeCount === 0 && limiter.pendingCount === 0) {
|
|
126474
|
+
this.groupLimiters.delete(job.groupId);
|
|
126475
|
+
}
|
|
126476
|
+
}
|
|
126477
|
+
async handleJob(job, worker) {
|
|
126478
|
+
const currentQueue = job.queueName || "default";
|
|
126479
|
+
const startTime = Date.now();
|
|
126480
|
+
this.log(`Processing job ${job.id} from ${currentQueue}`);
|
|
126481
|
+
this.emit("job:started", { job, queue: currentQueue });
|
|
126482
|
+
if (this.options.monitor) {
|
|
126483
|
+
await this.publishLog("info", `Processing job: ${job.id}`, job.id);
|
|
126484
|
+
}
|
|
126485
|
+
try {
|
|
126486
|
+
await worker.process(job);
|
|
126487
|
+
const duration = Date.now() - startTime;
|
|
126488
|
+
this.stats.processed++;
|
|
126489
|
+
this.emit("job:processed", { job, duration, queue: currentQueue });
|
|
126490
|
+
this.log(`Completed job ${job.id} in ${duration}ms`);
|
|
126491
|
+
if (this.options.monitor) {
|
|
126492
|
+
await this.publishLog("success", `Completed job: ${job.id}`, job.id);
|
|
126493
|
+
}
|
|
126494
|
+
} catch (err) {
|
|
126495
|
+
const error = err;
|
|
126496
|
+
const duration = Date.now() - startTime;
|
|
126497
|
+
this.emit("job:failed", { job, error, duration, queue: currentQueue });
|
|
126498
|
+
this.log(`Failed job ${job.id} in ${duration}ms`, { error: error.message });
|
|
126499
|
+
this.stats.failed++;
|
|
126500
|
+
if (this.options.monitor) {
|
|
126501
|
+
await this.publishLog("error", `Job failed: ${job.id} - ${error.message}`, job.id);
|
|
126502
|
+
}
|
|
126503
|
+
const attempts = job.attempts ?? 1;
|
|
126504
|
+
const maxAttempts = job.maxAttempts ?? this.options.workerOptions?.maxAttempts ?? 3;
|
|
126505
|
+
if (attempts < maxAttempts) {
|
|
126506
|
+
job.attempts = attempts + 1;
|
|
126507
|
+
const delayMs = job.getRetryDelay(job.attempts);
|
|
126508
|
+
const delaySec = Math.ceil(delayMs / 1000);
|
|
126509
|
+
job.delay(delaySec);
|
|
126510
|
+
await this.queueManager.push(job);
|
|
126511
|
+
this.log(`Retrying job ${job.id} in ${delaySec}s (Attempt ${job.attempts}/${maxAttempts})`);
|
|
126512
|
+
this.stats.retried++;
|
|
126513
|
+
this.emit("job:retried", { job, attempt: job.attempts, delay: delaySec });
|
|
126514
|
+
if (this.options.monitor) {
|
|
126515
|
+
await this.publishLog("warning", `Job retrying in ${delaySec}s (Attempt ${job.attempts}/${maxAttempts})`, job.id);
|
|
126516
|
+
}
|
|
126517
|
+
} else {
|
|
126518
|
+
this.emit("job:failed_permanently", { job, error });
|
|
126519
|
+
this.log(`Job ${job.id} failed permanently`);
|
|
126520
|
+
await this.queueManager.fail(job, error).catch((dlqErr) => {
|
|
126521
|
+
console.error("[Consumer] Error moving job to DLQ:", dlqErr);
|
|
126522
|
+
});
|
|
126523
|
+
}
|
|
126524
|
+
} finally {
|
|
126525
|
+
await this.queueManager.complete(job).catch((err) => {
|
|
126526
|
+
console.error(`[Consumer] Error completing job in queue "${currentQueue}":`, err);
|
|
126527
|
+
});
|
|
126528
|
+
}
|
|
124050
126529
|
}
|
|
124051
126530
|
startHeartbeat() {
|
|
124052
126531
|
const interval = typeof this.options.monitor === "object" ? this.options.monitor.interval ?? 5000 : 5000;
|
|
@@ -124065,7 +126544,8 @@ class Consumer {
|
|
|
124065
126544
|
rss: Math.floor(mem.rss / 1024 / 1024),
|
|
124066
126545
|
heapUsed: Math.floor(mem.heapUsed / 1024 / 1024),
|
|
124067
126546
|
total: Math.floor(os2.totalmem() / 1024 / 1024)
|
|
124068
|
-
}
|
|
126547
|
+
},
|
|
126548
|
+
stats: this.stats
|
|
124069
126549
|
};
|
|
124070
126550
|
await driver.reportHeartbeat({
|
|
124071
126551
|
id: this.workerId,
|
|
@@ -124104,7 +126584,7 @@ class Consumer {
|
|
|
124104
126584
|
} catch (_e) {}
|
|
124105
126585
|
}
|
|
124106
126586
|
async stop() {
|
|
124107
|
-
|
|
126587
|
+
this.log("Stopping...");
|
|
124108
126588
|
this.stopRequested = true;
|
|
124109
126589
|
while (this.running) {
|
|
124110
126590
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -124113,15 +126593,31 @@ class Consumer {
|
|
|
124113
126593
|
isRunning() {
|
|
124114
126594
|
return this.running;
|
|
124115
126595
|
}
|
|
126596
|
+
getStats() {
|
|
126597
|
+
return { ...this.stats };
|
|
126598
|
+
}
|
|
126599
|
+
resetStats() {
|
|
126600
|
+
this.stats.processed = 0;
|
|
126601
|
+
this.stats.failed = 0;
|
|
126602
|
+
this.stats.retried = 0;
|
|
126603
|
+
}
|
|
124116
126604
|
}
|
|
124117
126605
|
// ../stream/src/drivers/MemoryDriver.ts
|
|
124118
126606
|
class MemoryDriver {
|
|
124119
126607
|
queues = new Map;
|
|
126608
|
+
maxSize;
|
|
126609
|
+
constructor(config = {}) {
|
|
126610
|
+
this.maxSize = config.maxSize ?? Infinity;
|
|
126611
|
+
}
|
|
124120
126612
|
async push(queue, job) {
|
|
124121
126613
|
if (!this.queues.has(queue)) {
|
|
124122
126614
|
this.queues.set(queue, []);
|
|
124123
126615
|
}
|
|
124124
|
-
this.queues.get(queue)
|
|
126616
|
+
const q = this.queues.get(queue);
|
|
126617
|
+
if (q.length >= this.maxSize) {
|
|
126618
|
+
throw new Error(`[MemoryDriver] Queue '${queue}' is full (max size: ${this.maxSize})`);
|
|
126619
|
+
}
|
|
126620
|
+
q.push(job);
|
|
124125
126621
|
}
|
|
124126
126622
|
async pop(queue) {
|
|
124127
126623
|
const queueJobs = this.queues.get(queue);
|
|
@@ -124141,6 +126637,33 @@ class MemoryDriver {
|
|
|
124141
126637
|
async clear(queue) {
|
|
124142
126638
|
this.queues.delete(queue);
|
|
124143
126639
|
}
|
|
126640
|
+
async fail(queue, job) {
|
|
126641
|
+
const failedQueue = `failed:${queue}`;
|
|
126642
|
+
if (!this.queues.has(failedQueue)) {
|
|
126643
|
+
this.queues.set(failedQueue, []);
|
|
126644
|
+
}
|
|
126645
|
+
this.queues.get(failedQueue)?.push(job);
|
|
126646
|
+
}
|
|
126647
|
+
async stats(queue) {
|
|
126648
|
+
const jobs = this.queues.get(queue) || [];
|
|
126649
|
+
const now = Date.now();
|
|
126650
|
+
let pending = 0;
|
|
126651
|
+
let delayed = 0;
|
|
126652
|
+
for (const job of jobs) {
|
|
126653
|
+
const isDelayed = job.delaySeconds && now < job.createdAt + job.delaySeconds * 1000;
|
|
126654
|
+
if (isDelayed) {
|
|
126655
|
+
delayed++;
|
|
126656
|
+
} else {
|
|
126657
|
+
pending++;
|
|
126658
|
+
}
|
|
126659
|
+
}
|
|
126660
|
+
return {
|
|
126661
|
+
queue,
|
|
126662
|
+
size: pending,
|
|
126663
|
+
delayed,
|
|
126664
|
+
failed: this.queues.get(`failed:${queue}`)?.length || 0
|
|
126665
|
+
};
|
|
126666
|
+
}
|
|
124144
126667
|
async pushMany(queue, jobs) {
|
|
124145
126668
|
if (!this.queues.has(queue)) {
|
|
124146
126669
|
this.queues.set(queue, []);
|
|
@@ -124160,6 +126683,26 @@ class MemoryDriver {
|
|
|
124160
126683
|
return results;
|
|
124161
126684
|
}
|
|
124162
126685
|
}
|
|
126686
|
+
// ../stream/src/serializers/CachedSerializer.ts
|
|
126687
|
+
class CachedSerializer {
|
|
126688
|
+
delegate;
|
|
126689
|
+
cache = new WeakMap;
|
|
126690
|
+
constructor(delegate) {
|
|
126691
|
+
this.delegate = delegate;
|
|
126692
|
+
}
|
|
126693
|
+
serialize(job) {
|
|
126694
|
+
if (this.cache.has(job)) {
|
|
126695
|
+
return this.cache.get(job);
|
|
126696
|
+
}
|
|
126697
|
+
const serialized = this.delegate.serialize(job);
|
|
126698
|
+
this.cache.set(job, serialized);
|
|
126699
|
+
return serialized;
|
|
126700
|
+
}
|
|
126701
|
+
deserialize(serialized) {
|
|
126702
|
+
return this.delegate.deserialize(serialized);
|
|
126703
|
+
}
|
|
126704
|
+
}
|
|
126705
|
+
|
|
124163
126706
|
// ../stream/src/serializers/ClassNameSerializer.ts
|
|
124164
126707
|
class ClassNameSerializer {
|
|
124165
126708
|
jobClasses = new Map;
|
|
@@ -124172,7 +126715,7 @@ class ClassNameSerializer {
|
|
|
124172
126715
|
}
|
|
124173
126716
|
}
|
|
124174
126717
|
serialize(job) {
|
|
124175
|
-
const id = job.id || `${Date.now()}-${
|
|
126718
|
+
const id = job.id || `${Date.now()}-${crypto.randomUUID()}`;
|
|
124176
126719
|
const className = job.constructor.name;
|
|
124177
126720
|
const properties = {};
|
|
124178
126721
|
for (const key in job) {
|
|
@@ -124184,10 +126727,7 @@ class ClassNameSerializer {
|
|
|
124184
126727
|
id,
|
|
124185
126728
|
type: "class",
|
|
124186
126729
|
className,
|
|
124187
|
-
data: JSON.stringify(
|
|
124188
|
-
class: className,
|
|
124189
|
-
properties
|
|
124190
|
-
}),
|
|
126730
|
+
data: JSON.stringify(properties),
|
|
124191
126731
|
createdAt: Date.now(),
|
|
124192
126732
|
...job.delaySeconds !== undefined ? { delaySeconds: job.delaySeconds } : {},
|
|
124193
126733
|
attempts: job.attempts ?? 0,
|
|
@@ -124209,10 +126749,10 @@ class ClassNameSerializer {
|
|
|
124209
126749
|
if (!JobClass) {
|
|
124210
126750
|
throw new Error(`Job class "${serialized.className}" is not registered. Please register it using serializer.register().`);
|
|
124211
126751
|
}
|
|
124212
|
-
const
|
|
126752
|
+
const properties = JSON.parse(serialized.data);
|
|
124213
126753
|
const job = new JobClass;
|
|
124214
|
-
if (
|
|
124215
|
-
Object.assign(job,
|
|
126754
|
+
if (properties) {
|
|
126755
|
+
Object.assign(job, properties);
|
|
124216
126756
|
}
|
|
124217
126757
|
job.id = serialized.id;
|
|
124218
126758
|
if (serialized.delaySeconds !== undefined) {
|
|
@@ -124243,14 +126783,17 @@ class ClassNameSerializer {
|
|
|
124243
126783
|
// ../stream/src/serializers/JsonSerializer.ts
|
|
124244
126784
|
class JsonSerializer {
|
|
124245
126785
|
serialize(job) {
|
|
124246
|
-
const id = `${Date.now()}-${
|
|
126786
|
+
const id = job.id || `${Date.now()}-${crypto.randomUUID()}`;
|
|
126787
|
+
const properties = {};
|
|
126788
|
+
for (const key in job) {
|
|
126789
|
+
if (Object.hasOwn(job, key) && typeof job[key] !== "function") {
|
|
126790
|
+
properties[key] = job[key];
|
|
126791
|
+
}
|
|
126792
|
+
}
|
|
124247
126793
|
return {
|
|
124248
126794
|
id,
|
|
124249
126795
|
type: "json",
|
|
124250
|
-
data: JSON.stringify(
|
|
124251
|
-
job: job.constructor.name,
|
|
124252
|
-
properties: { ...job }
|
|
124253
|
-
}),
|
|
126796
|
+
data: JSON.stringify(properties),
|
|
124254
126797
|
createdAt: Date.now(),
|
|
124255
126798
|
...job.delaySeconds !== undefined ? { delaySeconds: job.delaySeconds } : {},
|
|
124256
126799
|
attempts: job.attempts ?? 0,
|
|
@@ -124263,15 +126806,22 @@ class JsonSerializer {
|
|
|
124263
126806
|
if (serialized.type !== "json") {
|
|
124264
126807
|
throw new Error('Invalid serialization type: expected "json"');
|
|
124265
126808
|
}
|
|
124266
|
-
const
|
|
126809
|
+
const properties = JSON.parse(serialized.data);
|
|
124267
126810
|
const job = Object.create({});
|
|
124268
|
-
Object.assign(job,
|
|
126811
|
+
Object.assign(job, properties);
|
|
126812
|
+
job.id = serialized.id;
|
|
124269
126813
|
if (serialized.groupId) {
|
|
124270
126814
|
job.groupId = serialized.groupId;
|
|
124271
126815
|
}
|
|
124272
126816
|
if (serialized.priority) {
|
|
124273
126817
|
job.priority = serialized.priority;
|
|
124274
126818
|
}
|
|
126819
|
+
if (serialized.delaySeconds !== undefined) {
|
|
126820
|
+
job.delaySeconds = serialized.delaySeconds;
|
|
126821
|
+
}
|
|
126822
|
+
if (serialized.attempts !== undefined) {
|
|
126823
|
+
job.attempts = serialized.attempts;
|
|
126824
|
+
}
|
|
124275
126825
|
return job;
|
|
124276
126826
|
}
|
|
124277
126827
|
}
|
|
@@ -124284,15 +126834,30 @@ class QueueManager {
|
|
|
124284
126834
|
defaultSerializer;
|
|
124285
126835
|
persistence;
|
|
124286
126836
|
scheduler;
|
|
126837
|
+
debug;
|
|
124287
126838
|
constructor(config = {}) {
|
|
124288
126839
|
this.persistence = config.persistence;
|
|
124289
126840
|
this.defaultConnection = config.default ?? "default";
|
|
126841
|
+
this.debug = config.debug ?? false;
|
|
126842
|
+
if (this.persistence && (this.persistence.bufferSize || this.persistence.flushInterval)) {
|
|
126843
|
+
const { BufferedPersistence: BufferedPersistence2 } = __toCommonJS(exports_BufferedPersistence);
|
|
126844
|
+
this.persistence.adapter = new BufferedPersistence2(this.persistence.adapter, {
|
|
126845
|
+
maxBufferSize: this.persistence.bufferSize,
|
|
126846
|
+
flushInterval: this.persistence.flushInterval
|
|
126847
|
+
});
|
|
126848
|
+
}
|
|
124290
126849
|
const serializerType = config.defaultSerializer ?? "class";
|
|
124291
126850
|
if (serializerType === "class") {
|
|
124292
126851
|
this.defaultSerializer = new ClassNameSerializer;
|
|
126852
|
+
} else if (serializerType === "msgpack") {
|
|
126853
|
+
const { MessagePackSerializer: MessagePackSerializer2 } = __toCommonJS(exports_MessagePackSerializer);
|
|
126854
|
+
this.defaultSerializer = new MessagePackSerializer2;
|
|
124293
126855
|
} else {
|
|
124294
126856
|
this.defaultSerializer = new JsonSerializer;
|
|
124295
126857
|
}
|
|
126858
|
+
if (config.useSerializationCache) {
|
|
126859
|
+
this.defaultSerializer = new CachedSerializer(this.defaultSerializer);
|
|
126860
|
+
}
|
|
124296
126861
|
if (!this.drivers.has("default")) {
|
|
124297
126862
|
this.drivers.set("default", new MemoryDriver);
|
|
124298
126863
|
}
|
|
@@ -124302,6 +126867,17 @@ class QueueManager {
|
|
|
124302
126867
|
}
|
|
124303
126868
|
}
|
|
124304
126869
|
}
|
|
126870
|
+
log(message, data) {
|
|
126871
|
+
if (this.debug) {
|
|
126872
|
+
const timestamp = new Date().toISOString();
|
|
126873
|
+
const prefix = `[QueueManager] [${timestamp}]`;
|
|
126874
|
+
if (data) {
|
|
126875
|
+
console.log(prefix, message, data);
|
|
126876
|
+
} else {
|
|
126877
|
+
console.log(prefix, message);
|
|
126878
|
+
}
|
|
126879
|
+
}
|
|
126880
|
+
}
|
|
124305
126881
|
registerConnection(name, config) {
|
|
124306
126882
|
const driverType = config.driver;
|
|
124307
126883
|
switch (driverType) {
|
|
@@ -124310,48 +126886,44 @@ class QueueManager {
|
|
|
124310
126886
|
break;
|
|
124311
126887
|
case "database": {
|
|
124312
126888
|
const { DatabaseDriver: DatabaseDriver2 } = __toCommonJS(exports_DatabaseDriver);
|
|
124313
|
-
|
|
124314
|
-
if (!dbService) {
|
|
126889
|
+
if (!config.dbService) {
|
|
124315
126890
|
throw new Error("[QueueManager] DatabaseDriver requires dbService. Please provide a database service that implements DatabaseService interface.");
|
|
124316
126891
|
}
|
|
124317
126892
|
this.drivers.set(name, new DatabaseDriver2({
|
|
124318
|
-
dbService,
|
|
126893
|
+
dbService: config.dbService,
|
|
124319
126894
|
table: config.table
|
|
124320
126895
|
}));
|
|
124321
126896
|
break;
|
|
124322
126897
|
}
|
|
124323
126898
|
case "redis": {
|
|
124324
126899
|
const { RedisDriver: RedisDriver3 } = __toCommonJS(exports_RedisDriver);
|
|
124325
|
-
|
|
124326
|
-
if (!client) {
|
|
126900
|
+
if (!config.client) {
|
|
124327
126901
|
throw new Error("[QueueManager] RedisDriver requires client. Please provide Redis client in connection config.");
|
|
124328
126902
|
}
|
|
124329
126903
|
this.drivers.set(name, new RedisDriver3({
|
|
124330
|
-
client,
|
|
126904
|
+
client: config.client,
|
|
124331
126905
|
prefix: config.prefix
|
|
124332
126906
|
}));
|
|
124333
126907
|
break;
|
|
124334
126908
|
}
|
|
124335
126909
|
case "kafka": {
|
|
124336
126910
|
const { KafkaDriver: KafkaDriver2 } = __toCommonJS(exports_KafkaDriver);
|
|
124337
|
-
|
|
124338
|
-
if (!client) {
|
|
126911
|
+
if (!config.client) {
|
|
124339
126912
|
throw new Error("[QueueManager] KafkaDriver requires client. Please provide Kafka client in connection config.");
|
|
124340
126913
|
}
|
|
124341
126914
|
this.drivers.set(name, new KafkaDriver2({
|
|
124342
|
-
client,
|
|
126915
|
+
client: config.client,
|
|
124343
126916
|
consumerGroupId: config.consumerGroupId
|
|
124344
126917
|
}));
|
|
124345
126918
|
break;
|
|
124346
126919
|
}
|
|
124347
126920
|
case "sqs": {
|
|
124348
126921
|
const { SQSDriver: SQSDriver2 } = __toCommonJS(exports_SQSDriver);
|
|
124349
|
-
|
|
124350
|
-
if (!client) {
|
|
126922
|
+
if (!config.client) {
|
|
124351
126923
|
throw new Error("[QueueManager] SQSDriver requires client. Please provide SQS client in connection config.");
|
|
124352
126924
|
}
|
|
124353
126925
|
this.drivers.set(name, new SQSDriver2({
|
|
124354
|
-
client,
|
|
126926
|
+
client: config.client,
|
|
124355
126927
|
queueUrlPrefix: config.queueUrlPrefix,
|
|
124356
126928
|
visibilityTimeout: config.visibilityTimeout,
|
|
124357
126929
|
waitTimeSeconds: config.waitTimeSeconds
|
|
@@ -124360,12 +126932,11 @@ class QueueManager {
|
|
|
124360
126932
|
}
|
|
124361
126933
|
case "rabbitmq": {
|
|
124362
126934
|
const { RabbitMQDriver: RabbitMQDriver2 } = __toCommonJS(exports_RabbitMQDriver);
|
|
124363
|
-
|
|
124364
|
-
if (!client) {
|
|
126935
|
+
if (!config.client) {
|
|
124365
126936
|
throw new Error("[QueueManager] RabbitMQDriver requires client. Please provide RabbitMQ connection/channel in connection config.");
|
|
124366
126937
|
}
|
|
124367
126938
|
this.drivers.set(name, new RabbitMQDriver2({
|
|
124368
|
-
client,
|
|
126939
|
+
client: config.client,
|
|
124369
126940
|
exchange: config.exchange,
|
|
124370
126941
|
exchangeType: config.exchangeType
|
|
124371
126942
|
}));
|
|
@@ -124411,6 +126982,11 @@ class QueueManager {
|
|
|
124411
126982
|
pushOptions.priority = job.priority;
|
|
124412
126983
|
}
|
|
124413
126984
|
await driver.push(queue, serialized, pushOptions);
|
|
126985
|
+
this.log(`Pushed job to ${queue} (${connection})`, {
|
|
126986
|
+
id: serialized.id,
|
|
126987
|
+
job: serialized.className ?? "json",
|
|
126988
|
+
options: pushOptions
|
|
126989
|
+
});
|
|
124414
126990
|
if (this.persistence?.archiveEnqueued) {
|
|
124415
126991
|
this.persistence.adapter.archive(queue, serialized, "waiting").catch((err) => {
|
|
124416
126992
|
console.error("[QueueManager] Persistence archive failed (waiting):", err);
|
|
@@ -124418,10 +126994,12 @@ class QueueManager {
|
|
|
124418
126994
|
}
|
|
124419
126995
|
return job;
|
|
124420
126996
|
}
|
|
124421
|
-
async pushMany(jobs) {
|
|
126997
|
+
async pushMany(jobs, options = {}) {
|
|
124422
126998
|
if (jobs.length === 0) {
|
|
124423
126999
|
return;
|
|
124424
127000
|
}
|
|
127001
|
+
const batchSize = options.batchSize ?? 100;
|
|
127002
|
+
const concurrency = options.concurrency ?? 1;
|
|
124425
127003
|
const groups = new Map;
|
|
124426
127004
|
const serializer = this.getSerializer();
|
|
124427
127005
|
for (const job of jobs) {
|
|
@@ -124434,17 +127012,42 @@ class QueueManager {
|
|
|
124434
127012
|
}
|
|
124435
127013
|
groups.get(key)?.push(serialized);
|
|
124436
127014
|
}
|
|
127015
|
+
const processBatch = async (driver, queue, batch) => {
|
|
127016
|
+
if (driver.pushMany) {
|
|
127017
|
+
await driver.pushMany(queue, batch);
|
|
127018
|
+
} else {
|
|
127019
|
+
for (const job of batch) {
|
|
127020
|
+
await driver.push(queue, job);
|
|
127021
|
+
}
|
|
127022
|
+
}
|
|
127023
|
+
};
|
|
124437
127024
|
for (const [key, serializedJobs] of groups.entries()) {
|
|
124438
127025
|
const [connection, queue] = key.split(":");
|
|
124439
127026
|
if (!connection || !queue) {
|
|
124440
127027
|
continue;
|
|
124441
127028
|
}
|
|
124442
127029
|
const driver = this.getDriver(connection);
|
|
124443
|
-
|
|
124444
|
-
|
|
127030
|
+
this.log(`Pushing ${serializedJobs.length} jobs to ${queue} (${connection})`);
|
|
127031
|
+
const chunks = [];
|
|
127032
|
+
for (let i3 = 0;i3 < serializedJobs.length; i3 += batchSize) {
|
|
127033
|
+
chunks.push(serializedJobs.slice(i3, i3 + batchSize));
|
|
127034
|
+
}
|
|
127035
|
+
if (concurrency > 1) {
|
|
127036
|
+
const activePromises = [];
|
|
127037
|
+
for (const chunk of chunks) {
|
|
127038
|
+
const promise = processBatch(driver, queue, chunk);
|
|
127039
|
+
activePromises.push(promise);
|
|
127040
|
+
if (activePromises.length >= concurrency) {
|
|
127041
|
+
await Promise.race(activePromises);
|
|
127042
|
+
}
|
|
127043
|
+
}
|
|
127044
|
+
for (let i3 = 0;i3 < chunks.length; i3 += concurrency) {
|
|
127045
|
+
const batchPromises = chunks.slice(i3, i3 + concurrency).map((chunk) => processBatch(driver, queue, chunk));
|
|
127046
|
+
await Promise.all(batchPromises);
|
|
127047
|
+
}
|
|
124445
127048
|
} else {
|
|
124446
|
-
for (const
|
|
124447
|
-
await driver
|
|
127049
|
+
for (const chunk of chunks) {
|
|
127050
|
+
await processBatch(driver, queue, chunk);
|
|
124448
127051
|
}
|
|
124449
127052
|
}
|
|
124450
127053
|
}
|
|
@@ -124456,6 +127059,7 @@ class QueueManager {
|
|
|
124456
127059
|
if (!serialized) {
|
|
124457
127060
|
return null;
|
|
124458
127061
|
}
|
|
127062
|
+
this.log(`Popped job from ${queue} (${connection})`, { id: serialized.id });
|
|
124459
127063
|
try {
|
|
124460
127064
|
return serializer.deserialize(serialized);
|
|
124461
127065
|
} catch (error) {
|
|
@@ -124463,14 +127067,71 @@ class QueueManager {
|
|
|
124463
127067
|
return null;
|
|
124464
127068
|
}
|
|
124465
127069
|
}
|
|
127070
|
+
async popMany(queue = "default", count = 10, connection = this.defaultConnection) {
|
|
127071
|
+
const driver = this.getDriver(connection);
|
|
127072
|
+
const serializer = this.getSerializer();
|
|
127073
|
+
const results = [];
|
|
127074
|
+
if (driver.popMany) {
|
|
127075
|
+
const serializedJobs = await driver.popMany(queue, count);
|
|
127076
|
+
if (serializedJobs.length > 0) {
|
|
127077
|
+
this.log(`Popped ${serializedJobs.length} jobs from ${queue} (${connection})`);
|
|
127078
|
+
}
|
|
127079
|
+
for (const serialized of serializedJobs) {
|
|
127080
|
+
try {
|
|
127081
|
+
results.push(serializer.deserialize(serialized));
|
|
127082
|
+
} catch (error) {
|
|
127083
|
+
console.error("[QueueManager] Failed to deserialize job:", error);
|
|
127084
|
+
}
|
|
127085
|
+
}
|
|
127086
|
+
} else {
|
|
127087
|
+
for (let i3 = 0;i3 < count; i3++) {
|
|
127088
|
+
const job = await this.pop(queue, connection);
|
|
127089
|
+
if (job) {
|
|
127090
|
+
results.push(job);
|
|
127091
|
+
} else {
|
|
127092
|
+
break;
|
|
127093
|
+
}
|
|
127094
|
+
}
|
|
127095
|
+
}
|
|
127096
|
+
return results;
|
|
127097
|
+
}
|
|
124466
127098
|
async size(queue = "default", connection = this.defaultConnection) {
|
|
124467
127099
|
const driver = this.getDriver(connection);
|
|
124468
127100
|
return driver.size(queue);
|
|
124469
127101
|
}
|
|
127102
|
+
async popBlocking(queues = "default", timeout = 0, connection = this.defaultConnection) {
|
|
127103
|
+
const driver = this.getDriver(connection);
|
|
127104
|
+
const serializer = this.getSerializer();
|
|
127105
|
+
if (!driver.popBlocking) {
|
|
127106
|
+
const q3 = Array.isArray(queues) ? queues[0] : queues;
|
|
127107
|
+
return this.pop(q3, connection);
|
|
127108
|
+
}
|
|
127109
|
+
const serialized = await driver.popBlocking(queues, timeout);
|
|
127110
|
+
if (!serialized) {
|
|
127111
|
+
return null;
|
|
127112
|
+
}
|
|
127113
|
+
this.log(`Popped job (blocking) from ${Array.isArray(queues) ? queues.join(",") : queues} (${connection})`, { id: serialized.id });
|
|
127114
|
+
try {
|
|
127115
|
+
return serializer.deserialize(serialized);
|
|
127116
|
+
} catch (error) {
|
|
127117
|
+
console.error("[QueueManager] Failed to deserialize job:", error);
|
|
127118
|
+
return null;
|
|
127119
|
+
}
|
|
127120
|
+
}
|
|
124470
127121
|
async clear(queue = "default", connection = this.defaultConnection) {
|
|
124471
127122
|
const driver = this.getDriver(connection);
|
|
124472
127123
|
await driver.clear(queue);
|
|
124473
127124
|
}
|
|
127125
|
+
async stats(queue = "default", connection = this.defaultConnection) {
|
|
127126
|
+
const driver = this.getDriver(connection);
|
|
127127
|
+
if (driver.stats) {
|
|
127128
|
+
return await driver.stats(queue);
|
|
127129
|
+
}
|
|
127130
|
+
return {
|
|
127131
|
+
queue,
|
|
127132
|
+
size: await driver.size(queue)
|
|
127133
|
+
};
|
|
127134
|
+
}
|
|
124474
127135
|
async complete(job) {
|
|
124475
127136
|
const connection = job.connectionName ?? this.defaultConnection;
|
|
124476
127137
|
const queue = job.queueName ?? "default";
|
|
@@ -124479,6 +127140,7 @@ class QueueManager {
|
|
|
124479
127140
|
if (driver.complete) {
|
|
124480
127141
|
const serialized = serializer.serialize(job);
|
|
124481
127142
|
await driver.complete(queue, serialized);
|
|
127143
|
+
this.log(`Completed job ${job.id} in ${queue}`);
|
|
124482
127144
|
if (this.persistence?.archiveCompleted) {
|
|
124483
127145
|
await this.persistence.adapter.archive(queue, serialized, "completed").catch((err) => {
|
|
124484
127146
|
console.error("[QueueManager] Persistence archive failed (completed):", err);
|
|
@@ -124496,6 +127158,7 @@ class QueueManager {
|
|
|
124496
127158
|
serialized.error = error.message;
|
|
124497
127159
|
serialized.failedAt = Date.now();
|
|
124498
127160
|
await driver.fail(queue, serialized);
|
|
127161
|
+
this.log(`Failed job ${job.id} in ${queue}`, { error: error.message });
|
|
124499
127162
|
if (this.persistence?.archiveFailed) {
|
|
124500
127163
|
await this.persistence.adapter.archive(queue, serialized, "failed").catch((err) => {
|
|
124501
127164
|
console.error("[QueueManager] Persistence archive failed (failed):", err);
|
|
@@ -124539,26 +127202,38 @@ class MySQLPersistence {
|
|
|
124539
127202
|
db;
|
|
124540
127203
|
table;
|
|
124541
127204
|
logsTable;
|
|
124542
|
-
constructor(db, table = "flux_job_archive", logsTable = "flux_system_logs") {
|
|
127205
|
+
constructor(db, table = "flux_job_archive", logsTable = "flux_system_logs", _options = {}) {
|
|
124543
127206
|
this.db = db;
|
|
124544
127207
|
this.table = table;
|
|
124545
127208
|
this.logsTable = logsTable;
|
|
124546
127209
|
}
|
|
124547
127210
|
async archive(queue, job, status) {
|
|
124548
|
-
|
|
124549
|
-
|
|
124550
|
-
|
|
124551
|
-
|
|
124552
|
-
|
|
124553
|
-
|
|
124554
|
-
|
|
124555
|
-
|
|
124556
|
-
|
|
124557
|
-
|
|
124558
|
-
|
|
124559
|
-
|
|
127211
|
+
await this.archiveMany([{ queue, job, status }]);
|
|
127212
|
+
}
|
|
127213
|
+
async archiveMany(jobs) {
|
|
127214
|
+
if (jobs.length === 0) {
|
|
127215
|
+
return;
|
|
127216
|
+
}
|
|
127217
|
+
const batchSize = 500;
|
|
127218
|
+
for (let i3 = 0;i3 < jobs.length; i3 += batchSize) {
|
|
127219
|
+
const chunk = jobs.slice(i3, i3 + batchSize);
|
|
127220
|
+
try {
|
|
127221
|
+
const records = chunk.map((item) => ({
|
|
127222
|
+
job_id: item.job.id,
|
|
127223
|
+
queue: item.queue,
|
|
127224
|
+
status: item.status,
|
|
127225
|
+
payload: JSON.stringify(item.job),
|
|
127226
|
+
error: item.job.error || null,
|
|
127227
|
+
created_at: new Date(item.job.createdAt),
|
|
127228
|
+
archived_at: new Date
|
|
127229
|
+
}));
|
|
127230
|
+
await this.db.table(this.table).insert(records);
|
|
127231
|
+
} catch (err) {
|
|
127232
|
+
console.error(`[MySQLPersistence] Failed to archive ${chunk.length} jobs:`, err);
|
|
127233
|
+
}
|
|
124560
127234
|
}
|
|
124561
127235
|
}
|
|
127236
|
+
async flush() {}
|
|
124562
127237
|
async find(queue, id) {
|
|
124563
127238
|
const row = await this.db.table(this.table).where("queue", queue).where("job_id", id).first();
|
|
124564
127239
|
if (!row) {
|
|
@@ -124593,7 +127268,7 @@ class MySQLPersistence {
|
|
|
124593
127268
|
} catch (_e3) {
|
|
124594
127269
|
return null;
|
|
124595
127270
|
}
|
|
124596
|
-
}).filter(
|
|
127271
|
+
}).filter((item) => !!item);
|
|
124597
127272
|
}
|
|
124598
127273
|
async search(query, options = {}) {
|
|
124599
127274
|
let q3 = this.db.table(this.table);
|
|
@@ -124610,19 +127285,27 @@ class MySQLPersistence {
|
|
|
124610
127285
|
} catch (_e3) {
|
|
124611
127286
|
return null;
|
|
124612
127287
|
}
|
|
124613
|
-
}).filter(
|
|
127288
|
+
}).filter((item) => !!item);
|
|
124614
127289
|
}
|
|
124615
127290
|
async archiveLog(log) {
|
|
127291
|
+
await this.archiveLogMany([log]);
|
|
127292
|
+
}
|
|
127293
|
+
async archiveLogMany(logs) {
|
|
127294
|
+
if (logs.length === 0) {
|
|
127295
|
+
return;
|
|
127296
|
+
}
|
|
124616
127297
|
try {
|
|
124617
|
-
|
|
127298
|
+
const records = logs.map((log) => ({
|
|
124618
127299
|
level: log.level,
|
|
124619
127300
|
message: log.message,
|
|
124620
127301
|
worker_id: log.workerId,
|
|
124621
127302
|
queue: log.queue || null,
|
|
124622
127303
|
timestamp: log.timestamp
|
|
124623
|
-
});
|
|
127304
|
+
}));
|
|
127305
|
+
await this.db.table(this.logsTable).insert(records);
|
|
124624
127306
|
} catch (err) {
|
|
124625
|
-
|
|
127307
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
127308
|
+
console.error(`[MySQLPersistence] Failed to archive ${logs.length} logs:`, error.message);
|
|
124626
127309
|
}
|
|
124627
127310
|
}
|
|
124628
127311
|
async listLogs(options = {}) {
|
|
@@ -124667,8 +127350,8 @@ class MySQLPersistence {
|
|
|
124667
127350
|
if (options.endTime) {
|
|
124668
127351
|
query = query.where("timestamp", "<=", options.endTime);
|
|
124669
127352
|
}
|
|
124670
|
-
const result = await query.count(
|
|
124671
|
-
return result
|
|
127353
|
+
const result = await query.count();
|
|
127354
|
+
return Number(result) || 0;
|
|
124672
127355
|
}
|
|
124673
127356
|
async cleanup(days) {
|
|
124674
127357
|
const threshold = new Date;
|
|
@@ -124677,7 +127360,7 @@ class MySQLPersistence {
|
|
|
124677
127360
|
this.db.table(this.table).where("archived_at", "<", threshold).delete(),
|
|
124678
127361
|
this.db.table(this.logsTable).where("timestamp", "<", threshold).delete()
|
|
124679
127362
|
]);
|
|
124680
|
-
return (jobsDeleted || 0) + (logsDeleted || 0);
|
|
127363
|
+
return (Number(jobsDeleted) || 0) + (Number(logsDeleted) || 0);
|
|
124681
127364
|
}
|
|
124682
127365
|
async count(queue, options = {}) {
|
|
124683
127366
|
let query = this.db.table(this.table).where("queue", queue);
|
|
@@ -124693,8 +127376,8 @@ class MySQLPersistence {
|
|
|
124693
127376
|
if (options.endTime) {
|
|
124694
127377
|
query = query.where("archived_at", "<=", options.endTime);
|
|
124695
127378
|
}
|
|
124696
|
-
const result = await query.count(
|
|
124697
|
-
return result
|
|
127379
|
+
const result = await query.count();
|
|
127380
|
+
return Number(result) || 0;
|
|
124698
127381
|
}
|
|
124699
127382
|
async setupTable() {
|
|
124700
127383
|
await Promise.all([this.setupJobsTable(), this.setupLogsTable()]);
|
|
@@ -124745,26 +127428,45 @@ class SQLitePersistence {
|
|
|
124745
127428
|
db;
|
|
124746
127429
|
table;
|
|
124747
127430
|
logsTable;
|
|
124748
|
-
constructor(db, table = "flux_job_archive", logsTable = "flux_system_logs") {
|
|
127431
|
+
constructor(db, table = "flux_job_archive", logsTable = "flux_system_logs", _options = {}) {
|
|
124749
127432
|
this.db = db;
|
|
124750
127433
|
this.table = table;
|
|
124751
127434
|
this.logsTable = logsTable;
|
|
124752
127435
|
}
|
|
124753
127436
|
async archive(queue, job, status) {
|
|
124754
|
-
|
|
124755
|
-
|
|
124756
|
-
|
|
124757
|
-
|
|
124758
|
-
|
|
124759
|
-
|
|
124760
|
-
|
|
124761
|
-
|
|
124762
|
-
|
|
124763
|
-
|
|
124764
|
-
|
|
124765
|
-
|
|
127437
|
+
await this.archiveMany([{ queue, job, status }]);
|
|
127438
|
+
}
|
|
127439
|
+
async archiveMany(jobs) {
|
|
127440
|
+
if (jobs.length === 0) {
|
|
127441
|
+
return;
|
|
127442
|
+
}
|
|
127443
|
+
const batchSize = 200;
|
|
127444
|
+
for (let i3 = 0;i3 < jobs.length; i3 += batchSize) {
|
|
127445
|
+
const chunk = jobs.slice(i3, i3 + batchSize);
|
|
127446
|
+
try {
|
|
127447
|
+
const records = chunk.map((item) => ({
|
|
127448
|
+
job_id: item.job.id,
|
|
127449
|
+
queue: item.queue,
|
|
127450
|
+
status: item.status,
|
|
127451
|
+
payload: JSON.stringify(item.job),
|
|
127452
|
+
error: item.job.error || null,
|
|
127453
|
+
created_at: new Date(item.job.createdAt),
|
|
127454
|
+
archived_at: new Date
|
|
127455
|
+
}));
|
|
127456
|
+
if (typeof this.db.transaction === "function") {
|
|
127457
|
+
await this.db.transaction(async (trx) => {
|
|
127458
|
+
await trx.table(this.table).insert(records);
|
|
127459
|
+
});
|
|
127460
|
+
} else {
|
|
127461
|
+
await this.db.table(this.table).insert(records);
|
|
127462
|
+
}
|
|
127463
|
+
} catch (err) {
|
|
127464
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
127465
|
+
console.error(`[SQLitePersistence] Failed to archive ${chunk.length} jobs:`, error.message);
|
|
127466
|
+
}
|
|
124766
127467
|
}
|
|
124767
127468
|
}
|
|
127469
|
+
async flush() {}
|
|
124768
127470
|
async find(queue, id) {
|
|
124769
127471
|
const row = await this.db.table(this.table).where("queue", queue).where("job_id", id).first();
|
|
124770
127472
|
if (!row) {
|
|
@@ -124799,7 +127501,7 @@ class SQLitePersistence {
|
|
|
124799
127501
|
} catch (_e3) {
|
|
124800
127502
|
return null;
|
|
124801
127503
|
}
|
|
124802
|
-
}).filter(
|
|
127504
|
+
}).filter((item) => !!item);
|
|
124803
127505
|
}
|
|
124804
127506
|
async search(query, options = {}) {
|
|
124805
127507
|
let q3 = this.db.table(this.table);
|
|
@@ -124816,19 +127518,27 @@ class SQLitePersistence {
|
|
|
124816
127518
|
} catch (_e3) {
|
|
124817
127519
|
return null;
|
|
124818
127520
|
}
|
|
124819
|
-
}).filter(
|
|
127521
|
+
}).filter((item) => !!item);
|
|
124820
127522
|
}
|
|
124821
127523
|
async archiveLog(log) {
|
|
127524
|
+
await this.archiveLogMany([log]);
|
|
127525
|
+
}
|
|
127526
|
+
async archiveLogMany(logs) {
|
|
127527
|
+
if (logs.length === 0) {
|
|
127528
|
+
return;
|
|
127529
|
+
}
|
|
124822
127530
|
try {
|
|
124823
|
-
|
|
127531
|
+
const records = logs.map((log) => ({
|
|
124824
127532
|
level: log.level,
|
|
124825
127533
|
message: log.message,
|
|
124826
127534
|
worker_id: log.workerId,
|
|
124827
127535
|
queue: log.queue || null,
|
|
124828
127536
|
timestamp: log.timestamp
|
|
124829
|
-
});
|
|
127537
|
+
}));
|
|
127538
|
+
await this.db.table(this.logsTable).insert(records);
|
|
124830
127539
|
} catch (err) {
|
|
124831
|
-
|
|
127540
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
127541
|
+
console.error(`[SQLitePersistence] Failed to archive ${logs.length} logs:`, error.message);
|
|
124832
127542
|
}
|
|
124833
127543
|
}
|
|
124834
127544
|
async listLogs(options = {}) {
|
|
@@ -124873,8 +127583,8 @@ class SQLitePersistence {
|
|
|
124873
127583
|
if (options.endTime) {
|
|
124874
127584
|
query = query.where("timestamp", "<=", options.endTime);
|
|
124875
127585
|
}
|
|
124876
|
-
const result = await query.count(
|
|
124877
|
-
return result
|
|
127586
|
+
const result = await query.count();
|
|
127587
|
+
return Number(result) || 0;
|
|
124878
127588
|
}
|
|
124879
127589
|
async cleanup(days) {
|
|
124880
127590
|
const threshold = new Date;
|
|
@@ -124883,7 +127593,7 @@ class SQLitePersistence {
|
|
|
124883
127593
|
this.db.table(this.table).where("archived_at", "<", threshold).delete(),
|
|
124884
127594
|
this.db.table(this.logsTable).where("timestamp", "<", threshold).delete()
|
|
124885
127595
|
]);
|
|
124886
|
-
return (jobsDeleted || 0) + (logsDeleted || 0);
|
|
127596
|
+
return (Number(jobsDeleted) || 0) + (Number(logsDeleted) || 0);
|
|
124887
127597
|
}
|
|
124888
127598
|
async count(queue, options = {}) {
|
|
124889
127599
|
let query = this.db.table(this.table).where("queue", queue);
|
|
@@ -124899,8 +127609,8 @@ class SQLitePersistence {
|
|
|
124899
127609
|
if (options.endTime) {
|
|
124900
127610
|
query = query.where("archived_at", "<=", options.endTime);
|
|
124901
127611
|
}
|
|
124902
|
-
const result = await query.count(
|
|
124903
|
-
return result
|
|
127612
|
+
const result = await query.count();
|
|
127613
|
+
return Number(result) || 0;
|
|
124904
127614
|
}
|
|
124905
127615
|
async setupTable() {
|
|
124906
127616
|
await Promise.all([this.setupJobsTable(), this.setupLogsTable()]);
|
|
@@ -125872,20 +128582,20 @@ class PulseService {
|
|
|
125872
128582
|
}
|
|
125873
128583
|
|
|
125874
128584
|
// src/server/services/QueueService.ts
|
|
125875
|
-
import { EventEmitter as
|
|
128585
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
125876
128586
|
var import_ioredis5 = __toESM(require_built4(), 1);
|
|
125877
128587
|
|
|
125878
128588
|
// src/server/services/AlertService.ts
|
|
125879
128589
|
var import_ioredis4 = __toESM(require_built4(), 1);
|
|
125880
128590
|
var import_nodemailer = __toESM(require_nodemailer(), 1);
|
|
125881
|
-
import { EventEmitter } from "events";
|
|
128591
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
125882
128592
|
|
|
125883
128593
|
class AlertService {
|
|
125884
128594
|
redis;
|
|
125885
128595
|
rules = [];
|
|
125886
128596
|
config = { channels: {} };
|
|
125887
128597
|
cooldowns = new Map;
|
|
125888
|
-
emitter = new
|
|
128598
|
+
emitter = new EventEmitter2;
|
|
125889
128599
|
RULES_KEY = "gravito:zenith:alerts:rules";
|
|
125890
128600
|
CONFIG_KEY = "gravito:zenith:alerts:config";
|
|
125891
128601
|
constructor(redisUrl) {
|
|
@@ -126132,13 +128842,13 @@ Severity: ${event.severity}`,
|
|
|
126132
128842
|
}
|
|
126133
128843
|
|
|
126134
128844
|
// src/server/services/LogStreamProcessor.ts
|
|
126135
|
-
import { EventEmitter as
|
|
128845
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
126136
128846
|
|
|
126137
128847
|
class LogStreamProcessor {
|
|
126138
128848
|
redis;
|
|
126139
128849
|
subRedis;
|
|
126140
128850
|
static MAX_LOGS_PER_SEC = 50;
|
|
126141
|
-
logEmitter = new
|
|
128851
|
+
logEmitter = new EventEmitter3;
|
|
126142
128852
|
logThrottleCount = 0;
|
|
126143
128853
|
logThrottleReset = Date.now();
|
|
126144
128854
|
constructor(redis, subRedis) {
|
|
@@ -126341,7 +129051,7 @@ class QueueService {
|
|
|
126341
129051
|
redis;
|
|
126342
129052
|
subRedis;
|
|
126343
129053
|
prefix;
|
|
126344
|
-
logEmitter = new
|
|
129054
|
+
logEmitter = new EventEmitter4;
|
|
126345
129055
|
manager;
|
|
126346
129056
|
alerts;
|
|
126347
129057
|
logProcessor;
|
|
@@ -126776,7 +129486,7 @@ if (dbDriver === "sqlite" || process.env.DB_HOST) {
|
|
|
126776
129486
|
password: process.env.DB_PASSWORD || ""
|
|
126777
129487
|
});
|
|
126778
129488
|
}
|
|
126779
|
-
const adapter = dbDriver === "sqlite" ? new SQLitePersistence(DB) : new MySQLPersistence(DB);
|
|
129489
|
+
const adapter = dbDriver === "sqlite" ? new SQLitePersistence(DB.connection()) : new MySQLPersistence(DB.connection());
|
|
126780
129490
|
adapter.setupTable().catch((err) => console.error("[FluxConsole] SQL Archive Setup Error:", err));
|
|
126781
129491
|
persistence = {
|
|
126782
129492
|
adapter,
|