@dangao/bun-server 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/cluster.d.ts.map +1 -1
- package/dist/database/connection-pool.d.ts +10 -0
- package/dist/database/connection-pool.d.ts.map +1 -1
- package/dist/index.js +37 -8
- package/dist/index.node.mjs +37 -8
- package/dist/platform/bun/parser.d.ts.map +1 -1
- package/dist/platform/node/parser.d.ts.map +1 -1
- package/dist/platform/types.d.ts +2 -0
- package/dist/platform/types.d.ts.map +1 -1
- package/dist/queue/service.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/cluster.ts +5 -1
- package/src/database/connection-pool.ts +15 -0
- package/src/platform/bun/parser.ts +4 -0
- package/src/platform/node/http.ts +13 -2
- package/src/platform/node/parser.ts +6 -0
- package/src/platform/types.ts +2 -0
- package/src/queue/service.ts +22 -11
- package/src/types/bun-augment.d.ts +24 -0
- package/tests/database/sqlite-adapter.test.ts +7 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/core/cluster.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B;;;OAGG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,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I,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,SAAS,CAAC,CAAS;gBAER,OAAO,EAAE;QAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,WAAW,CAAC;KACpB;IAWD;;OAEG;IACI,OAAO,IAAI,WAAW,GAAG,OAAO;IAIvC;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQnC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAuClC,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,uBAAuB;YAiBjB,UAAU;IA6BxB,OAAO,CAAC,gBAAgB;YAkBV,oBAAoB;YA4BpB,gBAAgB;IA2B9B,OAAO,CAAC,mBAAmB;IAoC3B;;OAEG;WACW,QAAQ,IAAI,OAAO;IAIjC;;OAEG;WACW,WAAW,IAAI,MAAM;IAInC;;;OAGG;WACW,cAAc,IAAI,WAAW,GAAG,OAAO,GAAG,IAAI;CAI7D"}
|
|
@@ -22,6 +22,16 @@ export declare class ConnectionPool {
|
|
|
22
22
|
* 关闭连接池
|
|
23
23
|
*/
|
|
24
24
|
close(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取连接并返回 Disposable 对象,支持 `await using` 语法(Bun 1.3.12+ / TC39 Explicit Resource Management)
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* await using { connection } = await pool.acquireDisposable();
|
|
30
|
+
* // 作用域结束时自动调用 release,无需手动释放
|
|
31
|
+
*/
|
|
32
|
+
acquireDisposable(): Promise<{
|
|
33
|
+
connection: unknown;
|
|
34
|
+
} & Disposable>;
|
|
25
35
|
/**
|
|
26
36
|
* 获取池状态信息
|
|
27
37
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-pool.d.ts","sourceRoot":"","sources":["../../src/database/connection-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EAEf,MAAM,SAAS,CAAC;AAyBjB;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,kBAAkB,CAAoC;IAC9D,OAAO,CAAC,SAAS,CAAS;gBAGxB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,qBAA0B;IAWrC;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IA8BxC;;OAEG;IACI,OAAO,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI;IAUzC;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBnC;;OAEG;IACI,YAAY,IAAI;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,cAAc,EAAE,MAAM,CAAC;KACxB;IAUD;;OAEG;YACW,gBAAgB;IAY9B;;OAEG;YACW,yBAAyB;IAuBvC;;OAEG;YACW,sBAAsB;IAqBpC;;OAEG;YACW,wBAAwB;IAoBtC;;OAEG;YACW,qBAAqB;IA0BnC;;OAEG;YACW,eAAe;IAW7B;;OAEG;YACW,qBAAqB;IAWnC;;OAEG;YACW,uBAAuB;IAarC;;OAEG;YACW,oBAAoB;IAalC;;OAEG;YACW,iBAAiB;IAoB/B;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
|
1
|
+
{"version":3,"file":"connection-pool.d.ts","sourceRoot":"","sources":["../../src/database/connection-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EAEf,MAAM,SAAS,CAAC;AAyBjB;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,kBAAkB,CAAoC;IAC9D,OAAO,CAAC,SAAS,CAAS;gBAGxB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,qBAA0B;IAWrC;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IA8BxC;;OAEG;IACI,OAAO,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI;IAUzC;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBnC;;;;;;OAMG;IACU,iBAAiB,IAAI,OAAO,CAAC;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE,GAAG,UAAU,CAAC;IAQ/E;;OAEG;IACI,YAAY,IAAI;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,cAAc,EAAE,MAAM,CAAC;KACxB;IAUD;;OAEG;YACW,gBAAgB;IAY9B;;OAEG;YACW,yBAAyB;IAuBvC;;OAEG;YACW,sBAAsB;IAqBpC;;OAEG;YACW,wBAAwB;IAoBtC;;OAEG;YACW,qBAAqB;IA0BnC;;OAEG;YACW,eAAe;IAW7B;;OAEG;YACW,qBAAqB;IAWnC;;OAEG;YACW,uBAAuB;IAarC;;OAEG;YACW,oBAAoB;IAalC;;OAEG;YACW,iBAAiB;IAoB/B;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
package/dist/index.js
CHANGED
|
@@ -196,6 +196,9 @@ var init_parser = __esm(() => {
|
|
|
196
196
|
},
|
|
197
197
|
renderMarkdown(md) {
|
|
198
198
|
return Bun.markdown.html(md, { headings: true });
|
|
199
|
+
},
|
|
200
|
+
renderMarkdownAnsi(md) {
|
|
201
|
+
return Bun.markdown.ansi(md);
|
|
199
202
|
}
|
|
200
203
|
};
|
|
201
204
|
});
|
|
@@ -12548,6 +12551,10 @@ var init_parser2 = __esm(() => {
|
|
|
12548
12551
|
const { marked: markedSync } = (init_marked_esm(), __toCommonJS(exports_marked_esm));
|
|
12549
12552
|
markedSync.setOptions({ async: false });
|
|
12550
12553
|
return markedSync(md);
|
|
12554
|
+
},
|
|
12555
|
+
renderMarkdownAnsi(md) {
|
|
12556
|
+
const html = this.renderMarkdown(md);
|
|
12557
|
+
return html.replace(/<[^>]+>/g, "");
|
|
12551
12558
|
}
|
|
12552
12559
|
};
|
|
12553
12560
|
});
|
|
@@ -12704,7 +12711,10 @@ function setupWebSocket(httpServer, handlers) {
|
|
|
12704
12711
|
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
12705
12712
|
` + "Install it with: bun add ws");
|
|
12706
12713
|
}
|
|
12707
|
-
const
|
|
12714
|
+
const WebSocketServer = wsModule.WebSocketServer ?? wsModule.default?.WebSocketServer ?? wsModule.Server;
|
|
12715
|
+
if (!WebSocketServer) {
|
|
12716
|
+
throw new Error("[bun-server] Could not find WebSocketServer in the ws module. " + "Please ensure ws >= 7.5.0 is installed.");
|
|
12717
|
+
}
|
|
12708
12718
|
const wss = new WebSocketServer({ noServer: true });
|
|
12709
12719
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
12710
12720
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -46064,6 +46074,13 @@ class ConnectionPool {
|
|
|
46064
46074
|
this.connections = [];
|
|
46065
46075
|
this.isClosing = false;
|
|
46066
46076
|
}
|
|
46077
|
+
async acquireDisposable() {
|
|
46078
|
+
const connection2 = await this.acquire();
|
|
46079
|
+
return {
|
|
46080
|
+
connection: connection2,
|
|
46081
|
+
[Symbol.dispose]: () => this.release(connection2)
|
|
46082
|
+
};
|
|
46083
|
+
}
|
|
46067
46084
|
getPoolStats() {
|
|
46068
46085
|
const inUse = this.connections.filter((conn) => conn.inUse).length;
|
|
46069
46086
|
return {
|
|
@@ -48282,6 +48299,7 @@ var QUEUE_SERVICE_TOKEN = Symbol("@dangao/bun-server:queue:service");
|
|
|
48282
48299
|
var QUEUE_OPTIONS_TOKEN = Symbol("@dangao/bun-server:queue:options");
|
|
48283
48300
|
|
|
48284
48301
|
// src/queue/service.ts
|
|
48302
|
+
init_runtime();
|
|
48285
48303
|
class QueueService {
|
|
48286
48304
|
store;
|
|
48287
48305
|
defaultQueue;
|
|
@@ -48340,12 +48358,19 @@ class QueueService {
|
|
|
48340
48358
|
if (options.runOnInit) {
|
|
48341
48359
|
await this.add(jobName, {}, undefined, queue);
|
|
48342
48360
|
}
|
|
48343
|
-
|
|
48344
|
-
|
|
48345
|
-
const timer2 = setInterval(async () => {
|
|
48361
|
+
if (getRuntime().engine === "bun") {
|
|
48362
|
+
const job = Bun.cron(options.pattern, async () => {
|
|
48346
48363
|
await this.add(jobName, {}, undefined, queue);
|
|
48347
|
-
}
|
|
48348
|
-
this.cronTimers.set(key,
|
|
48364
|
+
});
|
|
48365
|
+
this.cronTimers.set(key, job);
|
|
48366
|
+
} else {
|
|
48367
|
+
const interval = this.parseCronInterval(options.pattern);
|
|
48368
|
+
if (interval > 0) {
|
|
48369
|
+
const timer2 = setInterval(async () => {
|
|
48370
|
+
await this.add(jobName, {}, undefined, queue);
|
|
48371
|
+
}, interval);
|
|
48372
|
+
this.cronTimers.set(key, timer2);
|
|
48373
|
+
}
|
|
48349
48374
|
}
|
|
48350
48375
|
}
|
|
48351
48376
|
startWorker(queueName) {
|
|
@@ -48405,8 +48430,12 @@ class QueueService {
|
|
|
48405
48430
|
return -1;
|
|
48406
48431
|
}
|
|
48407
48432
|
destroy() {
|
|
48408
|
-
for (const
|
|
48409
|
-
|
|
48433
|
+
for (const handle of this.cronTimers.values()) {
|
|
48434
|
+
if (handle && typeof handle === "object" && "stop" in handle) {
|
|
48435
|
+
handle.stop();
|
|
48436
|
+
} else {
|
|
48437
|
+
clearInterval(handle);
|
|
48438
|
+
}
|
|
48410
48439
|
}
|
|
48411
48440
|
this.cronTimers.clear();
|
|
48412
48441
|
this.cronJobs.clear();
|
package/dist/index.node.mjs
CHANGED
|
@@ -199,6 +199,9 @@ var init_parser = __esm(() => {
|
|
|
199
199
|
},
|
|
200
200
|
renderMarkdown(md) {
|
|
201
201
|
return Bun.markdown.html(md, { headings: true });
|
|
202
|
+
},
|
|
203
|
+
renderMarkdownAnsi(md) {
|
|
204
|
+
return Bun.markdown.ansi(md);
|
|
202
205
|
}
|
|
203
206
|
};
|
|
204
207
|
});
|
|
@@ -509,6 +512,10 @@ var init_parser2 = __esm(() => {
|
|
|
509
512
|
const { marked: markedSync } = __require("marked");
|
|
510
513
|
markedSync.setOptions({ async: false });
|
|
511
514
|
return markedSync(md);
|
|
515
|
+
},
|
|
516
|
+
renderMarkdownAnsi(md) {
|
|
517
|
+
const html = this.renderMarkdown(md);
|
|
518
|
+
return html.replace(/<[^>]+>/g, "");
|
|
512
519
|
}
|
|
513
520
|
};
|
|
514
521
|
});
|
|
@@ -665,7 +672,10 @@ function setupWebSocket(httpServer, handlers) {
|
|
|
665
672
|
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
666
673
|
` + "Install it with: bun add ws");
|
|
667
674
|
}
|
|
668
|
-
const
|
|
675
|
+
const WebSocketServer = wsModule.WebSocketServer ?? wsModule.default?.WebSocketServer ?? wsModule.Server;
|
|
676
|
+
if (!WebSocketServer) {
|
|
677
|
+
throw new Error("[bun-server] Could not find WebSocketServer in the ws module. " + "Please ensure ws >= 7.5.0 is installed.");
|
|
678
|
+
}
|
|
669
679
|
const wss = new WebSocketServer({ noServer: true });
|
|
670
680
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
671
681
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -10895,6 +10905,13 @@ class ConnectionPool {
|
|
|
10895
10905
|
this.connections = [];
|
|
10896
10906
|
this.isClosing = false;
|
|
10897
10907
|
}
|
|
10908
|
+
async acquireDisposable() {
|
|
10909
|
+
const connection = await this.acquire();
|
|
10910
|
+
return {
|
|
10911
|
+
connection,
|
|
10912
|
+
[Symbol.dispose]: () => this.release(connection)
|
|
10913
|
+
};
|
|
10914
|
+
}
|
|
10898
10915
|
getPoolStats() {
|
|
10899
10916
|
const inUse = this.connections.filter((conn) => conn.inUse).length;
|
|
10900
10917
|
return {
|
|
@@ -13113,6 +13130,7 @@ var QUEUE_SERVICE_TOKEN = Symbol("@dangao/bun-server:queue:service");
|
|
|
13113
13130
|
var QUEUE_OPTIONS_TOKEN = Symbol("@dangao/bun-server:queue:options");
|
|
13114
13131
|
|
|
13115
13132
|
// src/queue/service.ts
|
|
13133
|
+
init_runtime();
|
|
13116
13134
|
class QueueService {
|
|
13117
13135
|
store;
|
|
13118
13136
|
defaultQueue;
|
|
@@ -13171,12 +13189,19 @@ class QueueService {
|
|
|
13171
13189
|
if (options.runOnInit) {
|
|
13172
13190
|
await this.add(jobName, {}, undefined, queue);
|
|
13173
13191
|
}
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
const timer = setInterval(async () => {
|
|
13192
|
+
if (getRuntime().engine === "bun") {
|
|
13193
|
+
const job = Bun.cron(options.pattern, async () => {
|
|
13177
13194
|
await this.add(jobName, {}, undefined, queue);
|
|
13178
|
-
}
|
|
13179
|
-
this.cronTimers.set(key,
|
|
13195
|
+
});
|
|
13196
|
+
this.cronTimers.set(key, job);
|
|
13197
|
+
} else {
|
|
13198
|
+
const interval = this.parseCronInterval(options.pattern);
|
|
13199
|
+
if (interval > 0) {
|
|
13200
|
+
const timer = setInterval(async () => {
|
|
13201
|
+
await this.add(jobName, {}, undefined, queue);
|
|
13202
|
+
}, interval);
|
|
13203
|
+
this.cronTimers.set(key, timer);
|
|
13204
|
+
}
|
|
13180
13205
|
}
|
|
13181
13206
|
}
|
|
13182
13207
|
startWorker(queueName) {
|
|
@@ -13236,8 +13261,12 @@ class QueueService {
|
|
|
13236
13261
|
return -1;
|
|
13237
13262
|
}
|
|
13238
13263
|
destroy() {
|
|
13239
|
-
for (const
|
|
13240
|
-
|
|
13264
|
+
for (const handle of this.cronTimers.values()) {
|
|
13265
|
+
if (handle && typeof handle === "object" && "stop" in handle) {
|
|
13266
|
+
handle.stop();
|
|
13267
|
+
} else {
|
|
13268
|
+
clearInterval(handle);
|
|
13269
|
+
}
|
|
13241
13270
|
}
|
|
13242
13271
|
this.cronTimers.clear();
|
|
13243
13272
|
this.cronJobs.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/platform/bun/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/platform/bun/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,gBAAgB,EAAE,cAoB9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/platform/node/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/platform/node/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,iBAAiB,EAAE,cAqC/B,CAAC"}
|
package/dist/platform/types.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface IParserAdapter {
|
|
|
48
48
|
parseJSON5(content: string): unknown;
|
|
49
49
|
parseJSONL(content: string): unknown[];
|
|
50
50
|
renderMarkdown(md: string): string;
|
|
51
|
+
/** 将 Markdown 渲染为 ANSI 着色字符串,用于终端 / CLI 输出(Bun 1.3.12+) */
|
|
52
|
+
renderMarkdownAnsi(md: string): string;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* 子进程接口
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/platform/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7B,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IACpC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3B,gDAAgD;IAChD,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,aAAa;IACb,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,WAAW;IACX,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,aAAa;IACb,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,I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AW,CAAC;CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/queue/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,kBAAkB,EAClB,GAAG,EACH,OAAO,EACP,UAAU,EACV,UAAU,EACV,WAAW,EACZ,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/queue/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,kBAAkB,EAClB,GAAG,EACH,OAAO,EACP,UAAU,EACV,UAAU,EACV,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBACa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,QAAQ,CACJ;IACZ,OAAO,CAAC,UAAU,CAA6E;gBAE/C,OAAO,EAAE,kBAAkB;IAW3E;;;;;;;OAOG;IACU,GAAG,CAAC,CAAC,GAAG,OAAO,EAC1B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,CAAC,EACP,OAAO,CAAC,EAAE,UAAU,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IAgBlB;;;;;OAKG;IACU,GAAG,CAAC,CAAC,GAAG,OAAO,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAK9B;;;;;OAKG;IACU,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxE;;;;OAIG;IACU,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD;;;;OAIG;IACU,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvD;;;;;OAKG;IACU,eAAe,CAAC,CAAC,GAAG,OAAO,EACtC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EACtB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAehB;;;;;;OAMG;IACU,YAAY,CAAC,CAAC,GAAG,OAAO,EACnC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,WAAW,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IA6BhB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAenB;;;OAGG;YACW,YAAY;IAoC1B;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAUlB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAqCzB;;OAEG;IACI,OAAO,IAAI,IAAI;CAYvB"}
|
package/package.json
CHANGED
package/src/core/cluster.ts
CHANGED
|
@@ -186,7 +186,8 @@ export class ClusterManager {
|
|
|
186
186
|
);
|
|
187
187
|
|
|
188
188
|
this.socketDir = join(tmpdir(), `bun-cluster-${process.pid}`);
|
|
189
|
-
//
|
|
189
|
+
// Bun 1.3.12+:绑定已存在的 unix socket 会正确抛出 EADDRINUSE(不再静默覆盖),
|
|
190
|
+
// 因此必须在启动前清理同 PID 上一次运行遗留的目录。
|
|
190
191
|
try { rmSync(this.socketDir, { recursive: true, force: true }); } catch (_error) { /* ignore */ }
|
|
191
192
|
mkdirSync(this.socketDir, { recursive: true });
|
|
192
193
|
|
|
@@ -291,6 +292,9 @@ export class ClusterManager {
|
|
|
291
292
|
);
|
|
292
293
|
|
|
293
294
|
const socketPath = this.socketPaths[index]!;
|
|
295
|
+
// Bun 1.3.12+:worker 正常退出时 Bun.serve stop() 会自动删除 socket 文件;
|
|
296
|
+
// 但崩溃(SIGKILL / 异常退出)时 stop() 不会被调用,socket 文件仍残留,
|
|
297
|
+
// 此处手动清理确保新 worker 能成功绑定(否则会得到 EADDRINUSE)。
|
|
294
298
|
try { rmSync(socketPath); } catch (_error) { /* ignore */ }
|
|
295
299
|
|
|
296
300
|
this.workers[index] = this.spawnProxyWorker(index, socketPath);
|
|
@@ -116,6 +116,21 @@ export class ConnectionPool {
|
|
|
116
116
|
this.isClosing = false;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* 获取连接并返回 Disposable 对象,支持 `await using` 语法(Bun 1.3.12+ / TC39 Explicit Resource Management)
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* await using { connection } = await pool.acquireDisposable();
|
|
124
|
+
* // 作用域结束时自动调用 release,无需手动释放
|
|
125
|
+
*/
|
|
126
|
+
public async acquireDisposable(): Promise<{ connection: unknown } & Disposable> {
|
|
127
|
+
const connection = await this.acquire();
|
|
128
|
+
return {
|
|
129
|
+
connection,
|
|
130
|
+
[Symbol.dispose]: () => this.release(connection),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
119
134
|
/**
|
|
120
135
|
* 获取池状态信息
|
|
121
136
|
*/
|
|
@@ -178,8 +178,19 @@ function setupWebSocket<T>(
|
|
|
178
178
|
'Install it with: bun add ws',
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
// Handle CJS (WebSocketServer as class property) and ESM interop (named export)
|
|
182
|
+
// Also falls back to .Server for ws < 7.5.0
|
|
183
|
+
const WebSocketServer =
|
|
184
|
+
(wsModule as unknown as Record<string, unknown>).WebSocketServer ??
|
|
185
|
+
(wsModule as unknown as { default?: Record<string, unknown> }).default?.WebSocketServer ??
|
|
186
|
+
(wsModule as unknown as Record<string, unknown>).Server;
|
|
187
|
+
if (!WebSocketServer) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
'[bun-server] Could not find WebSocketServer in the ws module. ' +
|
|
190
|
+
'Please ensure ws >= 7.5.0 is installed.',
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
const wss = new (WebSocketServer as new (opts: unknown) => import('ws').WebSocketServer)({ noServer: true });
|
|
183
194
|
|
|
184
195
|
httpServer.on('upgrade', (request, socket, head) => {
|
|
185
196
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -31,4 +31,10 @@ export const nodeParserAdapter: IParserAdapter = {
|
|
|
31
31
|
markedSync.setOptions({ async: false });
|
|
32
32
|
return markedSync(md) as string;
|
|
33
33
|
},
|
|
34
|
+
|
|
35
|
+
renderMarkdownAnsi(md: string): string {
|
|
36
|
+
// Node.js 平台无 Bun.markdown.ansi(),降级为纯文本(去除 HTML 标签)
|
|
37
|
+
const html = this.renderMarkdown(md);
|
|
38
|
+
return html.replace(/<[^>]+>/g, '');
|
|
39
|
+
},
|
|
34
40
|
};
|
package/src/platform/types.ts
CHANGED
|
@@ -53,6 +53,8 @@ export interface IParserAdapter {
|
|
|
53
53
|
parseJSON5(content: string): unknown;
|
|
54
54
|
parseJSONL(content: string): unknown[];
|
|
55
55
|
renderMarkdown(md: string): string;
|
|
56
|
+
/** 将 Markdown 渲染为 ANSI 着色字符串,用于终端 / CLI 输出(Bun 1.3.12+) */
|
|
57
|
+
renderMarkdownAnsi(md: string): string;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/**
|
package/src/queue/service.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
CronOptions,
|
|
11
11
|
} from './types';
|
|
12
12
|
import { QUEUE_OPTIONS_TOKEN } from './types';
|
|
13
|
+
import { getRuntime } from '../platform/runtime';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* 队列服务
|
|
@@ -23,7 +24,7 @@ export class QueueService {
|
|
|
23
24
|
private workers: Map<string, Set<Promise<void>>> = new Map();
|
|
24
25
|
private cronJobs: Map<string, { handler: JobHandler; options: CronOptions }> =
|
|
25
26
|
new Map();
|
|
26
|
-
private cronTimers: Map<string, ReturnType<typeof setInterval
|
|
27
|
+
private cronTimers: Map<string, ReturnType<typeof setInterval> | { stop(): void }> = new Map();
|
|
27
28
|
|
|
28
29
|
public constructor(@Inject(QUEUE_OPTIONS_TOKEN) options: QueueModuleOptions) {
|
|
29
30
|
this.store = options.store!;
|
|
@@ -158,14 +159,21 @@ export class QueueService {
|
|
|
158
159
|
await this.add(jobName, {} as T, undefined, queue);
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (interval > 0) {
|
|
165
|
-
const timer = setInterval(async () => {
|
|
162
|
+
if (getRuntime().engine === 'bun') {
|
|
163
|
+
// Bun 平台:使用原生 Bun.cron() —— 支持完整 cron 表达式、无重叠、--hot 安全、UTC 调度
|
|
164
|
+
const job = (Bun as any).cron(options.pattern, async () => {
|
|
166
165
|
await this.add(jobName, {} as T, undefined, queue);
|
|
167
|
-
}
|
|
168
|
-
this.cronTimers.set(key,
|
|
166
|
+
});
|
|
167
|
+
this.cronTimers.set(key, job);
|
|
168
|
+
} else {
|
|
169
|
+
// Node.js 平台兜底:简化实现,仅支持基础 cron 格式
|
|
170
|
+
const interval = this.parseCronInterval(options.pattern);
|
|
171
|
+
if (interval > 0) {
|
|
172
|
+
const timer = setInterval(async () => {
|
|
173
|
+
await this.add(jobName, {} as T, undefined, queue);
|
|
174
|
+
}, interval);
|
|
175
|
+
this.cronTimers.set(key, timer);
|
|
176
|
+
}
|
|
169
177
|
}
|
|
170
178
|
}
|
|
171
179
|
|
|
@@ -291,9 +299,12 @@ export class QueueService {
|
|
|
291
299
|
* 销毁服务,清理资源
|
|
292
300
|
*/
|
|
293
301
|
public destroy(): void {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
302
|
+
for (const handle of this.cronTimers.values()) {
|
|
303
|
+
if (handle && typeof handle === 'object' && 'stop' in handle) {
|
|
304
|
+
(handle as { stop(): void }).stop();
|
|
305
|
+
} else {
|
|
306
|
+
clearInterval(handle as ReturnType<typeof setInterval>);
|
|
307
|
+
}
|
|
297
308
|
}
|
|
298
309
|
this.cronTimers.clear();
|
|
299
310
|
this.cronJobs.clear();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun v1.3.12 新增 API 的类型补全
|
|
3
|
+
* 待 @types/bun 升级至对应版本后可删除此文件
|
|
4
|
+
*/
|
|
5
|
+
declare module 'bun' {
|
|
6
|
+
namespace markdown {
|
|
7
|
+
/**
|
|
8
|
+
* 将 Markdown 字符串渲染为带 ANSI 转义码的彩色终端文本(Bun 1.3.12+)
|
|
9
|
+
*/
|
|
10
|
+
function ansi(
|
|
11
|
+
input: string,
|
|
12
|
+
options?: {
|
|
13
|
+
/** 是否输出 ANSI 颜色转义码,默认 true */
|
|
14
|
+
colors?: boolean;
|
|
15
|
+
/** 是否输出可点击超链接(OSC 8),默认 false */
|
|
16
|
+
hyperlinks?: boolean;
|
|
17
|
+
/** 文本换行列宽,默认终端宽度 */
|
|
18
|
+
columns?: number;
|
|
19
|
+
/** 是否通过 Kitty Graphics Protocol 内联图片,默认 false */
|
|
20
|
+
kittyGraphics?: boolean;
|
|
21
|
+
},
|
|
22
|
+
): string;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
1
|
+
import { beforeAll, describe, expect, test } from 'bun:test';
|
|
2
2
|
|
|
3
3
|
import { Semaphore, SqliteAdapter } from '../../src/database/sqlite-adapter';
|
|
4
|
+
import { initRuntime } from '../../src/platform/runtime';
|
|
5
|
+
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
initRuntime();
|
|
8
|
+
});
|
|
4
9
|
|
|
5
10
|
describe('SqliteAdapter', () => {
|
|
6
11
|
test('should execute query and write', async () => {
|
|
@@ -15,7 +20,7 @@ describe('SqliteAdapter', () => {
|
|
|
15
20
|
);
|
|
16
21
|
await adapter.execute('INSERT INTO users (name) VALUES (?)', ['alice']);
|
|
17
22
|
|
|
18
|
-
const rows = adapter.query<{ id: number; name: string }>(
|
|
23
|
+
const rows = await adapter.query<{ id: number; name: string }>(
|
|
19
24
|
'SELECT * FROM users',
|
|
20
25
|
);
|
|
21
26
|
expect(rows.length).toBe(1);
|