@dangao/bun-server 2.0.3 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/config/config-module.d.ts +3 -0
  2. package/dist/config/config-module.d.ts.map +1 -1
  3. package/dist/core/context.d.ts +10 -0
  4. package/dist/core/context.d.ts.map +1 -1
  5. package/dist/database/service.d.ts +4 -4
  6. package/dist/database/service.d.ts.map +1 -1
  7. package/dist/index.js +232 -93
  8. package/dist/validation/decorators.d.ts.map +1 -1
  9. package/package.json +5 -4
  10. package/src/ai/providers/anthropic-provider.ts +1 -1
  11. package/src/ai/providers/google-provider.ts +1 -1
  12. package/src/ai/providers/ollama-provider.ts +1 -1
  13. package/src/ai/providers/openai-provider.ts +2 -2
  14. package/src/auth/jwt.ts +1 -1
  15. package/src/cache/interceptors.ts +3 -3
  16. package/src/cache/types.ts +10 -10
  17. package/src/client/runtime.ts +1 -1
  18. package/src/config/config-module.ts +46 -14
  19. package/src/config/service.ts +2 -2
  20. package/src/controller/param-binder.ts +1 -1
  21. package/src/conversation/service.ts +1 -1
  22. package/src/core/application.ts +1 -1
  23. package/src/core/cluster.ts +4 -4
  24. package/src/core/context.ts +71 -0
  25. package/src/dashboard/controller.ts +2 -2
  26. package/src/database/connection-manager.ts +4 -4
  27. package/src/database/service.ts +25 -28
  28. package/src/debug/middleware.ts +2 -2
  29. package/src/di/module-registry.ts +1 -1
  30. package/src/error/handler.ts +3 -3
  31. package/src/events/event-module.ts +4 -4
  32. package/src/files/static-middleware.ts +2 -2
  33. package/src/files/storage.ts +1 -1
  34. package/src/interceptor/builtin/log-interceptor.ts +1 -1
  35. package/src/mcp/server.ts +1 -1
  36. package/src/middleware/builtin/error-handler.ts +2 -2
  37. package/src/middleware/builtin/file-upload.ts +1 -1
  38. package/src/middleware/builtin/rate-limit.ts +1 -1
  39. package/src/middleware/builtin/static-file.ts +2 -2
  40. package/src/prompt/stores/file-store.ts +4 -4
  41. package/src/request/body-parser.ts +3 -3
  42. package/src/security/filter.ts +1 -1
  43. package/src/security/guards/guard-registry.ts +1 -1
  44. package/src/session/middleware.ts +1 -1
  45. package/src/session/types.ts +5 -5
  46. package/src/testing/test-client.ts +1 -1
  47. package/src/validation/decorators.ts +70 -2
  48. package/src/validation/rules/common.ts +2 -2
  49. package/tests/config/config-module-extended.test.ts +24 -0
  50. package/tests/core/context.test.ts +52 -0
  51. package/tests/database/database-module.test.ts +87 -0
  52. package/tests/error/error-handler.test.ts +24 -0
  53. package/tests/validation/validation.test.ts +18 -0
package/dist/index.js CHANGED
@@ -941,7 +941,7 @@ class RedisSessionStore {
941
941
  return;
942
942
  }
943
943
  return JSON.parse(value);
944
- } catch {
944
+ } catch (_error) {
945
945
  return;
946
946
  }
947
947
  }
@@ -952,7 +952,7 @@ class RedisSessionStore {
952
952
  PX: maxAge
953
953
  });
954
954
  return true;
955
- } catch {
955
+ } catch (_error) {
956
956
  return false;
957
957
  }
958
958
  }
@@ -960,7 +960,7 @@ class RedisSessionStore {
960
960
  try {
961
961
  await this.client.del(this.getKey(sessionId));
962
962
  return true;
963
- } catch {
963
+ } catch (_error) {
964
964
  return false;
965
965
  }
966
966
  }
@@ -968,7 +968,7 @@ class RedisSessionStore {
968
968
  try {
969
969
  const result = await this.client.exists(this.getKey(sessionId));
970
970
  return result === 1;
971
- } catch {
971
+ } catch (_error) {
972
972
  return false;
973
973
  }
974
974
  }
@@ -985,7 +985,7 @@ class RedisSessionStore {
985
985
  return true;
986
986
  }
987
987
  return false;
988
- } catch {
988
+ } catch (_error) {
989
989
  return false;
990
990
  }
991
991
  }
@@ -1052,7 +1052,7 @@ class ParamBinder {
1052
1052
  context.sessionId = newSession.id;
1053
1053
  return newSession;
1054
1054
  }
1055
- } catch {}
1055
+ } catch (_error) {}
1056
1056
  return;
1057
1057
  case "context" /* CONTEXT */:
1058
1058
  return contextStore.getStore() ?? context;
@@ -1275,7 +1275,7 @@ function createRateLimitMiddleware(options) {
1275
1275
  }
1276
1276
  if (currentCount > max) {
1277
1277
  context.setStatus(statusCode);
1278
- return context.createResponse({
1278
+ return context.createErrorResponse({
1279
1279
  error: message,
1280
1280
  retryAfter: Math.ceil(windowMs / 1000)
1281
1281
  });
@@ -1455,11 +1455,67 @@ function IsNumber(options = {}) {
1455
1455
  };
1456
1456
  }
1457
1457
  function IsEmail(options = {}) {
1458
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1459
1458
  return {
1460
1459
  name: "isEmail",
1461
1460
  message: options.message ?? "\u5FC5\u987B\u662F\u5408\u6CD5\u7684\u90AE\u7BB1\u5730\u5740",
1462
- validate: (value) => typeof value === "string" && emailRegex.test(value)
1461
+ validate: (value) => {
1462
+ if (typeof value !== "string") {
1463
+ return false;
1464
+ }
1465
+ const email = value.trim();
1466
+ if (!email || email.length > 254) {
1467
+ return false;
1468
+ }
1469
+ if (email.includes(" ")) {
1470
+ return false;
1471
+ }
1472
+ const atIndex = email.indexOf("@");
1473
+ if (atIndex <= 0 || atIndex !== email.lastIndexOf("@")) {
1474
+ return false;
1475
+ }
1476
+ const local = email.slice(0, atIndex);
1477
+ const domain = email.slice(atIndex + 1);
1478
+ if (!local || !domain || local.length > 64) {
1479
+ return false;
1480
+ }
1481
+ if (local.startsWith(".") || local.endsWith(".") || local.includes("..")) {
1482
+ return false;
1483
+ }
1484
+ if (domain.startsWith(".") || domain.endsWith(".") || domain.includes("..")) {
1485
+ return false;
1486
+ }
1487
+ if (!domain.includes(".")) {
1488
+ return false;
1489
+ }
1490
+ for (const ch of local) {
1491
+ const code = ch.charCodeAt(0);
1492
+ const isAlphaNum = code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
1493
+ const isAllowedSymbol = "!#$%&'*+/=?^_`{|}~.-".includes(ch);
1494
+ if (!isAlphaNum && !isAllowedSymbol) {
1495
+ return false;
1496
+ }
1497
+ }
1498
+ const labels = domain.split(".");
1499
+ if (labels.length < 2) {
1500
+ return false;
1501
+ }
1502
+ for (const label of labels) {
1503
+ if (!label || label.length > 63) {
1504
+ return false;
1505
+ }
1506
+ if (label.startsWith("-") || label.endsWith("-")) {
1507
+ return false;
1508
+ }
1509
+ for (const ch of label) {
1510
+ const code = ch.charCodeAt(0);
1511
+ const isAlphaNum = code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
1512
+ if (!isAlphaNum && ch !== "-") {
1513
+ return false;
1514
+ }
1515
+ }
1516
+ }
1517
+ return labels[labels.length - 1].length >= 2;
1518
+ }
1463
1519
  };
1464
1520
  }
1465
1521
  function IsOptional() {
@@ -1837,7 +1893,7 @@ function IsUrl(options = {}) {
1837
1893
  try {
1838
1894
  new URL(value);
1839
1895
  return true;
1840
- } catch {
1896
+ } catch (_error) {
1841
1897
  return false;
1842
1898
  }
1843
1899
  }
@@ -1854,7 +1910,7 @@ function IsJSON(options = {}) {
1854
1910
  try {
1855
1911
  JSON.parse(value);
1856
1912
  return true;
1857
- } catch {
1913
+ } catch (_error) {
1858
1914
  return false;
1859
1915
  }
1860
1916
  }
@@ -2516,11 +2572,11 @@ async function handleError(error, context) {
2516
2572
  if (error.details !== undefined) {
2517
2573
  responseBody.details = error.details;
2518
2574
  }
2519
- return context.createResponse(responseBody);
2575
+ return context.createErrorResponse(responseBody);
2520
2576
  }
2521
2577
  if (error instanceof ValidationError) {
2522
2578
  context.setStatus(400);
2523
- return context.createResponse({
2579
+ return context.createErrorResponse({
2524
2580
  error: error.message,
2525
2581
  code: "VALIDATION_FAILED",
2526
2582
  issues: error.issues
@@ -2535,7 +2591,7 @@ async function handleError(error, context) {
2535
2591
  message,
2536
2592
  stack
2537
2593
  });
2538
- return context.createResponse({
2594
+ return context.createErrorResponse({
2539
2595
  error: "Internal Server Error",
2540
2596
  details: message
2541
2597
  });
@@ -2585,7 +2641,7 @@ function createErrorHandlingMiddleware(options = {}) {
2585
2641
  return error;
2586
2642
  }
2587
2643
  if (error instanceof ValidationError) {
2588
- return context.createResponse({
2644
+ return context.createErrorResponse({
2589
2645
  error: error.message,
2590
2646
  issues: error.issues
2591
2647
  }, {
@@ -2599,7 +2655,7 @@ function createErrorHandlingMiddleware(options = {}) {
2599
2655
  return await handleError(error, context);
2600
2656
  }
2601
2657
  if (error instanceof Error) {
2602
- return context.createResponse({
2658
+ return context.createErrorResponse({
2603
2659
  error: error.message
2604
2660
  }, {
2605
2661
  status: defaultStatus
@@ -2705,7 +2761,7 @@ function createFileUploadMiddleware(options = {}) {
2705
2761
  for (const file of fileList) {
2706
2762
  if (file.size > maxSize) {
2707
2763
  context.setStatus(413);
2708
- return context.createResponse({ error: `File ${file.name} exceeds max size` });
2764
+ return context.createErrorResponse({ error: `File ${file.name} exceeds max size` });
2709
2765
  }
2710
2766
  }
2711
2767
  }
@@ -2754,7 +2810,7 @@ function createStaticFileMiddleware(options) {
2754
2810
  const segments = cleanPath.split("/").filter((segment) => segment.length > 0);
2755
2811
  if (segments.some((segment) => segment === "..")) {
2756
2812
  context.setStatus(403);
2757
- return context.createResponse({ error: "Forbidden" });
2813
+ return context.createErrorResponse({ error: "Forbidden" });
2758
2814
  }
2759
2815
  let targetPath = resolve(root, cleanPath);
2760
2816
  if (context.path.endsWith("/") || relativePath === "/") {
@@ -2762,7 +2818,7 @@ function createStaticFileMiddleware(options) {
2762
2818
  }
2763
2819
  if (!isSubPath(root, targetPath)) {
2764
2820
  context.setStatus(403);
2765
- return context.createResponse({ error: "Forbidden" });
2821
+ return context.createErrorResponse({ error: "Forbidden" });
2766
2822
  }
2767
2823
  const file = Bun.file(targetPath);
2768
2824
  if (!await file.exists()) {
@@ -3209,7 +3265,7 @@ var init_log_interceptor = __esm(() => {
3209
3265
  let logger;
3210
3266
  try {
3211
3267
  logger = container.resolve(LOGGER_TOKEN);
3212
- } catch {}
3268
+ } catch (_error) {}
3213
3269
  const log = (msg, data) => {
3214
3270
  if (logger) {
3215
3271
  switch (level) {
@@ -3837,10 +3893,10 @@ class BodyParser {
3837
3893
  }
3838
3894
  try {
3839
3895
  return JSON.parse(text);
3840
- } catch {
3896
+ } catch (_error) {
3841
3897
  return text;
3842
3898
  }
3843
- } catch {
3899
+ } catch (_error) {
3844
3900
  return;
3845
3901
  }
3846
3902
  }
@@ -3850,7 +3906,7 @@ class BodyParser {
3850
3906
  }
3851
3907
  try {
3852
3908
  return JSON.parse(fallbackText);
3853
- } catch {
3909
+ } catch (_error) {
3854
3910
  return fallbackText;
3855
3911
  }
3856
3912
  } catch (error) {
@@ -3888,6 +3944,7 @@ class BodyParser {
3888
3944
  import { URL as URL2 } from "url";
3889
3945
 
3890
3946
  class Context {
3947
+ static ERROR_REDACTED_KEYS = new Set(["stack", "trace", "cause"]);
3891
3948
  request;
3892
3949
  response;
3893
3950
  url;
@@ -3979,6 +4036,57 @@ class Context {
3979
4036
  ...init
3980
4037
  });
3981
4038
  }
4039
+ createErrorResponse(body, init) {
4040
+ const status = init?.status ?? this.statusCode;
4041
+ const errorStatus = status >= 400 ? status : 500;
4042
+ const sanitizedBody = this.sanitizeErrorPayload(body);
4043
+ return this.createResponse(sanitizedBody, {
4044
+ ...init,
4045
+ status: errorStatus
4046
+ });
4047
+ }
4048
+ sanitizeErrorPayload(body) {
4049
+ if (body === undefined || body === null) {
4050
+ return body;
4051
+ }
4052
+ if (body instanceof Error) {
4053
+ return {
4054
+ error: body.message || "Internal Server Error"
4055
+ };
4056
+ }
4057
+ const seen = new WeakSet;
4058
+ return this.sanitizeValue(body, seen);
4059
+ }
4060
+ sanitizeValue(value, seen) {
4061
+ if (value === null || value === undefined) {
4062
+ return value;
4063
+ }
4064
+ if (typeof value !== "object") {
4065
+ return value;
4066
+ }
4067
+ if (value instanceof Date || value instanceof ArrayBuffer || value instanceof Blob) {
4068
+ return value;
4069
+ }
4070
+ if (seen.has(value)) {
4071
+ return "[Circular]";
4072
+ }
4073
+ seen.add(value);
4074
+ if (Array.isArray(value)) {
4075
+ return value.map((item) => this.sanitizeValue(item, seen));
4076
+ }
4077
+ const prototype = Object.getPrototypeOf(value);
4078
+ if (prototype !== Object.prototype && prototype !== null) {
4079
+ return value;
4080
+ }
4081
+ const sanitized = {};
4082
+ for (const [key, nestedValue] of Object.entries(value)) {
4083
+ if (Context.ERROR_REDACTED_KEYS.has(key)) {
4084
+ continue;
4085
+ }
4086
+ sanitized[key] = this.sanitizeValue(nestedValue, seen);
4087
+ }
4088
+ return sanitized;
4089
+ }
3982
4090
  }
3983
4091
 
3984
4092
  // src/core/server.ts
@@ -4594,7 +4702,7 @@ class ModuleRegistry {
4594
4702
  } else if ("useFactory" in provider) {
4595
4703
  instances.push(ref.container.resolve(provider.provide));
4596
4704
  }
4597
- } catch {}
4705
+ } catch (_error) {}
4598
4706
  }
4599
4707
  }
4600
4708
  return instances;
@@ -4731,10 +4839,10 @@ class ConfigService {
4731
4839
  }
4732
4840
  try {
4733
4841
  return JSON.parse(content);
4734
- } catch {
4842
+ } catch (_error) {
4735
4843
  try {
4736
4844
  return Bun.JSONC.parse(content);
4737
- } catch {
4845
+ } catch (_innerError) {
4738
4846
  return Bun.JSON5.parse(content);
4739
4847
  }
4740
4848
  }
@@ -4842,6 +4950,21 @@ class ConfigService {
4842
4950
 
4843
4951
  // src/config/config-module.ts
4844
4952
  class ConfigModule {
4953
+ static DANGEROUS_PATH_SEGMENTS = new Set([
4954
+ "__proto__",
4955
+ "prototype",
4956
+ "constructor"
4957
+ ]);
4958
+ static isPlainObject(value) {
4959
+ if (typeof value !== "object" || value === null) {
4960
+ return false;
4961
+ }
4962
+ const proto = Object.getPrototypeOf(value);
4963
+ return proto === null || proto === Object.prototype;
4964
+ }
4965
+ static createSafeContainer() {
4966
+ return Object.create(null);
4967
+ }
4845
4968
  static forRoot(options = {}) {
4846
4969
  const providers = [];
4847
4970
  const env = ConfigModule.snapshotEnv();
@@ -4952,7 +5075,7 @@ class ConfigModule {
4952
5075
  try {
4953
5076
  const parsed = ConfigService.parseConfigContent(result.content);
4954
5077
  ConfigModule.setValueByPath(configMap, configPath, parsed);
4955
- } catch {
5078
+ } catch (_error) {
4956
5079
  ConfigModule.setValueByPath(configMap, configPath, result.content);
4957
5080
  }
4958
5081
  }).catch((error) => {
@@ -4979,7 +5102,7 @@ class ConfigModule {
4979
5102
  let parsedValue;
4980
5103
  try {
4981
5104
  parsedValue = ConfigService.parseConfigContent(result.content);
4982
- } catch {
5105
+ } catch (_error) {
4983
5106
  parsedValue = result.content;
4984
5107
  }
4985
5108
  const currentConfig = service.getAll();
@@ -4999,16 +5122,30 @@ class ConfigModule {
4999
5122
  }
5000
5123
  }
5001
5124
  static setValueByPath(obj, path, value) {
5002
- const segments = path.split(".");
5125
+ const normalizedSegments = path.split(".").map((segment) => segment.trim());
5126
+ if (normalizedSegments.length === 0 || normalizedSegments.some((segment) => !segment)) {
5127
+ throw new Error(`[ConfigModule] Invalid config path: "${path}"`);
5128
+ }
5129
+ for (const segment of normalizedSegments) {
5130
+ if (ConfigModule.DANGEROUS_PATH_SEGMENTS.has(segment)) {
5131
+ throw new Error(`[ConfigModule] Unsafe config path segment: "${segment}"`);
5132
+ }
5133
+ }
5003
5134
  let current = obj;
5004
- for (let i = 0;i < segments.length - 1; i++) {
5005
- const segment = segments[i];
5006
- if (!(segment in current) || current[segment] == null || typeof current[segment] !== "object") {
5007
- current[segment] = {};
5135
+ for (let i = 0;i < normalizedSegments.length - 1; i++) {
5136
+ const segment = normalizedSegments[i];
5137
+ const hasOwn = Object.prototype.hasOwnProperty.call(current, segment);
5138
+ const existing = hasOwn ? current[segment] : undefined;
5139
+ if (!ConfigModule.isPlainObject(existing)) {
5140
+ current[segment] = ConfigModule.createSafeContainer();
5008
5141
  }
5009
5142
  current = current[segment];
5010
5143
  }
5011
- current[segments[segments.length - 1]] = value;
5144
+ const lastSegment = normalizedSegments[normalizedSegments.length - 1];
5145
+ if (ConfigModule.DANGEROUS_PATH_SEGMENTS.has(lastSegment)) {
5146
+ throw new Error(`[ConfigModule] Unsafe config path segment: "${lastSegment}"`);
5147
+ }
5148
+ current[lastSegment] = value;
5012
5149
  }
5013
5150
  }
5014
5151
  ConfigModule = __legacyDecorateClassTS([
@@ -5133,7 +5270,7 @@ class RedisCacheStore {
5133
5270
  }
5134
5271
  try {
5135
5272
  return JSON.parse(value);
5136
- } catch {
5273
+ } catch (_error) {
5137
5274
  return;
5138
5275
  }
5139
5276
  }
@@ -5146,7 +5283,7 @@ class RedisCacheStore {
5146
5283
  await this.client.set(this.getKey(key), serialized);
5147
5284
  }
5148
5285
  return true;
5149
- } catch {
5286
+ } catch (_error) {
5150
5287
  return false;
5151
5288
  }
5152
5289
  }
@@ -5154,7 +5291,7 @@ class RedisCacheStore {
5154
5291
  try {
5155
5292
  await this.client.del(this.getKey(key));
5156
5293
  return true;
5157
- } catch {
5294
+ } catch (_error) {
5158
5295
  return false;
5159
5296
  }
5160
5297
  }
@@ -5162,7 +5299,7 @@ class RedisCacheStore {
5162
5299
  try {
5163
5300
  const result = await this.client.exists(this.getKey(key));
5164
5301
  return result === 1;
5165
- } catch {
5302
+ } catch (_error) {
5166
5303
  return false;
5167
5304
  }
5168
5305
  }
@@ -5170,7 +5307,7 @@ class RedisCacheStore {
5170
5307
  try {
5171
5308
  await this.client.flushdb();
5172
5309
  return true;
5173
- } catch {
5310
+ } catch (_error) {
5174
5311
  return false;
5175
5312
  }
5176
5313
  }
@@ -5187,10 +5324,10 @@ class RedisCacheStore {
5187
5324
  if (value !== null) {
5188
5325
  try {
5189
5326
  result.set(keys[i], JSON.parse(value));
5190
- } catch {}
5327
+ } catch (_error) {}
5191
5328
  }
5192
5329
  }
5193
- } catch {}
5330
+ } catch (_error) {}
5194
5331
  return result;
5195
5332
  }
5196
5333
  async setMany(entries, ttl) {
@@ -5209,7 +5346,7 @@ class RedisCacheStore {
5209
5346
  }
5210
5347
  }
5211
5348
  return true;
5212
- } catch {
5349
+ } catch (_error) {
5213
5350
  return false;
5214
5351
  }
5215
5352
  }
@@ -5224,10 +5361,10 @@ class RedisCacheStore {
5224
5361
  try {
5225
5362
  await this.client.del(key);
5226
5363
  deleted.push(key.replace(this.keyPrefix, ""));
5227
- } catch {}
5364
+ } catch (_error) {}
5228
5365
  }
5229
5366
  return deleted;
5230
- } catch {
5367
+ } catch (_error) {
5231
5368
  return [];
5232
5369
  }
5233
5370
  }
@@ -5406,7 +5543,7 @@ class CacheableInterceptor extends BaseInterceptor {
5406
5543
  let cacheService;
5407
5544
  try {
5408
5545
  cacheService = container.resolve(CACHE_SERVICE_TOKEN);
5409
- } catch {
5546
+ } catch (_error) {
5410
5547
  console.warn("[CacheableInterceptor] CacheService not registered, skipping cache");
5411
5548
  return await Promise.resolve(originalMethod.apply(target, args));
5412
5549
  }
@@ -5441,7 +5578,7 @@ class CacheEvictInterceptor extends BaseInterceptor {
5441
5578
  let cacheService;
5442
5579
  try {
5443
5580
  cacheService = container.resolve(CACHE_SERVICE_TOKEN);
5444
- } catch {
5581
+ } catch (_error) {
5445
5582
  console.warn("[CacheEvictInterceptor] CacheService not registered, skipping cache eviction");
5446
5583
  return await Promise.resolve(originalMethod.apply(target, args));
5447
5584
  }
@@ -5483,7 +5620,7 @@ class CachePutInterceptor extends BaseInterceptor {
5483
5620
  let cacheService;
5484
5621
  try {
5485
5622
  cacheService = container.resolve(CACHE_SERVICE_TOKEN);
5486
- } catch {
5623
+ } catch (_error) {
5487
5624
  console.warn("[CachePutInterceptor] CacheService not registered, skipping cache update");
5488
5625
  return await Promise.resolve(originalMethod.apply(target, args));
5489
5626
  }
@@ -5970,7 +6107,7 @@ class EventModule {
5970
6107
  if (eventModuleRef) {
5971
6108
  try {
5972
6109
  eventEmitter = eventModuleRef.container.resolve(EVENT_EMITTER_TOKEN);
5973
- } catch {}
6110
+ } catch (_error) {}
5974
6111
  }
5975
6112
  if (!eventEmitter) {
5976
6113
  console.warn("[EventModule] EventEmitter not found. Make sure EventModule.forRoot() is called and the module is registered.");
@@ -5994,12 +6131,12 @@ class EventModule {
5994
6131
  if (moduleRef) {
5995
6132
  try {
5996
6133
  return moduleRef.container.resolve(EVENT_EMITTER_TOKEN);
5997
- } catch {}
6134
+ } catch (_error) {}
5998
6135
  }
5999
6136
  if (container) {
6000
6137
  try {
6001
6138
  return container.resolve(EVENT_EMITTER_TOKEN);
6002
- } catch {}
6139
+ } catch (_error) {}
6003
6140
  }
6004
6141
  return;
6005
6142
  }
@@ -6015,7 +6152,7 @@ class EventModule {
6015
6152
  let eventEmitter;
6016
6153
  try {
6017
6154
  eventEmitter = eventModuleRef.container.resolve(EVENT_EMITTER_TOKEN);
6018
- } catch {
6155
+ } catch (_error) {
6019
6156
  return false;
6020
6157
  }
6021
6158
  if (!eventEmitter) {
@@ -6215,7 +6352,7 @@ class Application {
6215
6352
  path: context.path
6216
6353
  });
6217
6354
  context.setStatus(404);
6218
- return context.createResponse({ error: "Not Found" });
6355
+ return context.createErrorResponse({ error: "Not Found" });
6219
6356
  });
6220
6357
  });
6221
6358
  }
@@ -6393,7 +6530,7 @@ class ClusterManager {
6393
6530
  if (this.socketDir) {
6394
6531
  try {
6395
6532
  rmSync(this.socketDir, { recursive: true, force: true });
6396
- } catch {}
6533
+ } catch (_error) {}
6397
6534
  this.socketDir = undefined;
6398
6535
  }
6399
6536
  logger.info("[Cluster] All workers stopped");
@@ -6440,7 +6577,7 @@ class ClusterManager {
6440
6577
  this.socketDir = join(tmpdir(), `bun-cluster-${process.pid}`);
6441
6578
  try {
6442
6579
  rmSync(this.socketDir, { recursive: true, force: true });
6443
- } catch {}
6580
+ } catch (_error) {}
6444
6581
  mkdirSync(this.socketDir, { recursive: true });
6445
6582
  this.socketPaths = [];
6446
6583
  for (let i = 0;i < this.workerCount; i++) {
@@ -6506,7 +6643,7 @@ class ClusterManager {
6506
6643
  redirect: "manual",
6507
6644
  unix: socketPath
6508
6645
  });
6509
- } catch {
6646
+ } catch (_error) {
6510
6647
  return new Response("Bad Gateway", { status: 502 });
6511
6648
  }
6512
6649
  }
@@ -6522,7 +6659,7 @@ class ClusterManager {
6522
6659
  const socketPath = this.socketPaths[index];
6523
6660
  try {
6524
6661
  rmSync(socketPath);
6525
- } catch {}
6662
+ } catch (_error) {}
6526
6663
  this.workers[index] = this.spawnProxyWorker(index, socketPath);
6527
6664
  const deadline = Date.now() + 15000;
6528
6665
  while (Date.now() < deadline) {
@@ -7317,7 +7454,7 @@ class GuardRegistry {
7317
7454
  this.guardInstances.set(guard, instance2);
7318
7455
  return instance2;
7319
7456
  }
7320
- } catch {}
7457
+ } catch (_error) {}
7321
7458
  const GuardClass = guard;
7322
7459
  const instance = new GuardClass;
7323
7460
  this.guardInstances.set(guard, instance);
@@ -7485,7 +7622,7 @@ function createSecurityFilter(config) {
7485
7622
  const { ControllerRegistry: ControllerRegistry2 } = (init_controller(), __toCommonJS(exports_controller));
7486
7623
  cachedContainer = ControllerRegistry2.getInstance().getContainer();
7487
7624
  return cachedContainer;
7488
- } catch {
7625
+ } catch (_error) {
7489
7626
  return null;
7490
7627
  }
7491
7628
  };
@@ -7706,7 +7843,7 @@ class JWTUtil {
7706
7843
  return null;
7707
7844
  }
7708
7845
  return payload;
7709
- } catch {
7846
+ } catch (_error) {
7710
7847
  return null;
7711
7848
  }
7712
7849
  }
@@ -8569,7 +8706,7 @@ class DashboardService {
8569
8706
  const decoded = atob(authHeader.slice(6));
8570
8707
  const [username, password] = decoded.split(":");
8571
8708
  return username === this.auth.username && password === this.auth.password;
8572
- } catch {
8709
+ } catch (_error) {
8573
8710
  return false;
8574
8711
  }
8575
8712
  }
@@ -8678,7 +8815,7 @@ class DashboardService {
8678
8815
  return new Response(JSON.stringify(data), {
8679
8816
  headers: { "Content-Type": "application/json; charset=utf-8" }
8680
8817
  });
8681
- } catch {
8818
+ } catch (_error) {
8682
8819
  const data = {
8683
8820
  status: "up",
8684
8821
  timestamp: Date.now()
@@ -9712,7 +9849,7 @@ class DatabaseConnectionManager {
9712
9849
  return await this.healthCheckMysql(this.currentConnection);
9713
9850
  }
9714
9851
  return false;
9715
- } catch {
9852
+ } catch (_error) {
9716
9853
  return false;
9717
9854
  }
9718
9855
  }
@@ -9746,7 +9883,7 @@ class DatabaseConnectionManager {
9746
9883
  return true;
9747
9884
  }
9748
9885
  return false;
9749
- } catch {
9886
+ } catch (_error) {
9750
9887
  return false;
9751
9888
  }
9752
9889
  }
@@ -9761,7 +9898,7 @@ class DatabaseConnectionManager {
9761
9898
  return true;
9762
9899
  }
9763
9900
  return false;
9764
- } catch {
9901
+ } catch (_error) {
9765
9902
  return false;
9766
9903
  }
9767
9904
  }
@@ -9776,7 +9913,7 @@ class DatabaseConnectionManager {
9776
9913
  return true;
9777
9914
  }
9778
9915
  return false;
9779
- } catch {
9916
+ } catch (_error) {
9780
9917
  return false;
9781
9918
  }
9782
9919
  }
@@ -9845,11 +9982,15 @@ class DatabaseService2 {
9845
9982
  async queryBunSQL(connection, sql, params) {
9846
9983
  if (connection && typeof connection === "function") {
9847
9984
  try {
9848
- const sqlWithParams = this.interpolateParams(sql, params);
9849
- const result = await connection`${sqlWithParams}`;
9985
+ const { strings, values } = this.buildTemplateFromSql(sql, params);
9986
+ const template = Object.assign(strings, {
9987
+ raw: strings
9988
+ });
9989
+ const result = await connection(template, ...values);
9850
9990
  return result;
9851
- } catch {
9852
- throw new Error("Bun.SQL parameterized queries are not fully supported. Consider using template string queries.");
9991
+ } catch (error) {
9992
+ const errorMessage = error instanceof Error ? error.message : String(error);
9993
+ throw new Error(`Bun.SQL parameterized queries are not fully supported. Consider using template string queries. Original error: ${errorMessage}`);
9853
9994
  }
9854
9995
  }
9855
9996
  if (connection && typeof connection === "object" && "query" in connection && typeof connection.query === "function") {
@@ -9859,17 +10000,15 @@ class DatabaseService2 {
9859
10000
  }
9860
10001
  throw new Error("Invalid Bun.SQL connection");
9861
10002
  }
9862
- interpolateParams(sql, params) {
10003
+ buildTemplateFromSql(sql, params) {
9863
10004
  if (!params || params.length === 0) {
9864
- return sql;
10005
+ return { strings: [sql], values: [] };
9865
10006
  }
9866
- let result = sql;
9867
- for (let i = 0;i < params.length; i++) {
9868
- const param = params[i];
9869
- const value = typeof param === "string" ? `'${param.replace(/'/g, "''")}'` : String(param);
9870
- result = result.replace("?", value);
10007
+ const strings = sql.split("?");
10008
+ if (strings.length !== params.length + 1) {
10009
+ throw new Error("SQL placeholders count does not match parameters count");
9871
10010
  }
9872
- return result;
10011
+ return { strings, values: params };
9873
10012
  }
9874
10013
  }
9875
10014
  DatabaseService2 = __legacyDecorateClassTS([
@@ -10216,7 +10355,7 @@ function createDebugMiddleware(recorder, options = {}) {
10216
10355
  if (recordBody && ["POST", "PUT", "PATCH"].includes(context2.method)) {
10217
10356
  try {
10218
10357
  requestBody = await context2.getBody();
10219
- } catch {
10358
+ } catch (_error) {
10220
10359
  requestBody = undefined;
10221
10360
  }
10222
10361
  }
@@ -10237,7 +10376,7 @@ function createDebugMiddleware(recorder, options = {}) {
10237
10376
  if (route) {
10238
10377
  matchedRoute = route.path;
10239
10378
  }
10240
- } catch {
10379
+ } catch (_error) {
10241
10380
  matchedRoute = undefined;
10242
10381
  }
10243
10382
  const record = {
@@ -10898,7 +11037,7 @@ class TestHttpClient {
10898
11037
  let body;
10899
11038
  try {
10900
11039
  body = JSON.parse(text);
10901
- } catch {
11040
+ } catch (_error) {
10902
11041
  body = text;
10903
11042
  }
10904
11043
  return {
@@ -11126,7 +11265,7 @@ function createClient(manifest, config) {
11126
11265
  const text = await response.text();
11127
11266
  try {
11128
11267
  return JSON.parse(text);
11129
- } catch {
11268
+ } catch (_error) {
11130
11269
  return text;
11131
11270
  }
11132
11271
  };
@@ -11594,7 +11733,7 @@ function createSessionMiddleware(container) {
11594
11733
  let sessionService;
11595
11734
  try {
11596
11735
  sessionService = container.resolve(SESSION_SERVICE_TOKEN);
11597
- } catch {
11736
+ } catch (_error) {
11598
11737
  return await next();
11599
11738
  }
11600
11739
  if (!sessionService) {
@@ -13452,7 +13591,7 @@ class OpenAIProvider {
13452
13591
  controller2.enqueue(encoder.encode(`data: ${JSON.stringify(chunk)}
13453
13592
 
13454
13593
  `));
13455
- } catch {}
13594
+ } catch (_error) {}
13456
13595
  }
13457
13596
  }
13458
13597
  }
@@ -13504,7 +13643,7 @@ class OpenAIProvider {
13504
13643
  return parsed;
13505
13644
  }
13506
13645
  return {};
13507
- } catch {
13646
+ } catch (_error) {
13508
13647
  return {};
13509
13648
  }
13510
13649
  }
@@ -13643,7 +13782,7 @@ class AnthropicProvider {
13643
13782
 
13644
13783
  `));
13645
13784
  }
13646
- } catch {}
13785
+ } catch (_error) {}
13647
13786
  }
13648
13787
  }
13649
13788
  }
@@ -13770,7 +13909,7 @@ class OllamaProvider {
13770
13909
  controller2.enqueue(encoder.encode(`data: ${JSON.stringify({ content: msgContent, done: isDone })}
13771
13910
 
13772
13911
  `));
13773
- } catch {}
13912
+ } catch (_error) {}
13774
13913
  }
13775
13914
  }
13776
13915
  } catch (err) {
@@ -13907,7 +14046,7 @@ class GoogleProvider {
13907
14046
  controller2.enqueue(encoder.encode(`data: ${JSON.stringify({ content: text, done: false })}
13908
14047
 
13909
14048
  `));
13910
- } catch {}
14049
+ } catch (_error) {}
13911
14050
  }
13912
14051
  }
13913
14052
  }
@@ -14018,7 +14157,7 @@ class ConversationService {
14018
14157
  for (const msg of newMessages) {
14019
14158
  await this.store.appendMessage(id, msg);
14020
14159
  }
14021
- } catch {
14160
+ } catch (_error) {
14022
14161
  await this.store.trim(id, this.maxMessages);
14023
14162
  }
14024
14163
  }
@@ -14474,7 +14613,7 @@ class FilePromptStore {
14474
14613
  try {
14475
14614
  const path = `${this.promptsDir}/${id}.json`;
14476
14615
  await Bun.file(path).exists() && Bun.write(path, "");
14477
- } catch {}
14616
+ } catch (_error) {}
14478
14617
  }
14479
14618
  return deleted;
14480
14619
  }
@@ -14493,9 +14632,9 @@ class FilePromptStore {
14493
14632
  const data = JSON.parse(content);
14494
14633
  const id = data.id ?? file.replace(/\.json$/, "");
14495
14634
  await this.memory.create({ id, ...data }).catch(() => {});
14496
- } catch {}
14635
+ } catch (_error) {}
14497
14636
  }
14498
- } catch {}
14637
+ } catch (_error) {}
14499
14638
  }
14500
14639
  async writeFile(template) {
14501
14640
  try {
@@ -14507,7 +14646,7 @@ class FilePromptStore {
14507
14646
  variables: extractVariables(template.content)
14508
14647
  }, null, 2);
14509
14648
  await Bun.write(`${this.promptsDir}/${template.id}.json`, content);
14510
- } catch {}
14649
+ } catch (_error) {}
14511
14650
  }
14512
14651
  }
14513
14652
  // src/embedding/types.ts
@@ -15259,7 +15398,7 @@ data: ${JSON.stringify({
15259
15398
  controller2.enqueue(encoder.encode(`: ping
15260
15399
 
15261
15400
  `));
15262
- } catch {
15401
+ } catch (_error) {
15263
15402
  clearInterval(pingInterval);
15264
15403
  }
15265
15404
  }, 15000);