@gravito/core 1.6.1 → 2.0.0

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 (173) hide show
  1. package/README.md +100 -6
  2. package/README.zh-TW.md +101 -6
  3. package/dist/Application.d.ts +256 -0
  4. package/dist/CommandKernel.d.ts +33 -0
  5. package/dist/ConfigManager.d.ts +65 -0
  6. package/dist/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/Container.d.ts +153 -0
  9. package/dist/ErrorHandler.d.ts +66 -0
  10. package/dist/Event.d.ts +5 -0
  11. package/dist/EventManager.d.ts +123 -0
  12. package/dist/GlobalErrorHandlers.d.ts +47 -0
  13. package/dist/GravitoServer.d.ts +28 -0
  14. package/dist/HookManager.d.ts +435 -0
  15. package/dist/Listener.d.ts +4 -0
  16. package/dist/Logger.d.ts +20 -0
  17. package/dist/PlanetCore.d.ts +402 -0
  18. package/dist/RequestContext.d.ts +97 -0
  19. package/dist/Route.d.ts +36 -0
  20. package/dist/Router.d.ts +270 -0
  21. package/dist/ServiceProvider.d.ts +178 -0
  22. package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
  23. package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
  24. package/dist/adapters/bun/BunContext.d.ts +54 -0
  25. package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
  26. package/dist/adapters/bun/BunRequest.d.ts +31 -0
  27. package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  28. package/dist/adapters/bun/RadixNode.d.ts +19 -0
  29. package/dist/adapters/bun/RadixRouter.d.ts +32 -0
  30. package/dist/adapters/bun/index.d.ts +7 -0
  31. package/dist/adapters/bun/types.d.ts +20 -0
  32. package/dist/adapters/index.d.ts +12 -0
  33. package/dist/adapters/types.d.ts +235 -0
  34. package/dist/binary/BinaryUtils.d.ts +105 -0
  35. package/dist/binary/index.d.ts +5 -0
  36. package/dist/cli/queue-commands.d.ts +6 -0
  37. package/dist/compat/async-local-storage.browser.d.ts +9 -0
  38. package/dist/compat/async-local-storage.d.ts +7 -0
  39. package/dist/compat/crypto.browser.d.ts +5 -0
  40. package/dist/compat/crypto.d.ts +6 -0
  41. package/dist/compat.cjs +42 -11
  42. package/dist/compat.cjs.map +9 -0
  43. package/dist/compat.d.ts +23 -1
  44. package/dist/compat.js +3 -0
  45. package/dist/compat.js.map +9 -0
  46. package/dist/engine/AOTRouter.d.ts +139 -0
  47. package/dist/engine/FastContext.d.ts +141 -0
  48. package/dist/engine/Gravito.d.ts +131 -0
  49. package/dist/engine/MinimalContext.d.ts +102 -0
  50. package/dist/engine/analyzer.d.ts +113 -0
  51. package/dist/engine/constants.d.ts +23 -0
  52. package/dist/engine/index.cjs +576 -647
  53. package/dist/engine/index.cjs.map +22 -0
  54. package/dist/engine/index.d.ts +14 -910
  55. package/dist/engine/index.js +576 -623
  56. package/dist/engine/index.js.map +22 -0
  57. package/dist/engine/path.d.ts +26 -0
  58. package/dist/engine/pool.d.ts +83 -0
  59. package/dist/engine/types.d.ts +149 -0
  60. package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
  61. package/dist/events/BackpressureManager.d.ts +215 -0
  62. package/dist/events/CircuitBreaker.d.ts +229 -0
  63. package/dist/events/DeadLetterQueue.d.ts +219 -0
  64. package/dist/events/EventBackend.d.ts +12 -0
  65. package/dist/events/EventOptions.d.ts +204 -0
  66. package/dist/events/EventPriorityQueue.d.ts +63 -0
  67. package/dist/events/FlowControlStrategy.d.ts +109 -0
  68. package/dist/events/IdempotencyCache.d.ts +60 -0
  69. package/dist/events/MessageQueueBridge.d.ts +184 -0
  70. package/dist/events/PriorityEscalationManager.d.ts +82 -0
  71. package/dist/events/RetryScheduler.d.ts +104 -0
  72. package/dist/events/WorkerPool.d.ts +98 -0
  73. package/dist/events/WorkerPoolConfig.d.ts +153 -0
  74. package/dist/events/WorkerPoolMetrics.d.ts +65 -0
  75. package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
  76. package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
  77. package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
  78. package/dist/events/aggregation/EventBatcher.d.ts +99 -0
  79. package/dist/events/aggregation/index.d.ts +10 -0
  80. package/dist/events/aggregation/types.d.ts +117 -0
  81. package/dist/events/index.d.ts +26 -0
  82. package/dist/events/observability/EventMetrics.d.ts +132 -0
  83. package/dist/events/observability/EventTracer.d.ts +68 -0
  84. package/dist/events/observability/EventTracing.d.ts +161 -0
  85. package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
  86. package/dist/events/observability/ObservableHookManager.d.ts +108 -0
  87. package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
  88. package/dist/events/observability/index.d.ts +24 -0
  89. package/dist/events/observability/metrics-types.d.ts +16 -0
  90. package/dist/events/queue-core.d.ts +77 -0
  91. package/dist/events/task-executor.d.ts +51 -0
  92. package/dist/events/types.d.ts +134 -0
  93. package/dist/exceptions/AuthenticationException.d.ts +8 -0
  94. package/dist/exceptions/AuthorizationException.d.ts +8 -0
  95. package/dist/exceptions/CircularDependencyException.d.ts +9 -0
  96. package/dist/exceptions/GravitoException.d.ts +23 -0
  97. package/dist/exceptions/HttpException.d.ts +9 -0
  98. package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
  99. package/dist/exceptions/ValidationException.d.ts +22 -0
  100. package/dist/exceptions/index.d.ts +7 -0
  101. package/dist/ffi/NativeAccelerator.d.ts +69 -0
  102. package/dist/ffi/NativeHasher.d.ts +139 -0
  103. package/dist/ffi/cbor-fallback.d.ts +96 -0
  104. package/dist/ffi/hash-fallback.d.ts +33 -0
  105. package/dist/ffi/index.cjs +621 -0
  106. package/dist/ffi/index.cjs.map +14 -0
  107. package/dist/ffi/index.d.ts +10 -0
  108. package/dist/ffi/index.js +602 -0
  109. package/dist/ffi/index.js.map +14 -0
  110. package/dist/ffi/types.d.ts +135 -0
  111. package/dist/health/HealthProvider.d.ts +67 -0
  112. package/dist/helpers/Arr.d.ts +19 -0
  113. package/dist/helpers/Str.d.ts +38 -0
  114. package/dist/helpers/data.d.ts +25 -0
  115. package/dist/helpers/errors.d.ts +34 -0
  116. package/dist/helpers/response.d.ts +41 -0
  117. package/dist/helpers.d.ts +338 -0
  118. package/dist/hooks/ActionManager.d.ts +132 -0
  119. package/dist/hooks/AsyncDetector.d.ts +84 -0
  120. package/dist/hooks/FilterManager.d.ts +71 -0
  121. package/dist/hooks/MigrationWarner.d.ts +24 -0
  122. package/dist/hooks/dlq-operations.d.ts +60 -0
  123. package/dist/hooks/index.d.ts +11 -0
  124. package/dist/hooks/types.d.ts +107 -0
  125. package/dist/http/CookieJar.d.ts +51 -0
  126. package/dist/http/cookie.d.ts +29 -0
  127. package/dist/http/index.d.ts +12 -0
  128. package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +29 -16
  129. package/dist/index.browser.d.ts +34 -0
  130. package/dist/index.cjs +10525 -11171
  131. package/dist/index.cjs.map +168 -0
  132. package/dist/index.d.ts +58 -10981
  133. package/dist/index.js +10861 -10997
  134. package/dist/index.js.map +168 -0
  135. package/dist/observability/QueueDashboard.d.ts +136 -0
  136. package/dist/observability/contracts.d.ts +137 -0
  137. package/dist/observability/index.d.ts +13 -0
  138. package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
  139. package/dist/reliability/RetryPolicy.d.ts +217 -0
  140. package/dist/reliability/index.d.ts +6 -0
  141. package/dist/router/ControllerDispatcher.d.ts +12 -0
  142. package/dist/router/RequestValidator.d.ts +20 -0
  143. package/dist/runtime/adapter-bun.d.ts +12 -0
  144. package/dist/runtime/adapter-deno.d.ts +12 -0
  145. package/dist/runtime/adapter-node.d.ts +12 -0
  146. package/dist/runtime/adapter-unknown.d.ts +13 -0
  147. package/dist/runtime/archive.d.ts +17 -0
  148. package/dist/runtime/compression.d.ts +21 -0
  149. package/dist/runtime/deep-equals.d.ts +56 -0
  150. package/dist/runtime/detection.d.ts +22 -0
  151. package/dist/runtime/escape.d.ts +34 -0
  152. package/dist/runtime/index.browser.d.ts +20 -0
  153. package/dist/runtime/index.d.ts +44 -0
  154. package/dist/runtime/markdown.d.ts +44 -0
  155. package/dist/runtime/types.d.ts +436 -0
  156. package/dist/runtime-helpers.d.ts +67 -0
  157. package/dist/runtime.d.ts +11 -0
  158. package/dist/security/Encrypter.d.ts +33 -0
  159. package/dist/security/Hasher.d.ts +29 -0
  160. package/dist/testing/HttpTester.d.ts +39 -0
  161. package/dist/testing/TestResponse.d.ts +78 -0
  162. package/dist/testing/index.d.ts +2 -0
  163. package/dist/transpiler-utils.d.ts +170 -0
  164. package/dist/types/events.d.ts +94 -0
  165. package/dist/types.d.ts +13 -0
  166. package/package.json +21 -52
  167. package/src/ffi/native/cbor.c +1148 -0
  168. package/dist/Metrics-VOWWRNNR.js +0 -219
  169. package/dist/chunk-R5U7XKVJ.js +0 -16
  170. package/dist/compat-CI8hiulX.d.ts +0 -376
  171. package/dist/compat.d.cts +0 -1
  172. package/dist/engine/index.d.cts +0 -922
  173. package/dist/index.d.cts +0 -11008
@@ -0,0 +1,217 @@
1
+ /**
2
+ * @gravito/core - Retry Policy
3
+ *
4
+ * 重試策略和退避算法的實現
5
+ * 支持指數和線性退避,包含 Jitter 防止雷鳴羊群
6
+ */
7
+ /**
8
+ * 重試策略配置接口
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const policy: RetryPolicy = {
13
+ * maxRetries: 3,
14
+ * backoff: 'exponential',
15
+ * initialDelayMs: 1000,
16
+ * maxDelayMs: 30000,
17
+ * dlqAfterMaxRetries: true
18
+ * }
19
+ * ```
20
+ */
21
+ export interface RetryPolicy {
22
+ /** 最大重試次數 */
23
+ maxRetries: number;
24
+ /** 退避策略:指數或線性 */
25
+ backoff: 'exponential' | 'linear';
26
+ /** 初始延遲時間(毫秒) */
27
+ initialDelayMs: number;
28
+ /** 最大延遲時間(毫秒) */
29
+ maxDelayMs: number;
30
+ /** 超過最大重試次數後是否發送到死信隊列 */
31
+ dlqAfterMaxRetries?: boolean;
32
+ }
33
+ /**
34
+ * 重試引擎
35
+ *
36
+ * 負責計算重試延遲、判斷是否應該重試等邏輯
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const engine = new RetryEngine()
41
+ * const delay = engine.calculateDelay(1, policy)
42
+ * const shouldRetry = engine.shouldRetry(3, policy)
43
+ * ```
44
+ */
45
+ export declare class RetryEngine {
46
+ /**
47
+ * 計算下次重試的延遲時間(毫秒)
48
+ *
49
+ * @param attemptCount - 當前嘗試次數(從 1 開始)
50
+ * @param policy - 重試策略配置
51
+ * @returns 延遲時間(毫秒)
52
+ *
53
+ * @description
54
+ * - 指數退避:delay = initialDelay * 2^(attemptCount - 1)
55
+ * - 線性退避:delay = initialDelay * attemptCount
56
+ * - 添加隨機抖動(Jitter),防止雷鳴羊群問題
57
+ * - 結果不超過 maxDelayMs
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const policy: RetryPolicy = {
62
+ * maxRetries: 3,
63
+ * backoff: 'exponential',
64
+ * initialDelayMs: 1000,
65
+ * maxDelayMs: 30000
66
+ * }
67
+ *
68
+ * // 第 1 次重試:1000ms * 2^0 = 1000ms (加抖動)
69
+ * const delay1 = engine.calculateDelay(1, policy) // ~1100ms
70
+ *
71
+ * // 第 2 次重試:1000ms * 2^1 = 2000ms (加抖動)
72
+ * const delay2 = engine.calculateDelay(2, policy) // ~2200ms
73
+ *
74
+ * // 第 3 次重試:1000ms * 2^2 = 4000ms (加抖動)
75
+ * const delay3 = engine.calculateDelay(3, policy) // ~4400ms
76
+ * ```
77
+ */
78
+ calculateDelay(attemptCount: number, policy: RetryPolicy): number;
79
+ /**
80
+ * 判斷是否應該重試
81
+ *
82
+ * @param attemptCount - 當前嘗試次數(從 1 開始)
83
+ * @param policy - 重試策略配置
84
+ * @returns 是否應該重試
85
+ *
86
+ * @description
87
+ * 當 attemptCount < maxRetries 時返回 true
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const policy = { maxRetries: 3, ... }
92
+ *
93
+ * engine.shouldRetry(1, policy) // true(1 < 3)
94
+ * engine.shouldRetry(3, policy) // false(3 >= 3)
95
+ * engine.shouldRetry(4, policy) // false(4 >= 3)
96
+ * ```
97
+ */
98
+ shouldRetry(attemptCount: number, policy: RetryPolicy): boolean;
99
+ /**
100
+ * 獲取退避時間(包含延遲計算和 Jitter)
101
+ *
102
+ * @param retryCount - 重試次數(從 0 開始)
103
+ * @param policy - 重試策略配置
104
+ * @returns 退避時間(毫秒)
105
+ *
106
+ * @description
107
+ * 這是 calculateDelay 的別名,但接收的是從 0 開始的重試計數
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const policy = { maxRetries: 3, initialDelayMs: 1000, maxDelayMs: 30000, backoff: 'exponential' }
112
+ *
113
+ * // 第 0 次重試(第 1 次嘗試失敗)
114
+ * const time1 = engine.getBackoffTime(0, policy) // ~1100ms
115
+ *
116
+ * // 第 1 次重試(第 2 次嘗試失敗)
117
+ * const time2 = engine.getBackoffTime(1, policy) // ~2200ms
118
+ * ```
119
+ */
120
+ getBackoffTime(retryCount: number, policy: RetryPolicy): number;
121
+ /**
122
+ * 計算下次重試的絕對時間
123
+ *
124
+ * @param retryCount - 重試次數(從 0 開始)
125
+ * @param policy - 重試策略配置
126
+ * @param baseTime - 基礎時間戳(默認為當前時間)
127
+ * @returns 下次重試的時間戳(毫秒)
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const policy = { maxRetries: 3, initialDelayMs: 1000, maxDelayMs: 30000, backoff: 'exponential' }
132
+ *
133
+ * const now = Date.now()
134
+ * const nextRetryTime = engine.getNextRetryTime(0, policy, now)
135
+ * // 返回大約 now + 1000 + jitter
136
+ * ```
137
+ */
138
+ getNextRetryTime(retryCount: number, policy: RetryPolicy, baseTime?: number): number;
139
+ /**
140
+ * 驗證重試策略配置
141
+ *
142
+ * @param policy - 重試策略配置
143
+ * @returns 是否有效
144
+ *
145
+ * @description
146
+ * 檢查配置是否合理:
147
+ * - maxRetries >= 0
148
+ * - initialDelayMs > 0
149
+ * - maxDelayMs >= initialDelayMs
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const validPolicy = { maxRetries: 3, initialDelayMs: 1000, maxDelayMs: 30000, backoff: 'exponential' }
154
+ * engine.isValidPolicy(validPolicy) // true
155
+ *
156
+ * const invalidPolicy = { maxRetries: 3, initialDelayMs: 5000, maxDelayMs: 1000, backoff: 'exponential' }
157
+ * engine.isValidPolicy(invalidPolicy) // false (maxDelayMs < initialDelayMs)
158
+ * ```
159
+ */
160
+ isValidPolicy(policy: RetryPolicy): boolean;
161
+ /**
162
+ * 獲取人類可讀的重試信息
163
+ *
164
+ * @param attemptCount - 當前嘗試次數(從 1 開始)
165
+ * @param policy - 重試策略配置
166
+ * @returns 描述性文本
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const policy = { maxRetries: 3, initialDelayMs: 1000, maxDelayMs: 30000, backoff: 'exponential' }
171
+ *
172
+ * engine.getRetryInfo(1, policy) // "Retry 1 of 3, will retry in ~1100ms"
173
+ * engine.getRetryInfo(3, policy) // "Retry 3 of 3 (final attempt), will retry in ~4400ms"
174
+ * engine.getRetryInfo(4, policy) // "Max retries exceeded (4 >= 3)"
175
+ * ```
176
+ */
177
+ getRetryInfo(attemptCount: number, policy: RetryPolicy): string;
178
+ }
179
+ /**
180
+ * 創建默認的重試策略
181
+ *
182
+ * @returns 默認重試策略
183
+ *
184
+ * @description
185
+ * 默認配置:
186
+ * - 最多重試 3 次
187
+ * - 指數退避
188
+ * - 初始延遲 1 秒
189
+ * - 最大延遲 30 秒
190
+ * - 超過最大重試後發送 DLQ
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * const policy = getDefaultRetryPolicy()
195
+ * // { maxRetries: 3, backoff: 'exponential', initialDelayMs: 1000, maxDelayMs: 30000, dlqAfterMaxRetries: true }
196
+ * ```
197
+ */
198
+ export declare function getDefaultRetryPolicy(): RetryPolicy;
199
+ /**
200
+ * 為不同類型的操作獲取預設的重試策略
201
+ *
202
+ * @param type - 操作類型
203
+ * @returns 推薦的重試策略
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // 外部 API 調用:更多重試,更長延遲
208
+ * const apiPolicy = getPresetRetryPolicy('external-api')
209
+ *
210
+ * // 數據庫操作:較少重試,短延遲
211
+ * const dbPolicy = getPresetRetryPolicy('database')
212
+ *
213
+ * // 消息隊列:適中重試
214
+ * const mqPolicy = getPresetRetryPolicy('message-queue')
215
+ * ```
216
+ */
217
+ export declare function getPresetRetryPolicy(type: 'external-api' | 'database' | 'message-queue' | 'default'): RetryPolicy;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Reliability and retry exports.
3
+ * @packageDocumentation
4
+ */
5
+ export { DeadLetterQueueManager, type DLQManagerFilter, type DLQRecord, type DLQStats, } from './DeadLetterQueueManager';
6
+ export { getDefaultRetryPolicy, getPresetRetryPolicy, RetryEngine, type RetryPolicy, } from './RetryPolicy';
@@ -0,0 +1,12 @@
1
+ import type { GravitoHandler } from '../http/types';
2
+ import type { PlanetCore } from '../PlanetCore';
3
+ import type { ControllerClass } from '../Router';
4
+ export declare class ControllerDispatcher {
5
+ private core;
6
+ private controllers;
7
+ constructor(core: PlanetCore);
8
+ /**
9
+ * Resolve Controller Instance and Method
10
+ */
11
+ resolve(CtrlClass: ControllerClass, methodName: string): GravitoHandler;
12
+ }
@@ -0,0 +1,20 @@
1
+ import type { GravitoMiddleware } from '../http/types';
2
+ import { type FormRequestClass } from '../Router';
3
+ /**
4
+ * Handles validation of incoming requests using FormRequest classes.
5
+ * Provides mechanisms to detect and convert FormRequest classes into Gravito middleware.
6
+ */
7
+ export declare class RequestValidator {
8
+ /**
9
+ * Check if a value is a FormRequest class.
10
+ * Optimized with Symbol check, prototype check, and caching.
11
+ * @internal
12
+ */
13
+ static isFormRequestClass(value: unknown): value is FormRequestClass;
14
+ /**
15
+ * Convert a FormRequest class to middleware.
16
+ * Uses instance caching to avoid re-instantiation on every request.
17
+ * @internal
18
+ */
19
+ static formRequestToMiddleware(RequestClass: FormRequestClass): GravitoMiddleware;
20
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Bun runtime adapter implementation.
3
+ *
4
+ * @module runtime/adapter-bun
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for the Bun runtime.
10
+ * @internal
11
+ */
12
+ export declare function createBunAdapter(): RuntimeAdapter;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Deno runtime adapter implementation.
3
+ *
4
+ * @module runtime/adapter-deno
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for the Deno runtime.
10
+ * @internal
11
+ */
12
+ export declare function createDenoAdapter(): RuntimeAdapter;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Node.js runtime adapter implementation.
3
+ *
4
+ * @module runtime/adapter-node
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for the Node.js runtime.
10
+ * @internal
11
+ */
12
+ export declare function createNodeAdapter(): RuntimeAdapter;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Unknown runtime adapter implementation (fallback).
3
+ *
4
+ * @module runtime/adapter-unknown
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for unsupported runtimes.
10
+ * All methods throw with descriptive error messages.
11
+ * @internal
12
+ */
13
+ export declare function createUnknownAdapter(): RuntimeAdapter;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Runtime archive adapter implementations.
3
+ *
4
+ * @module runtime/archive
5
+ * @since 3.2.0
6
+ */
7
+ import type { ArchiveFromDirectoryOptions, RuntimeArchiveAdapter } from './types';
8
+ /**
9
+ * 取得封裝操作 adapter
10
+ * @public
11
+ */
12
+ export declare function getArchiveAdapter(): RuntimeArchiveAdapter;
13
+ /**
14
+ * 將目錄封裝為歸檔檔案
15
+ * @public
16
+ */
17
+ export declare function archiveFromDirectory(dirPath: string, archivePath: string, options?: ArchiveFromDirectoryOptions): Promise<Uint8Array>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Runtime compression adapter implementations.
3
+ *
4
+ * Provides unified gzip/deflate compression across Bun and Node.js runtimes.
5
+ * Bun uses native C++ implementations (Bun.gzipSync etc.) for 2-5x better performance.
6
+ * Node.js falls back to the standard node:zlib module.
7
+ *
8
+ * @module runtime/compression
9
+ * @since 3.2.0
10
+ */
11
+ import type { RuntimeCompressionAdapter } from './types';
12
+ /**
13
+ * 取得壓縮操作 adapter(依運行時自動選擇最佳實作)
14
+ *
15
+ * - Bun: 使用原生 C++ 壓縮(2-5x 更快)
16
+ * - Node.js: 使用 node:zlib
17
+ * - Deno/Unknown: 拋出錯誤
18
+ *
19
+ * @public
20
+ */
21
+ export declare function getCompressionAdapter(): RuntimeCompressionAdapter;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Deep equality comparison abstraction.
3
+ *
4
+ * Provides unified deep equality checking across Bun, Node.js, and Deno runtimes.
5
+ * Uses Bun.deepEquals() when available, falls back to recursive comparison.
6
+ *
7
+ * @module runtime/deep-equals
8
+ * @since 3.2.0
9
+ */
10
+ /**
11
+ * Options for deep equality comparison.
12
+ * @public
13
+ */
14
+ export interface DeepEqualsOptions {
15
+ /**
16
+ * When true, uses strict equality semantics:
17
+ * - NaN !== NaN
18
+ * - +0 !== -0
19
+ *
20
+ * When false (default), uses lenient semantics:
21
+ * - NaN === NaN
22
+ * - +0 === -0
23
+ */
24
+ strict?: boolean;
25
+ }
26
+ /**
27
+ * Function signature for deep equality comparison.
28
+ * @public
29
+ */
30
+ export type DeepEqualsFn = (a: unknown, b: unknown, options?: DeepEqualsOptions) => boolean;
31
+ /**
32
+ * Get the optimized deep equality comparison function for the current runtime.
33
+ *
34
+ * - **Bun**: Uses native Bun.deepEquals() for maximum performance (C++ optimized)
35
+ * - **Node.js/Deno/Unknown**: Uses fallback recursive implementation with cycle detection
36
+ *
37
+ * Results are cached after first invocation for efficiency.
38
+ *
39
+ * @returns A function that performs deep equality comparison
40
+ * @public
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const deepEquals = getDeepEquals()
45
+ *
46
+ * const obj1 = { a: [1, 2], b: { c: 3 } }
47
+ * const obj2 = { a: [1, 2], b: { c: 3 } }
48
+ *
49
+ * console.log(deepEquals(obj1, obj2)) // true
50
+ *
51
+ * // Strict mode for +0 / -0 and NaN
52
+ * console.log(deepEquals(NaN, NaN)) // true (lenient)
53
+ * console.log(deepEquals(NaN, NaN, { strict: true })) // false
54
+ * ```
55
+ */
56
+ export declare function getDeepEquals(): DeepEqualsFn;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Runtime detection utilities.
3
+ *
4
+ * @module runtime/detection
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeKind } from './types';
8
+ /**
9
+ * Detect the current JavaScript runtime environment.
10
+ * @internal
11
+ */
12
+ export declare function getRuntimeKind(): RuntimeKind;
13
+ /**
14
+ * Get environment variables from the current runtime.
15
+ * @public
16
+ */
17
+ export declare function getRuntimeEnv(): Record<string, string | undefined>;
18
+ /**
19
+ * Convert various data types to Uint8Array.
20
+ * @internal
21
+ */
22
+ export declare function toUint8Array(data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Runtime HTML escape abstraction.
3
+ *
4
+ * Provides unified HTML escaping across Bun, Node.js, and Deno runtimes.
5
+ * Bun uses the native C++ `Bun.escapeHTML()` for 10-100x better performance.
6
+ * Node.js/Deno fall back to manual entity replacement.
7
+ *
8
+ * @module runtime/escape
9
+ * @since 3.4.0
10
+ */
11
+ /**
12
+ * HTML escape function type.
13
+ * @public
14
+ */
15
+ export type EscapeHtmlFn = (value: string) => string;
16
+ /**
17
+ * Get the HTML escape function (auto-selects best implementation based on runtime).
18
+ *
19
+ * - Bun: Uses native C++ `Bun.escapeHTML()` (10-100x faster, SIMD accelerated)
20
+ * - Node.js/Deno/Unknown: Uses .replace() chain fallback with same behavior
21
+ *
22
+ * @returns HTML escape function
23
+ * @public
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { getEscapeHtml } from '@gravito/core'
28
+ *
29
+ * const escapeHtml = getEscapeHtml()
30
+ * const safe = escapeHtml('<script>alert("xss")</script>')
31
+ * // '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;'
32
+ * ```
33
+ */
34
+ export declare function getEscapeHtml(): EscapeHtmlFn;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Browser-safe runtime abstraction module.
3
+ */
4
+ import type { RuntimeAdapter, RuntimePasswordAdapter, RuntimeSqliteDatabase } from './types';
5
+ export { getRuntimeEnv, getRuntimeKind } from './detection';
6
+ export * from './types';
7
+ export declare function getRuntimeAdapter(): RuntimeAdapter;
8
+ export declare function getPasswordAdapter(): RuntimePasswordAdapter;
9
+ export declare function createSqliteDatabase(_path: string): Promise<RuntimeSqliteDatabase>;
10
+ export declare function archiveFromDirectory(): Promise<void>;
11
+ export declare function getArchiveAdapter(): void;
12
+ export declare function getCompressionAdapter(): void;
13
+ export declare function createHtmlRenderCallbacks(): void;
14
+ export declare function getMarkdownAdapter(): void;
15
+ export declare function getDeepEquals(): (a: any, b: any) => boolean;
16
+ export declare function getEscapeHtml(): (str: string) => string;
17
+ /**
18
+ * Convert various data types to Uint8Array.
19
+ */
20
+ export declare function toUint8Array(data: Blob | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Runtime abstraction module.
3
+ *
4
+ * Provides unified APIs for filesystem, process, archive, and compression
5
+ * operations across Bun, Node.js, and Deno runtimes.
6
+ *
7
+ * @module runtime
8
+ * @since 3.2.0
9
+ */
10
+ import type { RuntimeAdapter, RuntimePasswordAdapter, RuntimeSqliteDatabase } from './types';
11
+ export type { ArchiveCreateOptions, ArchiveEntry, ArchiveExtractOptions, ArchiveFileInfo, ArchiveFromDirectoryOptions, CompressionOptions, MarkdownRenderCallbacks, MarkdownRenderOptions, OptionalRuntimeResourceUsage, RuntimeAdapter, RuntimeArchiveAdapter, RuntimeCompressionAdapter, RuntimeFileSink, RuntimeFileStat, RuntimeKind, RuntimeMarkdownAdapter, RuntimePasswordAdapter, RuntimeProcess, RuntimeProcessOutput, RuntimeResourceUsage, RuntimeServeConfig, RuntimeServer, RuntimeSpawnOptions, RuntimeSpawnSyncResult, RuntimeSqliteDatabase, RuntimeSqliteStatement, } from './types';
12
+ export { getRuntimeEnv, getRuntimeKind } from './detection';
13
+ export { archiveFromDirectory, getArchiveAdapter, } from './archive';
14
+ export { getCompressionAdapter } from './compression';
15
+ export { createHtmlRenderCallbacks, getMarkdownAdapter } from './markdown';
16
+ export type { DeepEqualsFn, DeepEqualsOptions } from './deep-equals';
17
+ export { getDeepEquals } from './deep-equals';
18
+ export type { EscapeHtmlFn } from './escape';
19
+ export { getEscapeHtml } from './escape';
20
+ /**
21
+ * Get the runtime abstraction adapter (Bun/Node/Deno).
22
+ * @public
23
+ */
24
+ export declare function getRuntimeAdapter(): RuntimeAdapter;
25
+ /**
26
+ * Reset the runtime adapter (mainly for testing).
27
+ * @internal
28
+ */
29
+ export declare function resetRuntimeAdapter(): void;
30
+ /**
31
+ * Get the password hashing adapter using native optimized implementations if available.
32
+ * @public
33
+ */
34
+ export declare function getPasswordAdapter(): RuntimePasswordAdapter;
35
+ /**
36
+ * Create a SQLite database connection using runtime-native drivers.
37
+ * @public
38
+ */
39
+ export declare function createSqliteDatabase(path: string): Promise<RuntimeSqliteDatabase>;
40
+ /**
41
+ * Convert various data types to Uint8Array.
42
+ * @internal
43
+ */
44
+ export declare function toUint8Array(data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Runtime markdown adapter implementations.
3
+ *
4
+ * Provides unified Markdown -> HTML rendering across Bun and Node.js runtimes.
5
+ * Bun uses the native C++ Markdown parser (Bun.markdown) for 10-100x better performance.
6
+ * Node.js falls back to the `marked` library (lazy-loaded optional dependency).
7
+ *
8
+ * @module runtime/markdown
9
+ * @since 3.3.0
10
+ */
11
+ import type { MarkdownRenderCallbacks, RuntimeMarkdownAdapter } from './types';
12
+ /**
13
+ * 建立預設的 HTML 渲染回調集合。
14
+ *
15
+ * 提供完整的 HTML 元素生成回調,產生與 `html()` 相同的 HTML 輸出。
16
+ * 使用者可透過覆寫個別回調來自訂特定元素的渲染行為(例如 XSS 防護、
17
+ * 自訂 CSS class 等),同時保留其他元素的預設 HTML 渲染。
18
+ *
19
+ * @param overrides - 要覆寫的回調。未指定的回調使用預設 HTML 渲染。
20
+ * @returns 完整的 MarkdownRenderCallbacks 物件
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // 自訂 link 和 html 渲染(XSS 防護)
25
+ * const callbacks = createHtmlRenderCallbacks({
26
+ * html: (raw) => escapeHtml(raw),
27
+ * link: (content, { href }) => `<a href="${href}" rel="noopener">${content}</a>`,
28
+ * })
29
+ * const result = adapter.render(markdown, callbacks)
30
+ * ```
31
+ *
32
+ * @public
33
+ */
34
+ export declare function createHtmlRenderCallbacks(overrides?: Partial<MarkdownRenderCallbacks>): MarkdownRenderCallbacks;
35
+ /**
36
+ * 取得 Markdown 操作 adapter(依運行時自動選擇最佳實作)
37
+ *
38
+ * - Bun: 使用原生 C++ Markdown 解析器(10-100x 更快)
39
+ * - Node.js: 使用 marked 函式庫(延遲載入 optional dependency)
40
+ * - Deno/Unknown: 拋出錯誤
41
+ *
42
+ * @public
43
+ */
44
+ export declare function getMarkdownAdapter(): RuntimeMarkdownAdapter;