@dangao/bun-server 3.0.1 → 3.0.3
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/database/connection-pool.d.ts.map +1 -1
- package/dist/database/sqlite-adapter.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.node.mjs +22 -3
- package/package.json +14 -4
- package/src/database/connection-pool.ts +11 -3
- package/src/database/sqlite-adapter.ts +10 -2
- package/src/platform/node/http.ts +11 -1
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"connection-pool.d.ts","sourceRoot":"","sources":["../../src/database/connection-pool.ts"],"names":[],"mappings":"A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AE,OAAO,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAejE,KAAK,IAAI,IAAI;CAKrB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoC;IAC9D,OAAO,CAAC,eAAe,CAAa;IAE7B,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,aAAa;IAUpE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIxC,UAAU,IAAI,aAAa;IAU3B,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa;IAQ3C,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAS/B,UAAU,IAAI,IAAI;CAM1B"}
|
package/dist/index.js
CHANGED
|
@@ -12697,7 +12697,14 @@ function sendWebResponse(res, webResponse) {
|
|
|
12697
12697
|
pump();
|
|
12698
12698
|
}
|
|
12699
12699
|
function setupWebSocket(httpServer, handlers) {
|
|
12700
|
-
|
|
12700
|
+
let wsModule;
|
|
12701
|
+
try {
|
|
12702
|
+
wsModule = __require("ws");
|
|
12703
|
+
} catch {
|
|
12704
|
+
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
12705
|
+
` + "Install it with: bun add ws");
|
|
12706
|
+
}
|
|
12707
|
+
const { WebSocketServer } = wsModule;
|
|
12701
12708
|
const wss = new WebSocketServer({ noServer: true });
|
|
12702
12709
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
12703
12710
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -46101,7 +46108,13 @@ class ConnectionPool {
|
|
|
46101
46108
|
const { Database } = await import("bun:sqlite");
|
|
46102
46109
|
return new Database(config.path);
|
|
46103
46110
|
}
|
|
46104
|
-
|
|
46111
|
+
let sqlite3;
|
|
46112
|
+
try {
|
|
46113
|
+
sqlite3 = __require("@vscode/sqlite3");
|
|
46114
|
+
} catch {
|
|
46115
|
+
throw new Error(`[bun-server] SQLite on Node.js requires @vscode/sqlite3.
|
|
46116
|
+
Install it with: bun add @vscode/sqlite3@5.1.12-vscode`);
|
|
46117
|
+
}
|
|
46105
46118
|
return new sqlite3.Database(config.path);
|
|
46106
46119
|
}
|
|
46107
46120
|
async createPostgresConnection(config) {
|
|
@@ -46582,7 +46595,13 @@ class SqliteAdapter {
|
|
|
46582
46595
|
}
|
|
46583
46596
|
this.db = db2;
|
|
46584
46597
|
} else {
|
|
46585
|
-
|
|
46598
|
+
let sqlite3;
|
|
46599
|
+
try {
|
|
46600
|
+
sqlite3 = __require("@vscode/sqlite3");
|
|
46601
|
+
} catch {
|
|
46602
|
+
throw new Error(`[bun-server] SQLite on Node.js requires @vscode/sqlite3.
|
|
46603
|
+
` + "Install it with: bun add @vscode/sqlite3@5.1.12-vscode");
|
|
46604
|
+
}
|
|
46586
46605
|
const db2 = new sqlite3.Database(config.database);
|
|
46587
46606
|
if (config.wal !== false) {
|
|
46588
46607
|
db2.run("PRAGMA journal_mode = WAL;");
|
package/dist/index.node.mjs
CHANGED
|
@@ -658,7 +658,14 @@ function sendWebResponse(res, webResponse) {
|
|
|
658
658
|
pump();
|
|
659
659
|
}
|
|
660
660
|
function setupWebSocket(httpServer, handlers) {
|
|
661
|
-
|
|
661
|
+
let wsModule;
|
|
662
|
+
try {
|
|
663
|
+
wsModule = __require("ws");
|
|
664
|
+
} catch {
|
|
665
|
+
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
666
|
+
` + "Install it with: bun add ws");
|
|
667
|
+
}
|
|
668
|
+
const { WebSocketServer } = wsModule;
|
|
662
669
|
const wss = new WebSocketServer({ noServer: true });
|
|
663
670
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
664
671
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
@@ -10932,7 +10939,13 @@ class ConnectionPool {
|
|
|
10932
10939
|
const { Database } = await import("bun:sqlite");
|
|
10933
10940
|
return new Database(config.path);
|
|
10934
10941
|
}
|
|
10935
|
-
|
|
10942
|
+
let sqlite3;
|
|
10943
|
+
try {
|
|
10944
|
+
sqlite3 = __require("@vscode/sqlite3");
|
|
10945
|
+
} catch {
|
|
10946
|
+
throw new Error(`[bun-server] SQLite on Node.js requires @vscode/sqlite3.
|
|
10947
|
+
Install it with: bun add @vscode/sqlite3@5.1.12-vscode`);
|
|
10948
|
+
}
|
|
10936
10949
|
return new sqlite3.Database(config.path);
|
|
10937
10950
|
}
|
|
10938
10951
|
async createPostgresConnection(config) {
|
|
@@ -11413,7 +11426,13 @@ class SqliteAdapter {
|
|
|
11413
11426
|
}
|
|
11414
11427
|
this.db = db;
|
|
11415
11428
|
} else {
|
|
11416
|
-
|
|
11429
|
+
let sqlite3;
|
|
11430
|
+
try {
|
|
11431
|
+
sqlite3 = __require("@vscode/sqlite3");
|
|
11432
|
+
} catch {
|
|
11433
|
+
throw new Error(`[bun-server] SQLite on Node.js requires @vscode/sqlite3.
|
|
11434
|
+
` + "Install it with: bun add @vscode/sqlite3@5.1.12-vscode");
|
|
11435
|
+
}
|
|
11417
11436
|
const db = new sqlite3.Database(config.database);
|
|
11418
11437
|
if (config.wal !== false) {
|
|
11419
11438
|
db.run("PRAGMA journal_mode = WAL;");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dangao/bun-server",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -65,17 +65,27 @@
|
|
|
65
65
|
"typescript": "^5.9.3",
|
|
66
66
|
"vitest": "^4.1.4"
|
|
67
67
|
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@vscode/sqlite3": "5.1.12-vscode",
|
|
70
|
+
"ws": "^8.0.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"@vscode/sqlite3": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"ws": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
68
80
|
"dependencies": {
|
|
69
81
|
"@dangao/logsmith": "0.2.0",
|
|
70
82
|
"@dangao/nacos-client": "0.1.1",
|
|
71
|
-
"@vscode/sqlite3": "5.1.12-vscode",
|
|
72
83
|
"json5": "^2.2.3",
|
|
73
84
|
"jsonc-parser": "^3.3.1",
|
|
74
85
|
"marked": "^18.0.0",
|
|
75
86
|
"mime-types": "^3.0.2",
|
|
76
87
|
"mysql2": "^3.21.0",
|
|
77
88
|
"postgres": "^3.4.9",
|
|
78
|
-
"reflect-metadata": "^0.2.2"
|
|
79
|
-
"ws": "^8.20.0"
|
|
89
|
+
"reflect-metadata": "^0.2.2"
|
|
80
90
|
}
|
|
81
91
|
}
|
|
@@ -185,9 +185,17 @@ export class ConnectionPool {
|
|
|
185
185
|
const { Database } = await import('bun:sqlite');
|
|
186
186
|
return new Database(config.path);
|
|
187
187
|
}
|
|
188
|
-
// Node.js:使用 @vscode/sqlite3
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
// Node.js:使用 @vscode/sqlite3(可选对等依赖,需用户自行安装)
|
|
189
|
+
let sqlite3: any;
|
|
190
|
+
try {
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
192
|
+
sqlite3 = require('@vscode/sqlite3');
|
|
193
|
+
} catch {
|
|
194
|
+
throw new Error(
|
|
195
|
+
'[bun-server] SQLite on Node.js requires @vscode/sqlite3.\n' +
|
|
196
|
+
'Install it with: bun add @vscode/sqlite3@5.1.12-vscode',
|
|
197
|
+
);
|
|
198
|
+
}
|
|
191
199
|
return new sqlite3.Database(config.path);
|
|
192
200
|
}
|
|
193
201
|
|
|
@@ -58,8 +58,16 @@ export class SqliteAdapter {
|
|
|
58
58
|
}
|
|
59
59
|
this.db = db;
|
|
60
60
|
} else {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
let sqlite3: any;
|
|
62
|
+
try {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
64
|
+
sqlite3 = require('@vscode/sqlite3');
|
|
65
|
+
} catch {
|
|
66
|
+
throw new Error(
|
|
67
|
+
'[bun-server] SQLite on Node.js requires @vscode/sqlite3.\n' +
|
|
68
|
+
'Install it with: bun add @vscode/sqlite3@5.1.12-vscode',
|
|
69
|
+
);
|
|
70
|
+
}
|
|
63
71
|
const db: any = new sqlite3.Database(config.database);
|
|
64
72
|
if (config.wal !== false) {
|
|
65
73
|
// Operations are serialized internally; WAL is queued before any query runs
|
|
@@ -168,7 +168,17 @@ function setupWebSocket<T>(
|
|
|
168
168
|
httpServer: import('node:http').Server,
|
|
169
169
|
handlers: WebSocketHandlers<T>,
|
|
170
170
|
): void {
|
|
171
|
-
|
|
171
|
+
let wsModule: typeof import('ws');
|
|
172
|
+
try {
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
174
|
+
wsModule = require('ws');
|
|
175
|
+
} catch {
|
|
176
|
+
throw new Error(
|
|
177
|
+
'[bun-server] WebSocket on Node.js requires the ws package.\n' +
|
|
178
|
+
'Install it with: bun add ws',
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const { WebSocketServer } = wsModule;
|
|
172
182
|
const wss = new WebSocketServer({ noServer: true });
|
|
173
183
|
|
|
174
184
|
httpServer.on('upgrade', (request, socket, head) => {
|