@gravito/core 2.0.6 → 3.0.1

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 (72) hide show
  1. package/README.md +64 -25
  2. package/dist/Application.d.ts +2 -9
  3. package/dist/Container.d.ts +18 -1
  4. package/dist/GravitoServer.d.ts +8 -8
  5. package/dist/HookManager.d.ts +36 -34
  6. package/dist/PlanetCore.d.ts +54 -0
  7. package/dist/Route.d.ts +5 -0
  8. package/dist/Router.d.ts +14 -1
  9. package/dist/adapters/bun/BunContext.d.ts +1 -1
  10. package/dist/adapters/bun/BunNativeAdapter.d.ts +11 -1
  11. package/dist/adapters/bun/FastPathRegistry.d.ts +31 -0
  12. package/dist/adapters/bun/RadixNode.d.ts +4 -3
  13. package/dist/adapters/bun/RadixRouter.d.ts +2 -2
  14. package/dist/adapters/bun/types.d.ts +7 -0
  15. package/dist/adapters/types.d.ts +20 -0
  16. package/dist/compat/async-local-storage.d.ts +5 -1
  17. package/dist/compat/async-local-storage.js.map +2 -2
  18. package/dist/compat/crypto.d.ts +6 -1
  19. package/dist/compat/crypto.js.map +2 -2
  20. package/dist/engine/AOTRouter.d.ts +1 -1
  21. package/dist/engine/FastContext.d.ts +4 -4
  22. package/dist/engine/MinimalContext.d.ts +3 -3
  23. package/dist/engine/index.js +29 -8
  24. package/dist/engine/index.js.map +10 -10
  25. package/dist/engine/types.d.ts +5 -5
  26. package/dist/events/CircuitBreaker.d.ts +12 -0
  27. package/dist/events/MessageQueueBridge.d.ts +2 -1
  28. package/dist/events/observability/EventMetrics.d.ts +1 -2
  29. package/dist/events/observability/ObservableHookManager.d.ts +1 -1
  30. package/dist/exceptions/AuthException.d.ts +19 -0
  31. package/dist/exceptions/AuthenticationException.d.ts +9 -3
  32. package/dist/exceptions/AuthorizationException.d.ts +2 -2
  33. package/dist/exceptions/CacheException.d.ts +9 -0
  34. package/dist/exceptions/CircularDependencyException.d.ts +2 -1
  35. package/dist/exceptions/ConfigurationException.d.ts +9 -0
  36. package/dist/exceptions/ContainerBindingCollisionException.d.ts +10 -0
  37. package/dist/exceptions/DatabaseException.d.ts +9 -0
  38. package/dist/exceptions/DomainException.d.ts +9 -0
  39. package/dist/exceptions/InfrastructureException.d.ts +17 -0
  40. package/dist/exceptions/MiddlewareDriftException.d.ts +10 -0
  41. package/dist/exceptions/QueueException.d.ts +9 -0
  42. package/dist/exceptions/StorageException.d.ts +9 -0
  43. package/dist/exceptions/StreamException.d.ts +9 -0
  44. package/dist/exceptions/SystemException.d.ts +9 -0
  45. package/dist/exceptions/ValidationException.d.ts +2 -2
  46. package/dist/exceptions/index.d.ts +12 -0
  47. package/dist/ffi/NativeAccelerator.js.map +3 -3
  48. package/dist/ffi/NativeHasher.d.ts +14 -0
  49. package/dist/ffi/NativeHasher.js +24 -1
  50. package/dist/ffi/NativeHasher.js.map +4 -4
  51. package/dist/ffi/cbor-fallback.js.map +1 -1
  52. package/dist/ffi/hash-fallback.d.ts +15 -0
  53. package/dist/ffi/hash-fallback.js +12 -1
  54. package/dist/ffi/hash-fallback.js.map +3 -3
  55. package/dist/ffi/types.d.ts +13 -0
  56. package/dist/ffi/types.js.map +1 -1
  57. package/dist/hooks/types.d.ts +7 -3
  58. package/dist/http/types.d.ts +2 -2
  59. package/dist/index.browser.d.ts +5 -5
  60. package/dist/index.browser.js +190 -47
  61. package/dist/index.browser.js.map +50 -46
  62. package/dist/index.d.ts +17 -7
  63. package/dist/index.js +613 -202
  64. package/dist/index.js.map +82 -68
  65. package/dist/runtime/NativeOrbitDetector.d.ts +59 -0
  66. package/dist/runtime/index.browser.d.ts +1 -1
  67. package/dist/runtime/index.d.ts +7 -0
  68. package/dist/runtime.d.ts +1 -1
  69. package/dist/testing/HttpTester.d.ts +4 -4
  70. package/dist/testing/TestResponse.d.ts +4 -4
  71. package/dist/types.d.ts +3 -3
  72. package/package.json +4 -3
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/ffi/types.ts", "../src/ffi/cbor-fallback.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * FFI (Foreign Function Interface) 類型定義\n * 支持 bun:ffi 的原生加速層\n */\n\n/**\n * CBOR 編碼/解碼加速器介面\n * 可由原生 C 實現或 JavaScript 回退實現\n */\nexport interface CborAccelerator {\n /**\n * 將任意 JavaScript 物件編碼為 CBOR 二進制格式\n * @param data - 要編碼的物件(支援:map、string、uint、float64、bytes、null、boolean)\n * @returns CBOR 編碼的二進制資料\n */\n encode(data: Record<string, unknown>): Uint8Array\n\n /**\n * 將 CBOR 二進制格式解碼為 JavaScript 物件\n * @param bytes - CBOR 編碼的二進制資料\n * @returns 解碼後的物件\n */\n decode(bytes: Uint8Array): Record<string, unknown>\n}\n\n/**\n * FFI 加速層狀態報告\n */\nexport interface NativeAcceleratorStatus {\n /**\n * 原生 FFI 加速是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-ffi': Bun C 編譯器(bun:ffi 的 cc())\n * - 'js-fallback': 手寫 JavaScript CBOR 實現\n * - 'cborg': npm 的 cborg 套件(已棄用,僅用於向後相容)\n */\n readonly runtime: 'bun-ffi' | 'js-fallback' | 'cborg'\n\n /**\n * 運行時版本或詳細資訊\n */\n readonly version: string\n}\n\n/**\n * FFI 層配置選項\n */\nexport interface FfiConfig {\n /**\n * 啟用調試日誌\n * @default false\n */\n readonly debug?: boolean\n\n /**\n * 最大 buffer 大小(位元組)\n * @default 1048576 (1MB)\n */\n readonly maxBufferSize?: number\n\n /**\n * 強制使用特定的加速器實現\n * - undefined: 自動選擇(優先 bun-ffi,降級到 js-fallback)\n * - 'bun-ffi': 只使用原生 C 實現\n * - 'js-fallback': 只使用 JavaScript 實現\n */\n readonly forceImplementation?: 'bun-ffi' | 'js-fallback'\n}\n\n/**\n * CBOR Major Type 常數\n * 符合 RFC 7049 規範\n */\nexport const CBOR_MAJOR_TYPES = {\n UINT: 0, // 正整數 (0 to 2^64-1)\n NEGINT: 1, // 負整數 (-1 to -2^64)\n BYTES: 2, // 位元組字串\n TEXT: 3, // 文字字串\n ARRAY: 4, // 陣列\n MAP: 5, // Map 物件\n TAG: 6, // 語意 tag\n SIMPLE: 7, // 簡單值與浮點數\n} as const\n\n/**\n * CBOR 簡單值常數\n */\nexport const CBOR_SIMPLE_VALUES = {\n FALSE: 20, // Boolean false\n TRUE: 21, // Boolean true\n NULL: 22, // null\n UNDEFINED: 23, // undefined (不常用)\n} as const\n\n/**\n * CBOR 長度編碼的附加資訊\n */\nexport const CBOR_LENGTH_ENCODING = {\n SMALL_RANGE_END: 23, // 0-23: 直接作為值\n UINT8: 24, // 24: 接下來 1 byte 為 uint8_t\n UINT16: 25, // 25: 接下來 2 bytes 為 uint16_t (大端序)\n UINT32: 26, // 26: 接下來 4 bytes 為 uint32_t (大端序)\n UINT64: 27, // 27: 接下來 8 bytes 為 uint64_t (大端序)\n FLOAT16: 25, // 25: IEEE 754 半精度浮點數 (special case for SIMPLE)\n FLOAT32: 26, // 26: IEEE 754 單精度浮點數\n FLOAT64: 27, // 27: IEEE 754 雙精度浮點數\n INDEFINITE: 31, // 31: 無限長度編碼\n} as const\n\n/**\n * 雜湊加速器介面\n * 可由 Bun 原生實現或 Node.js 回退實現\n */\nexport interface HashAccelerator {\n /**\n * SHA-256 雜湊計算\n * @param input - 輸入(字串或二進制)\n * @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)\n */\n sha256(input: string | Uint8Array): string\n\n /**\n * HMAC-SHA256 計算\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)\n */\n hmacSha256(key: string, data: string): string\n}\n\n/**\n * 雜湊加速器狀態報告\n */\nexport interface NativeHasherStatus {\n /**\n * 雜湊加速層是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-crypto-hasher': Bun 原生 CryptoHasher(C 實現,推薦)\n * - 'node-crypto': node:crypto 回退實現\n */\n readonly runtime: 'bun-crypto-hasher' | 'node-crypto'\n}\n",
5
+ "/**\n * FFI (Foreign Function Interface) 類型定義\n * 支持 bun:ffi 的原生加速層\n */\n\n/**\n * CBOR 編碼/解碼加速器介面\n * 可由原生 C 實現或 JavaScript 回退實現\n */\nexport interface CborAccelerator {\n /**\n * 將任意 JavaScript 物件編碼為 CBOR 二進制格式\n * @param data - 要編碼的物件(支援:map、string、uint、float64、bytes、null、boolean)\n * @returns CBOR 編碼的二進制資料\n */\n encode(data: Record<string, unknown>): Uint8Array\n\n /**\n * 將 CBOR 二進制格式解碼為 JavaScript 物件\n * @param bytes - CBOR 編碼的二進制資料\n * @returns 解碼後的物件\n */\n decode(bytes: Uint8Array): Record<string, unknown>\n}\n\n/**\n * FFI 加速層狀態報告\n */\nexport interface NativeAcceleratorStatus {\n /**\n * 原生 FFI 加速是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-ffi': Bun C 編譯器(bun:ffi 的 cc())\n * - 'js-fallback': 手寫 JavaScript CBOR 實現\n * - 'cborg': npm 的 cborg 套件(已棄用,僅用於向後相容)\n */\n readonly runtime: 'bun-ffi' | 'js-fallback' | 'cborg'\n\n /**\n * 運行時版本或詳細資訊\n */\n readonly version: string\n}\n\n/**\n * FFI 層配置選項\n */\nexport interface FfiConfig {\n /**\n * 啟用調試日誌\n * @default false\n */\n readonly debug?: boolean\n\n /**\n * 最大 buffer 大小(位元組)\n * @default 1048576 (1MB)\n */\n readonly maxBufferSize?: number\n\n /**\n * 強制使用特定的加速器實現\n * - undefined: 自動選擇(優先 bun-ffi,降級到 js-fallback)\n * - 'bun-ffi': 只使用原生 C 實現\n * - 'js-fallback': 只使用 JavaScript 實現\n */\n readonly forceImplementation?: 'bun-ffi' | 'js-fallback'\n}\n\n/**\n * CBOR Major Type 常數\n * 符合 RFC 7049 規範\n */\nexport const CBOR_MAJOR_TYPES = {\n UINT: 0, // 正整數 (0 to 2^64-1)\n NEGINT: 1, // 負整數 (-1 to -2^64)\n BYTES: 2, // 位元組字串\n TEXT: 3, // 文字字串\n ARRAY: 4, // 陣列\n MAP: 5, // Map 物件\n TAG: 6, // 語意 tag\n SIMPLE: 7, // 簡單值與浮點數\n} as const\n\n/**\n * CBOR 簡單值常數\n */\nexport const CBOR_SIMPLE_VALUES = {\n FALSE: 20, // Boolean false\n TRUE: 21, // Boolean true\n NULL: 22, // null\n UNDEFINED: 23, // undefined (不常用)\n} as const\n\n/**\n * CBOR 長度編碼的附加資訊\n */\nexport const CBOR_LENGTH_ENCODING = {\n SMALL_RANGE_END: 23, // 0-23: 直接作為值\n UINT8: 24, // 24: 接下來 1 byte 為 uint8_t\n UINT16: 25, // 25: 接下來 2 bytes 為 uint16_t (大端序)\n UINT32: 26, // 26: 接下來 4 bytes 為 uint32_t (大端序)\n UINT64: 27, // 27: 接下來 8 bytes 為 uint64_t (大端序)\n FLOAT16: 25, // 25: IEEE 754 半精度浮點數 (special case for SIMPLE)\n FLOAT32: 26, // 26: IEEE 754 單精度浮點數\n FLOAT64: 27, // 27: IEEE 754 雙精度浮點數\n INDEFINITE: 31, // 31: 無限長度編碼\n} as const\n\n/**\n * 雜湊加速器介面\n * 可由 Bun 原生實現或 Node.js 回退實現\n */\nexport interface HashAccelerator {\n /**\n * SHA-256 雜湊計算\n * @param input - 輸入(字串或二進制)\n * @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)\n */\n sha256(input: string | Uint8Array): string\n\n /**\n * HMAC-SHA256 計算\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)\n */\n hmacSha256(key: string, data: string): string\n\n /**\n * SHA-512 hash computation\n * @param input - Input (string or binary)\n * @returns Hex-encoded SHA-512 hash (128 characters)\n */\n sha512(input: string | Uint8Array): string\n\n /**\n * BLAKE2b-256 hash computation\n * On non-Bun runtimes, falls back to SHA-256 with a console warning\n * @param input - Input (string or binary)\n * @returns Hex-encoded hash (64 characters)\n */\n blake2b(input: string | Uint8Array): string\n}\n\n/**\n * 雜湊加速器狀態報告\n */\nexport interface NativeHasherStatus {\n /**\n * 雜湊加速層是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-crypto-hasher': Bun 原生 CryptoHasher(C 實現,推薦)\n * - 'node-crypto': node:crypto 回退實現\n */\n readonly runtime: 'bun-crypto-hasher' | 'node-crypto'\n}\n",
6
6
  "/**\n * JavaScript CBOR 回退實現\n * 用於非 Bun 環境或 FFI 不可用的情況\n * 符合 RFC 7049 規範\n */\n\nimport type { CborAccelerator } from './types'\nimport { CBOR_LENGTH_ENCODING, CBOR_MAJOR_TYPES, CBOR_SIMPLE_VALUES } from './types'\n\n/**\n * CBOR 編碼器\n * 將 JavaScript 物件編碼為 CBOR 二進制格式\n */\nexport class CborFallbackEncoder implements CborAccelerator {\n private static readonly DEFAULT_BUFFER_SIZE = 4096\n private static readonly MAX_DEPTH = 16\n private static readonly MAX_BUFFER_SIZE = 1024 * 1024 // 1MB\n\n private buffer: Uint8Array\n private offset: number\n\n constructor() {\n this.buffer = new Uint8Array(CborFallbackEncoder.DEFAULT_BUFFER_SIZE)\n this.offset = 0\n }\n\n /**\n * 編碼 JavaScript 物件為 CBOR 格式\n */\n encode(data: Record<string, unknown>): Uint8Array {\n this.buffer = new Uint8Array(CborFallbackEncoder.DEFAULT_BUFFER_SIZE)\n this.offset = 0\n this.encodeValue(data, 0)\n return this.buffer.slice(0, this.offset)\n }\n\n /**\n * 解碼 CBOR 二進制為 JavaScript 物件\n */\n decode(bytes: Uint8Array): Record<string, unknown> {\n const decoder = new CborFallbackDecoder(bytes)\n const value = decoder.decode()\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error('CBOR 根值必須是物件')\n }\n return value as Record<string, unknown>\n }\n\n /**\n * 確保 buffer 有足夠空間\n */\n private ensureCapacity(required: number): void {\n let newCapacity = this.buffer.length\n while (this.offset + required > newCapacity) {\n newCapacity *= 2\n if (newCapacity > CborFallbackEncoder.MAX_BUFFER_SIZE) {\n throw new Error(\n `CBOR 編碼超過最大 buffer 大小 ${CborFallbackEncoder.MAX_BUFFER_SIZE} 位元組`\n )\n }\n }\n if (newCapacity !== this.buffer.length) {\n const newBuffer = new Uint8Array(newCapacity)\n newBuffer.set(this.buffer)\n this.buffer = newBuffer\n }\n }\n\n /**\n * 編寫一個位元組\n */\n private writeByte(byte: number): void {\n this.ensureCapacity(1)\n this.buffer[this.offset++] = byte & 0xff\n }\n\n /**\n * 編寫多個位元組\n */\n private writeBytes(bytes: ArrayLike<number>): void {\n this.ensureCapacity(bytes.length)\n this.buffer.set(bytes, this.offset)\n this.offset += bytes.length\n }\n\n /**\n * 編寫 CBOR 長度(Major Type + Additional Info)\n */\n private writeLength(majorType: number, length: number): void {\n const type = majorType << 5\n\n if (length < 24) {\n this.writeByte(type | length)\n } else if (length <= 0xff) {\n this.writeByte(type | CBOR_LENGTH_ENCODING.UINT8)\n this.writeByte(length)\n } else if (length <= 0xffff) {\n this.writeByte(type | CBOR_LENGTH_ENCODING.UINT16)\n this.writeByte((length >> 8) & 0xff)\n this.writeByte(length & 0xff)\n } else if (length <= 0xffffffff) {\n this.writeByte(type | CBOR_LENGTH_ENCODING.UINT32)\n this.writeByte((length >> 24) & 0xff)\n this.writeByte((length >> 16) & 0xff)\n this.writeByte((length >> 8) & 0xff)\n this.writeByte(length & 0xff)\n } else {\n throw new Error(`CBOR 不支援 > 2^32 的長度: ${length}`)\n }\n }\n\n /**\n * 遞迴編碼值\n */\n private encodeValue(value: unknown, depth: number): void {\n if (depth > CborFallbackEncoder.MAX_DEPTH) {\n throw new Error(`CBOR 編碼深度超過限制 ${CborFallbackEncoder.MAX_DEPTH}`)\n }\n\n if (value === null) {\n this.writeByte((CBOR_MAJOR_TYPES.SIMPLE << 5) | CBOR_SIMPLE_VALUES.NULL)\n } else if (value === true) {\n this.writeByte((CBOR_MAJOR_TYPES.SIMPLE << 5) | CBOR_SIMPLE_VALUES.TRUE)\n } else if (value === false) {\n this.writeByte((CBOR_MAJOR_TYPES.SIMPLE << 5) | CBOR_SIMPLE_VALUES.FALSE)\n } else if (typeof value === 'number') {\n this.encodeNumber(value)\n } else if (typeof value === 'string') {\n this.encodeString(value)\n } else if (value instanceof Uint8Array) {\n this.encodeBytes(value)\n } else if (Array.isArray(value)) {\n this.encodeArray(value, depth)\n } else if (typeof value === 'object') {\n this.encodeMap(value as Record<string, unknown>, depth)\n } else {\n throw new Error(`CBOR 不支援類型: ${typeof value}`)\n }\n }\n\n /**\n * 編碼整數或浮點數\n * 對於超過 uint32 範圍的整數,使用 float64 編碼(JavaScript 精度限制)\n */\n private encodeNumber(num: number): void {\n // 檢查是否為整數且在 uint32/negint32 範圍內\n if (Number.isInteger(num) && !Object.is(num, -0)) {\n if (num >= 0 && num <= 0xffffffff) {\n this.writeLength(CBOR_MAJOR_TYPES.UINT, num)\n return\n }\n if (num < 0 && -1 - num <= 0xffffffff) {\n this.writeLength(CBOR_MAJOR_TYPES.NEGINT, -1 - num)\n return\n }\n // 超過 32-bit 範圍的整數,降級為 float64\n }\n {\n // 浮點數(float64)\n const bytes = new Uint8Array(9)\n bytes[0] = (CBOR_MAJOR_TYPES.SIMPLE << 5) | CBOR_LENGTH_ENCODING.FLOAT64\n\n // IEEE 754 雙精度大端序\n const view = new DataView(new ArrayBuffer(8))\n view.setFloat64(0, num, false)\n for (let i = 0; i < 8; i++) {\n bytes[i + 1] = view.getUint8(i)\n }\n this.writeBytes(bytes)\n }\n }\n\n /**\n * 編碼字串\n */\n private encodeString(str: string): void {\n const encoder = new TextEncoder()\n const bytes = encoder.encode(str)\n this.writeLength(CBOR_MAJOR_TYPES.TEXT, bytes.length)\n this.writeBytes(bytes)\n }\n\n /**\n * 編碼位元組陣列\n */\n private encodeBytes(bytes: Uint8Array): void {\n this.writeLength(CBOR_MAJOR_TYPES.BYTES, bytes.length)\n this.writeBytes(bytes)\n }\n\n /**\n * 編碼陣列\n */\n private encodeArray(arr: unknown[], depth: number): void {\n this.writeLength(CBOR_MAJOR_TYPES.ARRAY, arr.length)\n for (const item of arr) {\n this.encodeValue(item, depth + 1)\n }\n }\n\n /**\n * 編碼物件(Map)\n */\n private encodeMap(obj: Record<string, unknown>, depth: number): void {\n const keys = Object.keys(obj)\n this.writeLength(CBOR_MAJOR_TYPES.MAP, keys.length)\n for (const key of keys) {\n this.encodeString(key)\n this.encodeValue(obj[key], depth + 1)\n }\n }\n}\n\n/**\n * CBOR 解碼器\n */\nexport class CborFallbackDecoder {\n private static readonly MAX_DEPTH = 16\n private data: Uint8Array\n private offset: number\n\n constructor(data: Uint8Array) {\n this.data = data\n this.offset = 0\n }\n\n /**\n * 解碼 CBOR 資料\n */\n decode(): unknown {\n return this.decodeValue(0)\n }\n\n /**\n * 讀取一個位元組\n */\n private readByte(): number {\n if (this.offset >= this.data.length) {\n throw new Error('CBOR 資料不足')\n }\n return this.data[this.offset++]\n }\n\n /**\n * 讀取固定長度的位元組\n */\n private readBytes(length: number): Uint8Array {\n if (this.offset + length > this.data.length) {\n throw new Error('CBOR 資料不足')\n }\n const result = this.data.slice(this.offset, this.offset + length)\n this.offset += length\n return result\n }\n\n /**\n * 讀取 CBOR 長度\n */\n private readLength(additionalInfo: number): number {\n if (additionalInfo < 24) {\n return additionalInfo\n }\n if (additionalInfo === 24) {\n return this.readByte()\n }\n if (additionalInfo === 25) {\n const b1 = this.readByte()\n const b2 = this.readByte()\n return (b1 << 8) | b2\n }\n if (additionalInfo === 26) {\n const b1 = this.readByte()\n const b2 = this.readByte()\n const b3 = this.readByte()\n const b4 = this.readByte()\n return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4\n }\n if (additionalInfo === 27) {\n // 64-bit,但 JavaScript 無法精確表示,只支援到 2^53\n const high =\n (this.readByte() << 24) | (this.readByte() << 16) | (this.readByte() << 8) | this.readByte()\n const low =\n (this.readByte() << 24) | (this.readByte() << 16) | (this.readByte() << 8) | this.readByte()\n return high * 0x100000000 + low\n }\n throw new Error(`CBOR 無效的長度編碼: ${additionalInfo}`)\n }\n\n /**\n * 遞迴解碼值\n */\n private decodeValue(depth: number): unknown {\n if (depth > CborFallbackDecoder.MAX_DEPTH) {\n throw new Error(`CBOR 解碼深度超過限制 ${CborFallbackDecoder.MAX_DEPTH}`)\n }\n\n const byte = this.readByte()\n const majorType = (byte >> 5) & 0x07\n const additionalInfo = byte & 0x1f\n\n switch (majorType) {\n case CBOR_MAJOR_TYPES.UINT:\n return this.readLength(additionalInfo)\n\n case CBOR_MAJOR_TYPES.NEGINT:\n return -1 - this.readLength(additionalInfo)\n\n case CBOR_MAJOR_TYPES.BYTES: {\n const length = this.readLength(additionalInfo)\n return this.readBytes(length)\n }\n\n case CBOR_MAJOR_TYPES.TEXT: {\n const length = this.readLength(additionalInfo)\n const bytes = this.readBytes(length)\n const decoder = new TextDecoder()\n return decoder.decode(bytes)\n }\n\n case CBOR_MAJOR_TYPES.ARRAY: {\n const length = this.readLength(additionalInfo)\n const result: unknown[] = []\n for (let i = 0; i < length; i++) {\n result.push(this.decodeValue(depth + 1))\n }\n return result\n }\n\n case CBOR_MAJOR_TYPES.MAP: {\n const length = this.readLength(additionalInfo)\n const result: Record<string, unknown> = {}\n for (let i = 0; i < length; i++) {\n const key = this.decodeValue(depth + 1)\n if (typeof key !== 'string') {\n throw new Error(`CBOR Map 的 key 必須是字串,得到: ${typeof key}`)\n }\n result[key] = this.decodeValue(depth + 1)\n }\n return result\n }\n\n case CBOR_MAJOR_TYPES.SIMPLE:\n if (additionalInfo === CBOR_SIMPLE_VALUES.FALSE) {\n return false\n }\n if (additionalInfo === CBOR_SIMPLE_VALUES.TRUE) {\n return true\n }\n if (additionalInfo === CBOR_SIMPLE_VALUES.NULL) {\n return null\n }\n\n // 浮點數\n if (additionalInfo === CBOR_LENGTH_ENCODING.FLOAT32) {\n const bytes = this.readBytes(4)\n const view = new DataView(bytes.buffer, bytes.byteOffset)\n return view.getFloat32(0, false)\n }\n if (additionalInfo === CBOR_LENGTH_ENCODING.FLOAT64) {\n const bytes = this.readBytes(8)\n const view = new DataView(bytes.buffer, bytes.byteOffset)\n return view.getFloat64(0, false)\n }\n\n throw new Error(`CBOR 不支援的 simple value: ${additionalInfo}`)\n\n case CBOR_MAJOR_TYPES.TAG:\n // TAG 類型在此實現中跳過\n return this.decodeValue(depth)\n\n default:\n throw new Error(`CBOR 無效的 major type: ${majorType}`)\n }\n }\n}\n"
7
7
  ],
8
8
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EO,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,KAAK;AAAA,EACL,QAAQ;AACV;AAKO,IAAM,qBAAqB;AAAA,EAChC,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AACb;AAKO,IAAM,uBAAuB;AAAA,EAClC,iBAAiB;AAAA,EACjB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AACd;;;AClGO,MAAM,oBAA+C;AAAA,SAClC,sBAAsB;AAAA,SACtB,YAAY;AAAA,SACZ,kBAAkB,OAAO;AAAA,EAEzC;AAAA,EACA;AAAA,EAER,WAAW,GAAG;AAAA,IACZ,KAAK,SAAS,IAAI,WAAW,oBAAoB,mBAAmB;AAAA,IACpE,KAAK,SAAS;AAAA;AAAA,EAMhB,MAAM,CAAC,MAA2C;AAAA,IAChD,KAAK,SAAS,IAAI,WAAW,oBAAoB,mBAAmB;AAAA,IACpE,KAAK,SAAS;AAAA,IACd,KAAK,YAAY,MAAM,CAAC;AAAA,IACxB,OAAO,KAAK,OAAO,MAAM,GAAG,KAAK,MAAM;AAAA;AAAA,EAMzC,MAAM,CAAC,OAA4C;AAAA,IACjD,MA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U,CAAC;AAAA,UAC9B,MAAM,OAAO,IAAI,SAAS,MAAM,QAAQ,MAAM,UAAU;AAAA,UACxD,OAAO,KAAK,WAAW,GAAG,KAAK;AAAA,QACjC;AAAA,QAEA,MAAM,IAAI,MAAM,+CAA0B,gBAAgB;AAAA,WAEvD,iBAAiB;AAAA,QAEpB,OAAO,KAAK,YAAY,KAAK;AAAA;AAAA,QAG7B,MAAM,IAAI,MAAM,uCAAuB,WAAW;AAAA;AAAA;AAG1D;",
@@ -17,6 +17,8 @@ import type { HashAccelerator } from './types';
17
17
  * 適用於非 Bun 環境
18
18
  */
19
19
  export declare class HashFallback implements HashAccelerator {
20
+ /** @internal */
21
+ private blake2bWarned;
20
22
  /**
21
23
  * SHA-256 計算(回退實現)
22
24
  * @param input - 輸入(字串或 Uint8Array)
@@ -30,4 +32,17 @@ export declare class HashFallback implements HashAccelerator {
30
32
  * @returns 十六進制編碼的 HMAC-SHA256 值
31
33
  */
32
34
  hmacSha256(key: string, data: string): string;
35
+ /**
36
+ * SHA-512 計算(回退實現)
37
+ * @param input - 輸入(字串或 Uint8Array)
38
+ * @returns 十六進制編碼的 SHA-512 雜湊值(128 字元)
39
+ */
40
+ sha512(input: string | Uint8Array): string;
41
+ /**
42
+ * BLAKE2b-256 計算(回退實現)
43
+ * BLAKE2b-256 在 node:crypto 中不普遍可用,回退至 SHA-256 並發出警告。
44
+ * @param input - 輸入(字串或 Uint8Array)
45
+ * @returns 十六進制編碼的雜湊值(64 字元)
46
+ */
47
+ blake2b(input: string | Uint8Array): string;
33
48
  }
@@ -49,15 +49,26 @@ var __require = import.meta.require;
49
49
  import { createHash, createHmac } from "crypto";
50
50
 
51
51
  class HashFallback {
52
+ blake2bWarned = false;
52
53
  sha256(input) {
53
54
  return createHash("sha256").update(input).digest("hex");
54
55
  }
55
56
  hmacSha256(key, data) {
56
57
  return createHmac("sha256", key).update(data).digest("hex");
57
58
  }
59
+ sha512(input) {
60
+ return createHash("sha512").update(input).digest("hex");
61
+ }
62
+ blake2b(input) {
63
+ if (!this.blake2bWarned) {
64
+ console.warn("[gravito] BLAKE2b not available in node:crypto \u2014 using SHA-256 fallback");
65
+ this.blake2bWarned = true;
66
+ }
67
+ return createHash("sha256").update(input).digest("hex");
68
+ }
58
69
  }
59
70
  export {
60
71
  HashFallback
61
72
  };
62
73
 
63
- //# debugId=3459244799B7D36C64756E2164756E21
74
+ //# debugId=8F3B1B97286D438A64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/ffi/hash-fallback.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * 雜湊加速器 JavaScript 回退實現\n * 基於 node:crypto 標準庫\n *\n * 使用場景:\n * - 非 Bun 環境(Node.js、Deno 等)\n * - Bun CryptoHasher 不可用的情況\n *\n * 性能特性:\n * - 短 key (<100 bytes):~1-2x 慢於 Bun.CryptoHasher(N-API 橋接開銷)\n * - 長 payload:差異較小(主要計算時間)\n * - 一致性:與 node:crypto 標準行為完全相同\n */\n\nimport { createHash, createHmac } from 'node:crypto'\nimport type { HashAccelerator } from './types'\n\n/**\n * Node.js crypto 回退實現\n * 適用於非 Bun 環境\n */\nexport class HashFallback implements HashAccelerator {\n /**\n * SHA-256 計算(回退實現)\n * @param input - 輸入(字串或 Uint8Array)\n * @returns 十六進制編碼的 SHA-256 雜湊值\n */\n sha256(input: string | Uint8Array): string {\n return createHash('sha256').update(input).digest('hex')\n }\n\n /**\n * HMAC-SHA256 計算(回退實現)\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值\n */\n hmacSha256(key: string, data: string): string {\n return createHmac('sha256', key).update(data).digest('hex')\n }\n}\n"
5
+ "/**\n * 雜湊加速器 JavaScript 回退實現\n * 基於 node:crypto 標準庫\n *\n * 使用場景:\n * - 非 Bun 環境(Node.js、Deno 等)\n * - Bun CryptoHasher 不可用的情況\n *\n * 性能特性:\n * - 短 key (<100 bytes):~1-2x 慢於 Bun.CryptoHasher(N-API 橋接開銷)\n * - 長 payload:差異較小(主要計算時間)\n * - 一致性:與 node:crypto 標準行為完全相同\n */\n\nimport { createHash, createHmac } from 'node:crypto'\nimport type { HashAccelerator } from './types'\n\n/**\n * Node.js crypto 回退實現\n * 適用於非 Bun 環境\n */\nexport class HashFallback implements HashAccelerator {\n /** @internal */\n private blake2bWarned = false\n\n /**\n * SHA-256 計算(回退實現)\n * @param input - 輸入(字串或 Uint8Array)\n * @returns 十六進制編碼的 SHA-256 雜湊值\n */\n sha256(input: string | Uint8Array): string {\n return createHash('sha256').update(input).digest('hex')\n }\n\n /**\n * HMAC-SHA256 計算(回退實現)\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值\n */\n hmacSha256(key: string, data: string): string {\n return createHmac('sha256', key).update(data).digest('hex')\n }\n\n /**\n * SHA-512 計算(回退實現)\n * @param input - 輸入(字串或 Uint8Array)\n * @returns 十六進制編碼的 SHA-512 雜湊值(128 字元)\n */\n sha512(input: string | Uint8Array): string {\n return createHash('sha512').update(input).digest('hex')\n }\n\n /**\n * BLAKE2b-256 計算(回退實現)\n * BLAKE2b-256 在 node:crypto 中不普遍可用,回退至 SHA-256 並發出警告。\n * @param input - 輸入(字串或 Uint8Array)\n * @returns 十六進制編碼的雜湊值(64 字元)\n */\n blake2b(input: string | Uint8Array): string {\n // BLAKE2b-256 not universally available in Node.js node:crypto\n // Fallback to SHA-256 with warning\n if (!this.blake2bWarned) {\n console.warn('[gravito] BLAKE2b not available in node:crypto — using SHA-256 fallback')\n this.blake2bWarned = true\n }\n return createHash('sha256').update(input).digest('hex')\n }\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;AAAA;AAOO,MAAM,aAAwC;AAAA,EAMnD,MAAM,CAAC,OAAoC;AAAA,IACzC,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA;AAAA,EASxD,UAAU,CAAC,KAAa,MAAsB;AAAA,IAC5C,OAAO,WAAW,UAAU,GAAG,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAAA;AAE9D;",
8
- "debugId": "3459244799B7D36C64756E2164756E21",
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;AAAA;AAOO,MAAM,aAAwC;AAAA,EAE3C,gBAAgB;AAAA,EAOxB,MAAM,CAAC,OAAoC;AAAA,IACzC,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA;AAAA,EASxD,UAAU,CAAC,KAAa,MAAsB;AAAA,IAC5C,OAAO,WAAW,UAAU,GAAG,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAAA;AAAA,EAQ5D,MAAM,CAAC,OAAoC;AAAA,IACzC,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA;AAAA,EASxD,OAAO,CAAC,OAAoC;AAAA,IAG1C,IAAI,CAAC,KAAK,eAAe;AAAA,MACvB,QAAQ,KAAK,8EAAwE;AAAA,MACrF,KAAK,gBAAgB;AAAA,IACvB;AAAA,IACA,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA;AAE1D;",
8
+ "debugId": "8F3B1B97286D438A64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -117,6 +117,19 @@ export interface HashAccelerator {
117
117
  * @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)
118
118
  */
119
119
  hmacSha256(key: string, data: string): string;
120
+ /**
121
+ * SHA-512 hash computation
122
+ * @param input - Input (string or binary)
123
+ * @returns Hex-encoded SHA-512 hash (128 characters)
124
+ */
125
+ sha512(input: string | Uint8Array): string;
126
+ /**
127
+ * BLAKE2b-256 hash computation
128
+ * On non-Bun runtimes, falls back to SHA-256 with a console warning
129
+ * @param input - Input (string or binary)
130
+ * @returns Hex-encoded hash (64 characters)
131
+ */
132
+ blake2b(input: string | Uint8Array): string;
120
133
  }
121
134
  /**
122
135
  * 雜湊加速器狀態報告
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/ffi/types.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * FFI (Foreign Function Interface) 類型定義\n * 支持 bun:ffi 的原生加速層\n */\n\n/**\n * CBOR 編碼/解碼加速器介面\n * 可由原生 C 實現或 JavaScript 回退實現\n */\nexport interface CborAccelerator {\n /**\n * 將任意 JavaScript 物件編碼為 CBOR 二進制格式\n * @param data - 要編碼的物件(支援:map、string、uint、float64、bytes、null、boolean)\n * @returns CBOR 編碼的二進制資料\n */\n encode(data: Record<string, unknown>): Uint8Array\n\n /**\n * 將 CBOR 二進制格式解碼為 JavaScript 物件\n * @param bytes - CBOR 編碼的二進制資料\n * @returns 解碼後的物件\n */\n decode(bytes: Uint8Array): Record<string, unknown>\n}\n\n/**\n * FFI 加速層狀態報告\n */\nexport interface NativeAcceleratorStatus {\n /**\n * 原生 FFI 加速是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-ffi': Bun C 編譯器(bun:ffi 的 cc())\n * - 'js-fallback': 手寫 JavaScript CBOR 實現\n * - 'cborg': npm 的 cborg 套件(已棄用,僅用於向後相容)\n */\n readonly runtime: 'bun-ffi' | 'js-fallback' | 'cborg'\n\n /**\n * 運行時版本或詳細資訊\n */\n readonly version: string\n}\n\n/**\n * FFI 層配置選項\n */\nexport interface FfiConfig {\n /**\n * 啟用調試日誌\n * @default false\n */\n readonly debug?: boolean\n\n /**\n * 最大 buffer 大小(位元組)\n * @default 1048576 (1MB)\n */\n readonly maxBufferSize?: number\n\n /**\n * 強制使用特定的加速器實現\n * - undefined: 自動選擇(優先 bun-ffi,降級到 js-fallback)\n * - 'bun-ffi': 只使用原生 C 實現\n * - 'js-fallback': 只使用 JavaScript 實現\n */\n readonly forceImplementation?: 'bun-ffi' | 'js-fallback'\n}\n\n/**\n * CBOR Major Type 常數\n * 符合 RFC 7049 規範\n */\nexport const CBOR_MAJOR_TYPES = {\n UINT: 0, // 正整數 (0 to 2^64-1)\n NEGINT: 1, // 負整數 (-1 to -2^64)\n BYTES: 2, // 位元組字串\n TEXT: 3, // 文字字串\n ARRAY: 4, // 陣列\n MAP: 5, // Map 物件\n TAG: 6, // 語意 tag\n SIMPLE: 7, // 簡單值與浮點數\n} as const\n\n/**\n * CBOR 簡單值常數\n */\nexport const CBOR_SIMPLE_VALUES = {\n FALSE: 20, // Boolean false\n TRUE: 21, // Boolean true\n NULL: 22, // null\n UNDEFINED: 23, // undefined (不常用)\n} as const\n\n/**\n * CBOR 長度編碼的附加資訊\n */\nexport const CBOR_LENGTH_ENCODING = {\n SMALL_RANGE_END: 23, // 0-23: 直接作為值\n UINT8: 24, // 24: 接下來 1 byte 為 uint8_t\n UINT16: 25, // 25: 接下來 2 bytes 為 uint16_t (大端序)\n UINT32: 26, // 26: 接下來 4 bytes 為 uint32_t (大端序)\n UINT64: 27, // 27: 接下來 8 bytes 為 uint64_t (大端序)\n FLOAT16: 25, // 25: IEEE 754 半精度浮點數 (special case for SIMPLE)\n FLOAT32: 26, // 26: IEEE 754 單精度浮點數\n FLOAT64: 27, // 27: IEEE 754 雙精度浮點數\n INDEFINITE: 31, // 31: 無限長度編碼\n} as const\n\n/**\n * 雜湊加速器介面\n * 可由 Bun 原生實現或 Node.js 回退實現\n */\nexport interface HashAccelerator {\n /**\n * SHA-256 雜湊計算\n * @param input - 輸入(字串或二進制)\n * @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)\n */\n sha256(input: string | Uint8Array): string\n\n /**\n * HMAC-SHA256 計算\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)\n */\n hmacSha256(key: string, data: string): string\n}\n\n/**\n * 雜湊加速器狀態報告\n */\nexport interface NativeHasherStatus {\n /**\n * 雜湊加速層是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-crypto-hasher': Bun 原生 CryptoHasher(C 實現,推薦)\n * - 'node-crypto': node:crypto 回退實現\n */\n readonly runtime: 'bun-crypto-hasher' | 'node-crypto'\n}\n"
5
+ "/**\n * FFI (Foreign Function Interface) 類型定義\n * 支持 bun:ffi 的原生加速層\n */\n\n/**\n * CBOR 編碼/解碼加速器介面\n * 可由原生 C 實現或 JavaScript 回退實現\n */\nexport interface CborAccelerator {\n /**\n * 將任意 JavaScript 物件編碼為 CBOR 二進制格式\n * @param data - 要編碼的物件(支援:map、string、uint、float64、bytes、null、boolean)\n * @returns CBOR 編碼的二進制資料\n */\n encode(data: Record<string, unknown>): Uint8Array\n\n /**\n * 將 CBOR 二進制格式解碼為 JavaScript 物件\n * @param bytes - CBOR 編碼的二進制資料\n * @returns 解碼後的物件\n */\n decode(bytes: Uint8Array): Record<string, unknown>\n}\n\n/**\n * FFI 加速層狀態報告\n */\nexport interface NativeAcceleratorStatus {\n /**\n * 原生 FFI 加速是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-ffi': Bun C 編譯器(bun:ffi 的 cc())\n * - 'js-fallback': 手寫 JavaScript CBOR 實現\n * - 'cborg': npm 的 cborg 套件(已棄用,僅用於向後相容)\n */\n readonly runtime: 'bun-ffi' | 'js-fallback' | 'cborg'\n\n /**\n * 運行時版本或詳細資訊\n */\n readonly version: string\n}\n\n/**\n * FFI 層配置選項\n */\nexport interface FfiConfig {\n /**\n * 啟用調試日誌\n * @default false\n */\n readonly debug?: boolean\n\n /**\n * 最大 buffer 大小(位元組)\n * @default 1048576 (1MB)\n */\n readonly maxBufferSize?: number\n\n /**\n * 強制使用特定的加速器實現\n * - undefined: 自動選擇(優先 bun-ffi,降級到 js-fallback)\n * - 'bun-ffi': 只使用原生 C 實現\n * - 'js-fallback': 只使用 JavaScript 實現\n */\n readonly forceImplementation?: 'bun-ffi' | 'js-fallback'\n}\n\n/**\n * CBOR Major Type 常數\n * 符合 RFC 7049 規範\n */\nexport const CBOR_MAJOR_TYPES = {\n UINT: 0, // 正整數 (0 to 2^64-1)\n NEGINT: 1, // 負整數 (-1 to -2^64)\n BYTES: 2, // 位元組字串\n TEXT: 3, // 文字字串\n ARRAY: 4, // 陣列\n MAP: 5, // Map 物件\n TAG: 6, // 語意 tag\n SIMPLE: 7, // 簡單值與浮點數\n} as const\n\n/**\n * CBOR 簡單值常數\n */\nexport const CBOR_SIMPLE_VALUES = {\n FALSE: 20, // Boolean false\n TRUE: 21, // Boolean true\n NULL: 22, // null\n UNDEFINED: 23, // undefined (不常用)\n} as const\n\n/**\n * CBOR 長度編碼的附加資訊\n */\nexport const CBOR_LENGTH_ENCODING = {\n SMALL_RANGE_END: 23, // 0-23: 直接作為值\n UINT8: 24, // 24: 接下來 1 byte 為 uint8_t\n UINT16: 25, // 25: 接下來 2 bytes 為 uint16_t (大端序)\n UINT32: 26, // 26: 接下來 4 bytes 為 uint32_t (大端序)\n UINT64: 27, // 27: 接下來 8 bytes 為 uint64_t (大端序)\n FLOAT16: 25, // 25: IEEE 754 半精度浮點數 (special case for SIMPLE)\n FLOAT32: 26, // 26: IEEE 754 單精度浮點數\n FLOAT64: 27, // 27: IEEE 754 雙精度浮點數\n INDEFINITE: 31, // 31: 無限長度編碼\n} as const\n\n/**\n * 雜湊加速器介面\n * 可由 Bun 原生實現或 Node.js 回退實現\n */\nexport interface HashAccelerator {\n /**\n * SHA-256 雜湊計算\n * @param input - 輸入(字串或二進制)\n * @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)\n */\n sha256(input: string | Uint8Array): string\n\n /**\n * HMAC-SHA256 計算\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)\n */\n hmacSha256(key: string, data: string): string\n\n /**\n * SHA-512 hash computation\n * @param input - Input (string or binary)\n * @returns Hex-encoded SHA-512 hash (128 characters)\n */\n sha512(input: string | Uint8Array): string\n\n /**\n * BLAKE2b-256 hash computation\n * On non-Bun runtimes, falls back to SHA-256 with a console warning\n * @param input - Input (string or binary)\n * @returns Hex-encoded hash (64 characters)\n */\n blake2b(input: string | Uint8Array): string\n}\n\n/**\n * 雜湊加速器狀態報告\n */\nexport interface NativeHasherStatus {\n /**\n * 雜湊加速層是否可用\n */\n readonly available: boolean\n\n /**\n * 當前使用的運行時實現\n * - 'bun-crypto-hasher': Bun 原生 CryptoHasher(C 實現,推薦)\n * - 'node-crypto': node:crypto 回退實現\n */\n readonly runtime: 'bun-crypto-hasher' | 'node-crypto'\n}\n"
6
6
  ],
7
7
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EO,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,KAAK;AAAA,EACL,QAAQ;AACV;AAKO,IAAM,qBAAqB;AAAA,EAChC,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AACb;AAKO,IAAM,uBAAuB;AAAA,EAClC,iBAAiB;AAAA,EACjB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AACd;",
8
8
  "debugId": "3722FA7EE113FE4A64756E2164756E21",
@@ -1,6 +1,8 @@
1
1
  import type { CircuitBreakerOptions } from '../events/CircuitBreaker';
2
2
  import type { EventBackend } from '../events/EventBackend';
3
+ import type { MessageQueueBridge } from '../events/MessageQueueBridge';
3
4
  import type { EventQueueConfig } from '../events/EventPriorityQueue';
5
+ import type { AggregationConfig } from '../events/aggregation/types';
4
6
  /**
5
7
  * Callback function for filters (transforms values).
6
8
  * @public
@@ -87,8 +89,10 @@ export interface HookManagerConfig {
87
89
  /**
88
90
  * Database connection for persistent DLQ (optional).
89
91
  * If provided, failed events after max retries will be persisted to database.
92
+ * Typed as `unknown` since core does not depend on @gravito/atlas or any specific DB type.
93
+ * The consuming code (DeadLetterQueueManager) accepts and narrows this to its internal type.
90
94
  */
91
- db?: any;
95
+ db?: unknown;
92
96
  /**
93
97
  * Enable persistent DLQ for failed events (requires db).
94
98
  * @default false
@@ -98,10 +102,10 @@ export interface HookManagerConfig {
98
102
  * Message Queue Bridge for distributed event processing via Bull Queue.
99
103
  * When provided, enables dispatchQueued() method for routing events to Redis-backed queue.
100
104
  */
101
- messageQueueBridge?: any;
105
+ messageQueueBridge?: MessageQueueBridge;
102
106
  /**
103
107
  * Event aggregation configuration (FS-102).
104
108
  * Enables deduplication and micro-batching for improved throughput.
105
109
  */
106
- aggregation?: any;
110
+ aggregation?: AggregationConfig;
107
111
  }
@@ -320,7 +320,7 @@ export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
320
320
  * URL generator helper.
321
321
  * Generates a URL for a named route.
322
322
  */
323
- route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
323
+ route: (name: string, params?: Record<string, string | number>, query?: Record<string, string | number | boolean | null | undefined>) => string;
324
324
  /**
325
325
  * Access the native context object from the underlying HTTP engine.
326
326
  *
@@ -338,7 +338,7 @@ export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
338
338
  * Access the RequestScopeManager for this request
339
339
  * Services resolved through this manager are scoped to the HTTP request lifetime.
340
340
  */
341
- requestScope(): any;
341
+ requestScope(): unknown;
342
342
  /**
343
343
  * Resolve or create a request-scoped service
344
344
  *
@@ -23,12 +23,12 @@ export { EventManager } from './EventManager';
23
23
  export * from './events';
24
24
  export { HookManager, type HookManagerConfig } from './HookManager';
25
25
  export { HealthProvider } from './health/HealthProvider';
26
- export { Arr, abort, abortIf, abortUnless, app, blank, config, DumpDieError, dd, dump, env, filled, hasApp, logger, router, Str, setApp, tap, throwIf, throwUnless, value, } from './helpers';
27
- export * from './helpers/data';
28
- export * from './helpers/errors';
29
- export * from './helpers/response';
26
+ export { Arr, abort, abortIf, abortUnless, app, blank, config, DumpDieError, dd, dump, env, filled, hasApp, logger, router, Str, tap, throwIf, throwUnless, value, } from './helpers';
27
+ export { type DataPath, dataGet, dataHas, dataSet, type PathSegment } from './helpers/data';
28
+ export { createErrorBag, type ErrorBag, errors, old } from './helpers/errors';
29
+ export { type ApiFailure, type ApiSuccess, fail, jsonFail, jsonSuccess, ok, } from './helpers/response';
30
30
  export { CookieJar, type CookieOptions } from './http/CookieJar';
31
31
  export { deleteCookie, getCookie, setCookie } from './http/cookie';
32
32
  export { ServiceProvider } from './ServiceProvider';
33
33
  export * from './runtime/index.browser';
34
- export declare function defineConfig(config: any): any;
34
+ export declare function defineConfig<T extends Record<string, unknown>>(config: T): T;