@gravito/core 1.6.1 → 2.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.
- package/README.md +100 -6
- package/README.zh-TW.md +101 -6
- package/dist/Application.d.ts +256 -0
- package/dist/CommandKernel.d.ts +33 -0
- package/dist/ConfigManager.d.ts +65 -0
- package/dist/Container/RequestScopeManager.d.ts +62 -0
- package/dist/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/Container.d.ts +153 -0
- package/dist/ErrorHandler.d.ts +66 -0
- package/dist/Event.d.ts +5 -0
- package/dist/EventManager.d.ts +123 -0
- package/dist/GlobalErrorHandlers.d.ts +47 -0
- package/dist/GravitoServer.d.ts +28 -0
- package/dist/HookManager.d.ts +435 -0
- package/dist/Listener.d.ts +4 -0
- package/dist/Logger.d.ts +20 -0
- package/dist/PlanetCore.d.ts +402 -0
- package/dist/RequestContext.d.ts +97 -0
- package/dist/Route.d.ts +36 -0
- package/dist/Router.d.ts +270 -0
- package/dist/ServiceProvider.d.ts +178 -0
- package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
- package/dist/adapters/bun/BunContext.d.ts +54 -0
- package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
- package/dist/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
- package/dist/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/adapters/bun/RadixRouter.d.ts +32 -0
- package/dist/adapters/bun/index.d.ts +7 -0
- package/dist/adapters/bun/types.d.ts +20 -0
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/types.d.ts +235 -0
- package/dist/binary/BinaryUtils.d.ts +105 -0
- package/dist/binary/index.d.ts +5 -0
- package/dist/cli/queue-commands.d.ts +6 -0
- package/dist/compat/async-local-storage.browser.d.ts +9 -0
- package/dist/compat/async-local-storage.d.ts +7 -0
- package/dist/compat/crypto.browser.d.ts +5 -0
- package/dist/compat/crypto.d.ts +6 -0
- package/dist/compat.d.ts +23 -1
- package/dist/compat.js +3 -0
- package/dist/compat.js.map +9 -0
- package/dist/engine/AOTRouter.d.ts +139 -0
- package/dist/engine/FastContext.d.ts +141 -0
- package/dist/engine/Gravito.d.ts +131 -0
- package/dist/engine/MinimalContext.d.ts +102 -0
- package/dist/engine/analyzer.d.ts +113 -0
- package/dist/engine/constants.d.ts +23 -0
- package/dist/engine/index.d.ts +14 -910
- package/dist/engine/index.js +623 -622
- package/dist/engine/index.js.map +23 -0
- package/dist/engine/path.d.ts +26 -0
- package/dist/engine/pool.d.ts +83 -0
- package/dist/engine/types.d.ts +149 -0
- package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/events/BackpressureManager.d.ts +215 -0
- package/dist/events/CircuitBreaker.d.ts +229 -0
- package/dist/events/DeadLetterQueue.d.ts +219 -0
- package/dist/events/EventBackend.d.ts +12 -0
- package/dist/events/EventOptions.d.ts +204 -0
- package/dist/events/EventPriorityQueue.d.ts +63 -0
- package/dist/events/FlowControlStrategy.d.ts +109 -0
- package/dist/events/IdempotencyCache.d.ts +60 -0
- package/dist/events/MessageQueueBridge.d.ts +184 -0
- package/dist/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/events/RetryScheduler.d.ts +104 -0
- package/dist/events/WorkerPool.d.ts +98 -0
- package/dist/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/events/aggregation/index.d.ts +10 -0
- package/dist/events/aggregation/types.d.ts +117 -0
- package/dist/events/index.d.ts +26 -0
- package/dist/events/observability/EventMetrics.d.ts +132 -0
- package/dist/events/observability/EventTracer.d.ts +68 -0
- package/dist/events/observability/EventTracing.d.ts +161 -0
- package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
- package/dist/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/events/observability/index.d.ts +24 -0
- package/dist/events/observability/metrics-types.d.ts +16 -0
- package/dist/events/queue-core.d.ts +77 -0
- package/dist/events/task-executor.d.ts +51 -0
- package/dist/events/types.d.ts +134 -0
- package/dist/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/exceptions/GravitoException.d.ts +23 -0
- package/dist/exceptions/HttpException.d.ts +9 -0
- package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/exceptions/ValidationException.d.ts +22 -0
- package/dist/exceptions/index.d.ts +7 -0
- package/dist/ffi/NativeAccelerator.d.ts +69 -0
- package/dist/ffi/NativeHasher.d.ts +139 -0
- package/dist/ffi/cbor-fallback.d.ts +96 -0
- package/dist/ffi/hash-fallback.d.ts +33 -0
- package/dist/ffi/index.d.ts +10 -0
- package/dist/ffi/index.js +131 -0
- package/dist/ffi/index.js.map +11 -0
- package/dist/ffi/types.d.ts +135 -0
- package/dist/health/HealthProvider.d.ts +67 -0
- package/dist/helpers/Arr.d.ts +19 -0
- package/dist/helpers/Str.d.ts +38 -0
- package/dist/helpers/data.d.ts +25 -0
- package/dist/helpers/errors.d.ts +34 -0
- package/dist/helpers/response.d.ts +41 -0
- package/dist/helpers.d.ts +338 -0
- package/dist/hooks/ActionManager.d.ts +132 -0
- package/dist/hooks/AsyncDetector.d.ts +84 -0
- package/dist/hooks/FilterManager.d.ts +71 -0
- package/dist/hooks/MigrationWarner.d.ts +24 -0
- package/dist/hooks/dlq-operations.d.ts +60 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/types.d.ts +107 -0
- package/dist/http/CookieJar.d.ts +51 -0
- package/dist/http/cookie.d.ts +29 -0
- package/dist/http/index.d.ts +12 -0
- package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +35 -16
- package/dist/index.browser.d.ts +34 -0
- package/dist/index.d.ts +60 -10981
- package/dist/index.js +10808 -11273
- package/dist/index.js.map +166 -0
- package/dist/observability/QueueDashboard.d.ts +136 -0
- package/dist/observability/contracts.d.ts +137 -0
- package/dist/observability/index.d.ts +13 -0
- package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
- package/dist/reliability/RetryPolicy.d.ts +217 -0
- package/dist/reliability/index.d.ts +6 -0
- package/dist/router/ControllerDispatcher.d.ts +12 -0
- package/dist/router/RequestValidator.d.ts +20 -0
- package/dist/runtime/adapter-bun.d.ts +12 -0
- package/dist/runtime/adapter-deno.d.ts +12 -0
- package/dist/runtime/adapter-node.d.ts +12 -0
- package/dist/runtime/adapter-unknown.d.ts +13 -0
- package/dist/runtime/archive.d.ts +17 -0
- package/dist/runtime/compression.d.ts +21 -0
- package/dist/runtime/deep-equals.d.ts +56 -0
- package/dist/runtime/detection.d.ts +22 -0
- package/dist/runtime/escape.d.ts +34 -0
- package/dist/runtime/index.browser.d.ts +20 -0
- package/dist/runtime/index.d.ts +44 -0
- package/dist/runtime/markdown.d.ts +44 -0
- package/dist/runtime/types.d.ts +436 -0
- package/dist/runtime-helpers.d.ts +67 -0
- package/dist/runtime.d.ts +11 -0
- package/dist/security/Encrypter.d.ts +33 -0
- package/dist/security/Hasher.d.ts +29 -0
- package/dist/testing/HttpTester.d.ts +39 -0
- package/dist/testing/TestResponse.d.ts +78 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/transpiler-utils.d.ts +170 -0
- package/dist/types/events.d.ts +94 -0
- package/dist/types.d.ts +13 -0
- package/package.json +25 -56
- package/src/ffi/native/cbor.c +1148 -0
- package/dist/Metrics-VOWWRNNR.js +0 -219
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/compat-CI8hiulX.d.ts +0 -376
- package/dist/compat.cjs +0 -18
- package/dist/compat.d.cts +0 -1
- package/dist/engine/index.cjs +0 -1764
- package/dist/engine/index.d.cts +0 -922
- package/dist/index.cjs +0 -14906
- package/dist/index.d.cts +0 -11008
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __returnValue = (v) => v;
|
|
34
|
+
function __exportSetter(name, newValue) {
|
|
35
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
36
|
+
}
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, {
|
|
40
|
+
get: all[name],
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
set: __exportSetter.bind(all, name)
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
var __require = import.meta.require;
|
|
47
|
+
// src/ffi/hash-fallback.ts
|
|
48
|
+
import { createHash, createHmac } from "crypto";
|
|
49
|
+
|
|
50
|
+
class HashFallback {
|
|
51
|
+
sha256(input) {
|
|
52
|
+
return createHash("sha256").update(input).digest("hex");
|
|
53
|
+
}
|
|
54
|
+
hmacSha256(key, data) {
|
|
55
|
+
return createHmac("sha256", key).update(data).digest("hex");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/ffi/NativeHasher.ts
|
|
60
|
+
class BunCryptoHasher {
|
|
61
|
+
sha256(input) {
|
|
62
|
+
return new Bun.CryptoHasher("sha256").update(input).digest("hex");
|
|
63
|
+
}
|
|
64
|
+
hmacSha256(key, data) {
|
|
65
|
+
return new Bun.CryptoHasher("sha256", key).update(data).digest("hex");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class NativeHasher {
|
|
70
|
+
static accelerator = null;
|
|
71
|
+
static status = null;
|
|
72
|
+
static getAccelerator() {
|
|
73
|
+
if (this.accelerator !== null) {
|
|
74
|
+
return this.accelerator;
|
|
75
|
+
}
|
|
76
|
+
if (this.isBunAvailable()) {
|
|
77
|
+
try {
|
|
78
|
+
this.accelerator = new BunCryptoHasher;
|
|
79
|
+
this.updateStatus("bun-crypto-hasher");
|
|
80
|
+
return this.accelerator;
|
|
81
|
+
} catch {}
|
|
82
|
+
}
|
|
83
|
+
this.accelerator = new HashFallback;
|
|
84
|
+
this.updateStatus("node-crypto");
|
|
85
|
+
return this.accelerator;
|
|
86
|
+
}
|
|
87
|
+
static isBunAvailable() {
|
|
88
|
+
try {
|
|
89
|
+
return typeof Bun !== "undefined" && typeof Bun.CryptoHasher === "function";
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
static updateStatus(runtime) {
|
|
95
|
+
this.status = {
|
|
96
|
+
available: runtime === "bun-crypto-hasher",
|
|
97
|
+
runtime
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
static sha256(input) {
|
|
101
|
+
return this.getAccelerator().sha256(input);
|
|
102
|
+
}
|
|
103
|
+
static hmacSha256(key, data) {
|
|
104
|
+
return this.getAccelerator().hmacSha256(key, data);
|
|
105
|
+
}
|
|
106
|
+
static getStatus() {
|
|
107
|
+
if (this.status === null) {
|
|
108
|
+
this.getAccelerator();
|
|
109
|
+
}
|
|
110
|
+
return this.status || {
|
|
111
|
+
available: false,
|
|
112
|
+
runtime: "node-crypto"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
static reset() {
|
|
116
|
+
this.accelerator = null;
|
|
117
|
+
this.status = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
NativeHasher,
|
|
122
|
+
NativeAccelerator,
|
|
123
|
+
HashFallback2 as HashFallback,
|
|
124
|
+
CborFallbackEncoder,
|
|
125
|
+
CborFallbackDecoder,
|
|
126
|
+
CBOR_SIMPLE_VALUES,
|
|
127
|
+
CBOR_MAJOR_TYPES,
|
|
128
|
+
CBOR_LENGTH_ENCODING
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//# debugId=3132C96BF3309F7664756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ffi/hash-fallback.ts", "../src/ffi/NativeHasher.ts"],
|
|
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",
|
|
6
|
+
"/**\n * 原生雜湊加速器\n * 運行時自適應實現,遵循 Galaxy Architecture 的設計模式\n *\n * 架構:\n * - 在 Bun 環境:使用 Bun.CryptoHasher(C 實現,高效)\n * - 其他環境:自動降級到 node:crypto\n * - 完全相同的 API 和結果保證\n *\n * 性能:\n * - Bun 環境:2-3x 快於 node:crypto(消除 N-API 開銷)\n * - 跨運行時:完全相容性\n *\n * 應用場景:\n * - FileStore.hashKey() 熱路徑\n * - Encrypter.hash() 加密雜湊\n * - 任何需要高效雜湊計算的地方\n */\n\nimport { HashFallback } from './hash-fallback'\nimport type { HashAccelerator, NativeHasherStatus } from './types'\n\n/**\n * Bun 原生 CryptoHasher 實現\n * 直接使用 Bun.CryptoHasher API\n */\nclass BunCryptoHasher implements HashAccelerator {\n /**\n * SHA-256 計算(Bun 原生)\n * @param input - 輸入(字串或 Uint8Array)\n * @returns 十六進制編碼的 SHA-256 雜湊值\n */\n sha256(input: string | Uint8Array): string {\n return new Bun.CryptoHasher('sha256').update(input).digest('hex')\n }\n\n /**\n * HMAC-SHA256 計算(Bun 原生)\n * Bun.CryptoHasher 第二參數直接支援 HMAC 密鑰\n *\n * @param key - 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值\n */\n hmacSha256(key: string, data: string): string {\n return new Bun.CryptoHasher('sha256', key).update(data).digest('hex')\n }\n}\n\n/**\n * 原生雜湊加速器統一入口\n * 提供運行時自適應的 SHA-256/HMAC-SHA256 計算\n *\n * 使用範例:\n * ```typescript\n * // SHA-256\n * const hash = NativeHasher.sha256('data')\n *\n * // HMAC-SHA256\n * const hmac = NativeHasher.hmacSha256('secret', 'message')\n *\n * // 檢查狀態\n * const status = NativeHasher.getStatus()\n * console.log(`使用: ${status.runtime}`)\n * ```\n */\nexport class NativeHasher {\n /**\n * 當前加速器實例緩存\n */\n private static accelerator: HashAccelerator | null = null\n\n /**\n * 當前狀態緩存\n */\n private static status: NativeHasherStatus | null = null\n\n /**\n * 取得雜湊加速器實例\n * 優先使用 Bun.CryptoHasher,失敗則降級到 node:crypto\n *\n * @returns 雜湊加速器實例\n */\n private static getAccelerator(): HashAccelerator {\n if (this.accelerator !== null) {\n return this.accelerator\n }\n\n // 嘗試使用 Bun 原生實現\n if (this.isBunAvailable()) {\n try {\n this.accelerator = new BunCryptoHasher()\n this.updateStatus('bun-crypto-hasher')\n return this.accelerator\n } catch {\n // 降級到回退實現\n }\n }\n\n // 降級到 node:crypto 回退\n this.accelerator = new HashFallback()\n this.updateStatus('node-crypto')\n return this.accelerator\n }\n\n /**\n * 檢測 Bun 運行時和 CryptoHasher 可用性\n *\n * @returns Bun.CryptoHasher 是否可用\n */\n private static isBunAvailable(): boolean {\n try {\n return typeof Bun !== 'undefined' && typeof Bun.CryptoHasher === 'function'\n } catch {\n return false\n }\n }\n\n /**\n * 更新狀態\n *\n * @param runtime - 當前使用的運行時\n */\n private static updateStatus(runtime: 'bun-crypto-hasher' | 'node-crypto'): void {\n this.status = {\n available: runtime === 'bun-crypto-hasher',\n runtime,\n }\n }\n\n /**\n * 計算 SHA-256 雜湊\n * 支援字串和二進制輸入\n *\n * @param input - 要雜湊的數據(字串或 Uint8Array)\n * @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)\n *\n * @example\n * ```typescript\n * const hash = NativeHasher.sha256('hello')\n * // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'\n *\n * // 支援 Uint8Array\n * const bytes = new TextEncoder().encode('hello')\n * const hash2 = NativeHasher.sha256(bytes)\n * // 相同結果\n * ```\n */\n static sha256(input: string | Uint8Array): string {\n return this.getAccelerator().sha256(input)\n }\n\n /**\n * 計算 HMAC-SHA256\n * 用於認證消息完整性\n *\n * @param key - HMAC 密鑰\n * @param data - 要雜湊的數據\n * @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)\n *\n * @example\n * ```typescript\n * const hmac = NativeHasher.hmacSha256('secret', 'message')\n * // '8b1a9953c4611296aed9e132b8502cf413b1b881fed3e8d26ab'...\n *\n * // 適用於加密驗證\n * const iv = Buffer.from('...').toString('base64')\n * const encrypted = '...'\n * const mac = NativeHasher.hmacSha256(key, iv + encrypted)\n * ```\n */\n static hmacSha256(key: string, data: string): string {\n return this.getAccelerator().hmacSha256(key, data)\n }\n\n /**\n * 取得加速器狀態\n * 用於診斷和性能監測\n *\n * @returns 加速器狀態報告\n *\n * @example\n * ```typescript\n * const status = NativeHasher.getStatus()\n * console.log(`可用: ${status.available}`)\n * console.log(`運行時: ${status.runtime}`)\n *\n * // 條件邏輯\n * if (status.runtime === 'bun-crypto-hasher') {\n * console.log('使用 Bun 原生實現(高效)')\n * } else {\n * console.log('使用 node:crypto(相容性回退)')\n * }\n * ```\n */\n static getStatus(): NativeHasherStatus {\n // 確保狀態已初始化\n if (this.status === null) {\n this.getAccelerator()\n }\n\n return (\n this.status || {\n available: false,\n runtime: 'node-crypto',\n }\n )\n }\n\n /**\n * 重置加速器狀態\n * 主要用於測試目的,允許重新初始化運行時檢測\n *\n * @internal\n * @example\n * ```typescript\n * // 測試中\n * NativeHasher.reset()\n * // 下一次呼叫會重新偵測運行時\n * const status = NativeHasher.getStatus()\n * ```\n */\n static reset(): void {\n this.accelerator = null\n this.status = null\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"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;;;ACdA,MAAM,gBAA2C;AAAA,EAM/C,MAAM,CAAC,OAAoC;AAAA,IACzC,OAAO,IAAI,IAAI,aAAa,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA;AAAA,EAWlE,UAAU,CAAC,KAAa,MAAsB;AAAA,IAC5C,OAAO,IAAI,IAAI,aAAa,UAAU,GAAG,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAAA;AAExE;AAAA;AAmBO,MAAM,aAAa;AAAA,SAIT,cAAsC;AAAA,SAKtC,SAAoC;AAAA,SAQpC,cAAc,GAAoB;AAAA,IAC/C,IAAI,KAAK,gBAAgB,MAAM;AAAA,MAC7B,OAAO,KAAK;AAAA,IACd;AAAA,IAGA,IAAI,KAAK,eAAe,GAAG;AAAA,MACzB,IAAI;AAAA,QACF,KAAK,cAAc,IAAI;AAAA,QACvB,KAAK,aAAa,mBAAmB;AAAA,QACrC,OAAO,KAAK;AAAA,QACZ,MAAM;AAAA,IAGV;AAAA,IAGA,KAAK,cAAc,IAAI;AAAA,IACvB,KAAK,aAAa,aAAa;AAAA,IAC/B,OAAO,KAAK;AAAA;AAAA,SAQC,cAAc,GAAY;AAAA,IACvC,IAAI;AAAA,MACF,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,iBAAiB;AAAA,MACjE,MAAM;AAAA,MACN,OAAO;AAAA;AAAA;AAAA,SASI,YAAY,CAAC,SAAoD;AAAA,IAC9E,KAAK,SAAS;AAAA,MACZ,WAAW,YAAY;AAAA,MACvB;AAAA,IACF;AAAA;AAAA,SAqBK,MAAM,CAAC,OAAoC;AAAA,IAChD,OAAO,KAAK,eAAe,EAAE,OAAO,KAAK;AAAA;AAAA,SAsBpC,UAAU,CAAC,KAAa,MAAsB;AAAA,IACnD,OAAO,KAAK,eAAe,EAAE,WAAW,KAAK,IAAI;AAAA;AAAA,SAuB5C,SAAS,GAAuB;AAAA,IAErC,IAAI,KAAK,WAAW,MAAM;AAAA,MACxB,KAAK,eAAe;AAAA,IACtB;AAAA,IAEA,OACE,KAAK,UAAU;AAAA,MACb,WAAW;AAAA,MACX,SAAS;AAAA,IACX;AAAA;AAAA,SAiBG,KAAK,GAAS;AAAA,IACnB,KAAK,cAAc;AAAA,IACnB,KAAK,SAAS;AAAA;AAElB;",
|
|
9
|
+
"debugId": "3132C96BF3309F7664756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFI (Foreign Function Interface) 類型定義
|
|
3
|
+
* 支持 bun:ffi 的原生加速層
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* CBOR 編碼/解碼加速器介面
|
|
7
|
+
* 可由原生 C 實現或 JavaScript 回退實現
|
|
8
|
+
*/
|
|
9
|
+
export interface CborAccelerator {
|
|
10
|
+
/**
|
|
11
|
+
* 將任意 JavaScript 物件編碼為 CBOR 二進制格式
|
|
12
|
+
* @param data - 要編碼的物件(支援:map、string、uint、float64、bytes、null、boolean)
|
|
13
|
+
* @returns CBOR 編碼的二進制資料
|
|
14
|
+
*/
|
|
15
|
+
encode(data: Record<string, unknown>): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* 將 CBOR 二進制格式解碼為 JavaScript 物件
|
|
18
|
+
* @param bytes - CBOR 編碼的二進制資料
|
|
19
|
+
* @returns 解碼後的物件
|
|
20
|
+
*/
|
|
21
|
+
decode(bytes: Uint8Array): Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* FFI 加速層狀態報告
|
|
25
|
+
*/
|
|
26
|
+
export interface NativeAcceleratorStatus {
|
|
27
|
+
/**
|
|
28
|
+
* 原生 FFI 加速是否可用
|
|
29
|
+
*/
|
|
30
|
+
readonly available: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 當前使用的運行時實現
|
|
33
|
+
* - 'bun-ffi': Bun C 編譯器(bun:ffi 的 cc())
|
|
34
|
+
* - 'js-fallback': 手寫 JavaScript CBOR 實現
|
|
35
|
+
* - 'cborg': npm 的 cborg 套件(已棄用,僅用於向後相容)
|
|
36
|
+
*/
|
|
37
|
+
readonly runtime: 'bun-ffi' | 'js-fallback' | 'cborg';
|
|
38
|
+
/**
|
|
39
|
+
* 運行時版本或詳細資訊
|
|
40
|
+
*/
|
|
41
|
+
readonly version: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* FFI 層配置選項
|
|
45
|
+
*/
|
|
46
|
+
export interface FfiConfig {
|
|
47
|
+
/**
|
|
48
|
+
* 啟用調試日誌
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
readonly debug?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 最大 buffer 大小(位元組)
|
|
54
|
+
* @default 1048576 (1MB)
|
|
55
|
+
*/
|
|
56
|
+
readonly maxBufferSize?: number;
|
|
57
|
+
/**
|
|
58
|
+
* 強制使用特定的加速器實現
|
|
59
|
+
* - undefined: 自動選擇(優先 bun-ffi,降級到 js-fallback)
|
|
60
|
+
* - 'bun-ffi': 只使用原生 C 實現
|
|
61
|
+
* - 'js-fallback': 只使用 JavaScript 實現
|
|
62
|
+
*/
|
|
63
|
+
readonly forceImplementation?: 'bun-ffi' | 'js-fallback';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* CBOR Major Type 常數
|
|
67
|
+
* 符合 RFC 7049 規範
|
|
68
|
+
*/
|
|
69
|
+
export declare const CBOR_MAJOR_TYPES: {
|
|
70
|
+
readonly UINT: 0;
|
|
71
|
+
readonly NEGINT: 1;
|
|
72
|
+
readonly BYTES: 2;
|
|
73
|
+
readonly TEXT: 3;
|
|
74
|
+
readonly ARRAY: 4;
|
|
75
|
+
readonly MAP: 5;
|
|
76
|
+
readonly TAG: 6;
|
|
77
|
+
readonly SIMPLE: 7;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* CBOR 簡單值常數
|
|
81
|
+
*/
|
|
82
|
+
export declare const CBOR_SIMPLE_VALUES: {
|
|
83
|
+
readonly FALSE: 20;
|
|
84
|
+
readonly TRUE: 21;
|
|
85
|
+
readonly NULL: 22;
|
|
86
|
+
readonly UNDEFINED: 23;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* CBOR 長度編碼的附加資訊
|
|
90
|
+
*/
|
|
91
|
+
export declare const CBOR_LENGTH_ENCODING: {
|
|
92
|
+
readonly SMALL_RANGE_END: 23;
|
|
93
|
+
readonly UINT8: 24;
|
|
94
|
+
readonly UINT16: 25;
|
|
95
|
+
readonly UINT32: 26;
|
|
96
|
+
readonly UINT64: 27;
|
|
97
|
+
readonly FLOAT16: 25;
|
|
98
|
+
readonly FLOAT32: 26;
|
|
99
|
+
readonly FLOAT64: 27;
|
|
100
|
+
readonly INDEFINITE: 31;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 雜湊加速器介面
|
|
104
|
+
* 可由 Bun 原生實現或 Node.js 回退實現
|
|
105
|
+
*/
|
|
106
|
+
export interface HashAccelerator {
|
|
107
|
+
/**
|
|
108
|
+
* SHA-256 雜湊計算
|
|
109
|
+
* @param input - 輸入(字串或二進制)
|
|
110
|
+
* @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)
|
|
111
|
+
*/
|
|
112
|
+
sha256(input: string | Uint8Array): string;
|
|
113
|
+
/**
|
|
114
|
+
* HMAC-SHA256 計算
|
|
115
|
+
* @param key - 密鑰
|
|
116
|
+
* @param data - 要雜湊的數據
|
|
117
|
+
* @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)
|
|
118
|
+
*/
|
|
119
|
+
hmacSha256(key: string, data: string): string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 雜湊加速器狀態報告
|
|
123
|
+
*/
|
|
124
|
+
export interface NativeHasherStatus {
|
|
125
|
+
/**
|
|
126
|
+
* 雜湊加速層是否可用
|
|
127
|
+
*/
|
|
128
|
+
readonly available: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* 當前使用的運行時實現
|
|
131
|
+
* - 'bun-crypto-hasher': Bun 原生 CryptoHasher(C 實現,推薦)
|
|
132
|
+
* - 'node-crypto': node:crypto 回退實現
|
|
133
|
+
*/
|
|
134
|
+
readonly runtime: 'bun-crypto-hasher' | 'node-crypto';
|
|
135
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HealthProvider - Cloud-native health checks
|
|
3
|
+
*
|
|
4
|
+
* Provides liveness and readiness probes for Kubernetes and cloud deployments
|
|
5
|
+
*
|
|
6
|
+
* @module @gravito/core/health
|
|
7
|
+
* @since 2.2.0
|
|
8
|
+
*/
|
|
9
|
+
import type { Container } from '../Container';
|
|
10
|
+
import type { PlanetCore } from '../PlanetCore';
|
|
11
|
+
import { ServiceProvider } from '../ServiceProvider';
|
|
12
|
+
/**
|
|
13
|
+
* Health check result
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export interface HealthCheckResult {
|
|
17
|
+
/** Health status */
|
|
18
|
+
status: 'healthy' | 'unhealthy';
|
|
19
|
+
/** Optional message */
|
|
20
|
+
message?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Health check function interface
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export interface HealthCheck {
|
|
27
|
+
/** Unique name for this check */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Check function that returns health status */
|
|
30
|
+
check(): Promise<HealthCheckResult>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* HealthProvider - Provides /health/liveness and /health/readiness endpoints
|
|
34
|
+
*
|
|
35
|
+
* - Liveness: Always returns 200 OK (just checks if server is running)
|
|
36
|
+
* - Readiness: Returns 200 if all checks are healthy, 503 otherwise
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare class HealthProvider extends ServiceProvider {
|
|
41
|
+
private checks;
|
|
42
|
+
register(container: Container): void;
|
|
43
|
+
/**
|
|
44
|
+
* Register a health check
|
|
45
|
+
*
|
|
46
|
+
* @param check - The health check to register
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const health = core.container.make<HealthProvider>('health')
|
|
51
|
+
* health.registerCheck({
|
|
52
|
+
* name: 'database',
|
|
53
|
+
* check: async () => {
|
|
54
|
+
* try {
|
|
55
|
+
* await db.ping()
|
|
56
|
+
* return { status: 'healthy' }
|
|
57
|
+
* } catch {
|
|
58
|
+
* return { status: 'unhealthy', message: 'DB unreachable' }
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
registerCheck(check: HealthCheck): void;
|
|
65
|
+
boot(core: PlanetCore): void;
|
|
66
|
+
}
|
|
67
|
+
export default HealthProvider;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type DataPath } from './data';
|
|
2
|
+
/**
|
|
3
|
+
* Array and Collection Helpers.
|
|
4
|
+
* Provides utility methods for array manipulation and deep object access.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const Arr: {
|
|
8
|
+
readonly get: <TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault) => unknown | TDefault;
|
|
9
|
+
readonly has: (target: unknown, path: DataPath | null | undefined) => boolean;
|
|
10
|
+
readonly set: (target: unknown, path: DataPath, value: unknown, overwrite?: boolean) => unknown;
|
|
11
|
+
readonly wrap: <T>(value: T | T[] | null | undefined) => T[];
|
|
12
|
+
readonly first: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
|
|
13
|
+
readonly last: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
|
|
14
|
+
readonly only: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
|
|
15
|
+
readonly except: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
|
|
16
|
+
readonly flatten: (items: unknown[], depth?: number) => unknown[];
|
|
17
|
+
readonly pluck: <TItem extends Record<string, unknown>>(items: readonly TItem[], valuePath: DataPath, keyPath?: DataPath) => unknown[] | Record<string, unknown>;
|
|
18
|
+
readonly where: <T>(items: readonly T[], callback: (value: T, index: number) => boolean) => T[];
|
|
19
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type StartsEndsNeedle = string | readonly string[];
|
|
2
|
+
/**
|
|
3
|
+
* String Helper Utilities.
|
|
4
|
+
* Provides methods for string manipulation, case conversion, and UUID generation.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const Str: {
|
|
8
|
+
readonly lower: (value: string) => string;
|
|
9
|
+
readonly upper: (value: string) => string;
|
|
10
|
+
readonly startsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
11
|
+
readonly endsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
12
|
+
readonly contains: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
13
|
+
readonly snake: (value: string) => string;
|
|
14
|
+
readonly kebab: (value: string) => string;
|
|
15
|
+
readonly studly: (value: string) => string;
|
|
16
|
+
readonly camel: (value: string) => string;
|
|
17
|
+
readonly title: (value: string) => string;
|
|
18
|
+
readonly limit: (value: string, limit: number, end?: string) => string;
|
|
19
|
+
readonly slug: (value: string, separator?: string) => string;
|
|
20
|
+
readonly uuid: () => string;
|
|
21
|
+
/**
|
|
22
|
+
* 生成 UUID v7(單調遞增,內含時間戳)。
|
|
23
|
+
*
|
|
24
|
+
* Bun 環境使用原生 Bun.randomUUIDv7() (C++ 實作)。
|
|
25
|
+
* Node.js/Deno 環境使用 RFC 9562 的 JavaScript polyfill。
|
|
26
|
+
*
|
|
27
|
+
* UUID v7 的優勢:
|
|
28
|
+
* - 資料庫主鍵天然有序 → B-tree 索引性能提升 2-10x
|
|
29
|
+
* - 可從 UUID 提取毫秒級時間戳
|
|
30
|
+
* - 仍保持全域唯一性
|
|
31
|
+
*
|
|
32
|
+
* @returns UUID v7 字串
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
readonly uuidv7: () => string;
|
|
36
|
+
readonly random: (length?: number) => string;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path segment (key) in a data structure.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export type PathSegment = string | number;
|
|
6
|
+
/**
|
|
7
|
+
* Path to a value (dot notation or array of segments).
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type DataPath = string | readonly PathSegment[];
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a value from a deep object using dot notation.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataGet<TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault): unknown | TDefault;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a key exists in a deep object using dot notation.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function dataHas(target: unknown, path: DataPath | null | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Set a value in a deep object using dot notation.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare function dataSet(target: unknown, path: DataPath, setValue: unknown, overwrite?: boolean): unknown;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GravitoContext } from '../http/types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for displaying validation errors in views.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ErrorBag {
|
|
7
|
+
/** Check if a field has errors */
|
|
8
|
+
has(field: string): boolean;
|
|
9
|
+
/** Get the first error message for a field (or any first error if no field specified) */
|
|
10
|
+
first(field?: string): string | undefined;
|
|
11
|
+
/** Get all error messages for a field */
|
|
12
|
+
get(field: string): string[];
|
|
13
|
+
/** Get all errors for all fields */
|
|
14
|
+
all(): Record<string, string[]>;
|
|
15
|
+
/** Check if there are any errors */
|
|
16
|
+
any(): boolean;
|
|
17
|
+
/** Get total number of error messages */
|
|
18
|
+
count(): number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a new ErrorBag instance from raw errors.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare function createErrorBag(errors: Record<string, string[]>): ErrorBag;
|
|
25
|
+
/**
|
|
26
|
+
* Helper to retrieve the ErrorBag from session flash data.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function errors(c: GravitoContext): ErrorBag;
|
|
30
|
+
/**
|
|
31
|
+
* Helper to retrieve old input value from session flash.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare function old(c: GravitoContext, field: string, defaultValue?: unknown): unknown;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContentfulStatusCode, GravitoContext } from '../http/types';
|
|
2
|
+
/**
|
|
3
|
+
* Standard API Success Response Structure
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type ApiSuccess<T> = {
|
|
7
|
+
success: true;
|
|
8
|
+
data: T;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Standard API Failure Response Structure
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type ApiFailure = {
|
|
15
|
+
success: false;
|
|
16
|
+
error: {
|
|
17
|
+
message: string;
|
|
18
|
+
code?: string;
|
|
19
|
+
details?: unknown;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Create a success response object.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function ok<T>(data: T): ApiSuccess<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a failure response object.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function fail(message: string, code?: string, details?: unknown): ApiFailure;
|
|
32
|
+
/**
|
|
33
|
+
* Return a JSON response with standard success structure.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare function jsonSuccess<T>(c: GravitoContext, data: T, status?: ContentfulStatusCode): Response;
|
|
37
|
+
/**
|
|
38
|
+
* Return a JSON response with standard failure structure.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare function jsonFail(c: GravitoContext, message: string, status?: ContentfulStatusCode, code?: string, details?: unknown): Response;
|