@gravito/core 1.6.0 → 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 (171) 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 +758 -532
  53. package/dist/engine/index.cjs.map +22 -0
  54. package/dist/engine/index.d.ts +14 -690
  55. package/dist/engine/index.js +758 -508
  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-C4Src6NN.d.cts → http/types.d.ts} +48 -16
  129. package/dist/index.browser.d.ts +34 -0
  130. package/dist/index.cjs +12909 -9492
  131. package/dist/index.cjs.map +168 -0
  132. package/dist/index.d.ts +58 -8707
  133. package/dist/index.js +12906 -9381
  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 +23 -53
  167. package/src/ffi/native/cbor.c +1148 -0
  168. package/dist/compat-C4Src6NN.d.ts +0 -357
  169. package/dist/compat.d.cts +0 -1
  170. package/dist/engine/index.d.cts +0 -702
  171. package/dist/index.d.cts +0 -8734
@@ -0,0 +1,436 @@
1
+ /**
2
+ * Runtime abstraction type definitions.
3
+ *
4
+ * @module runtime/types
5
+ * @since 3.2.0
6
+ */
7
+ /**
8
+ * Detected Javascript Runtime Environment
9
+ * @public
10
+ */
11
+ export type RuntimeKind = 'bun' | 'node' | 'deno' | 'unknown';
12
+ /**
13
+ * Options for spawning subprocesses
14
+ * @public
15
+ */
16
+ export interface RuntimeSpawnOptions {
17
+ cwd?: string;
18
+ env?: Record<string, string | undefined>;
19
+ stdin?: 'pipe' | 'inherit' | 'ignore';
20
+ stdout?: 'pipe' | 'inherit' | 'ignore';
21
+ stderr?: 'pipe' | 'inherit' | 'ignore';
22
+ timeout?: number;
23
+ signal?: AbortSignal;
24
+ }
25
+ /**
26
+ * Resource usage statistics from subprocess
27
+ * @public
28
+ */
29
+ export interface RuntimeResourceUsage {
30
+ cpuTime?: {
31
+ user: number;
32
+ system: number;
33
+ };
34
+ maxRSS?: number;
35
+ }
36
+ /**
37
+ * Optional resource usage statistics
38
+ * @internal
39
+ */
40
+ export type OptionalRuntimeResourceUsage = RuntimeResourceUsage | undefined;
41
+ /**
42
+ * Output from spawned subprocess
43
+ * @public
44
+ */
45
+ export interface RuntimeProcessOutput {
46
+ exitCode: number;
47
+ stdout: string;
48
+ stderr: string;
49
+ success: boolean;
50
+ timedOut: boolean;
51
+ }
52
+ /**
53
+ * Synchronous subprocess result
54
+ * @public
55
+ */
56
+ export interface RuntimeSpawnSyncResult {
57
+ exitCode: number;
58
+ stdout: string;
59
+ stderr: string;
60
+ success: boolean;
61
+ timedOut: boolean;
62
+ }
63
+ /**
64
+ * Abstract subprocess interface
65
+ * @public
66
+ */
67
+ export interface RuntimeProcess {
68
+ exited: Promise<number>;
69
+ stdout?: ReadableStream<Uint8Array> | null;
70
+ stderr?: ReadableStream<Uint8Array> | null;
71
+ kill?: (signal?: string | number) => void;
72
+ unref?: () => void;
73
+ resourceUsage?: () => Promise<OptionalRuntimeResourceUsage>;
74
+ }
75
+ /**
76
+ * File statistics abstraction
77
+ * @public
78
+ */
79
+ export interface RuntimeFileStat {
80
+ size: number;
81
+ }
82
+ /**
83
+ * HTTP Server configuration
84
+ * @public
85
+ */
86
+ export interface RuntimeServeConfig {
87
+ port?: number;
88
+ fetch: (req: Request, server?: unknown) => Response | Promise<Response>;
89
+ websocket?: unknown;
90
+ }
91
+ /**
92
+ * HTTP Server interface
93
+ * @public
94
+ */
95
+ export interface RuntimeServer {
96
+ stop?: () => void;
97
+ }
98
+ /**
99
+ * Incremental file writing interface (FileSink abstraction)
100
+ * @public
101
+ */
102
+ export interface RuntimeFileSink {
103
+ /** Write data to the file sink */
104
+ write(data: string | Uint8Array | ArrayBuffer): void;
105
+ /** Flush buffered data to disk */
106
+ flush(): Promise<void>;
107
+ /** Close the sink and flush remaining data */
108
+ end(): Promise<void>;
109
+ }
110
+ /**
111
+ * Abstraction layer for filesystem and process operations across runtimes.
112
+ * @public
113
+ */
114
+ export interface RuntimeAdapter {
115
+ kind: RuntimeKind;
116
+ spawn(command: string[], options?: RuntimeSpawnOptions): RuntimeProcess;
117
+ spawnAndCollect(command: string[], options?: RuntimeSpawnOptions): Promise<RuntimeProcessOutput>;
118
+ spawnSync(command: string[], options?: Omit<RuntimeSpawnOptions, 'signal'>): RuntimeSpawnSyncResult;
119
+ writeFile(path: string, data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<void>;
120
+ readFile(path: string): Promise<Uint8Array>;
121
+ readFileAsBlob(path: string): Promise<Blob>;
122
+ exists(path: string): Promise<boolean>;
123
+ stat(path: string): Promise<RuntimeFileStat>;
124
+ deleteFile(path: string): Promise<void>;
125
+ serve(config: RuntimeServeConfig): RuntimeServer;
126
+ /** Append data to a file (optional) */
127
+ appendFile?(path: string, data: string | Uint8Array): Promise<void>;
128
+ /** Read file as UTF-8 text (optional) */
129
+ readFileAsText?(path: string): Promise<string>;
130
+ /** Read and parse JSON file (optional) */
131
+ readFileAsJSON?<T = unknown>(path: string): Promise<T>;
132
+ /** Create directory (optional) */
133
+ mkdir?(path: string, options?: {
134
+ recursive?: boolean;
135
+ }): Promise<void>;
136
+ /** Read directory contents (optional) */
137
+ readDir?(path: string): Promise<Array<{
138
+ name: string;
139
+ isFile: boolean;
140
+ isDirectory: boolean;
141
+ }>>;
142
+ /** Get full file statistics including modification time (optional) */
143
+ statFull?(path: string): Promise<{
144
+ size: number;
145
+ mtimeMs: number;
146
+ isFile: boolean;
147
+ isDirectory: boolean;
148
+ }>;
149
+ /** Rename/move a file (optional) */
150
+ rename?(oldPath: string, newPath: string): Promise<void>;
151
+ /** Create an incremental file writer (FileSink) (optional) */
152
+ createFileSink?(path: string): RuntimeFileSink;
153
+ /** Recursively remove a directory (optional) */
154
+ removeRecursive?(path: string): Promise<void>;
155
+ /** Create/write a file exclusively (atomic) (optional) */
156
+ writeFileExclusive?(path: string, data: string | Uint8Array): Promise<void>;
157
+ }
158
+ /**
159
+ * Abstraction layer for password hashing
160
+ * @public
161
+ */
162
+ export interface RuntimePasswordAdapter {
163
+ hash(value: string, options: {
164
+ algorithm: 'bcrypt';
165
+ cost?: number;
166
+ } | {
167
+ algorithm: 'argon2id';
168
+ memoryCost?: number;
169
+ timeCost?: number;
170
+ parallelism?: number;
171
+ }): Promise<string>;
172
+ verify(value: string, hashed: string): Promise<boolean>;
173
+ }
174
+ /**
175
+ * SQLite Statement abstraction
176
+ * @public
177
+ */
178
+ export interface RuntimeSqliteStatement {
179
+ run(params?: Record<string, unknown>): void;
180
+ get(params?: Record<string, unknown>): unknown;
181
+ all(params?: Record<string, unknown>): unknown[];
182
+ }
183
+ /**
184
+ * SQLite Database abstraction
185
+ * @public
186
+ */
187
+ export interface RuntimeSqliteDatabase {
188
+ run(sql: string): void;
189
+ prepare(sql: string): RuntimeSqliteStatement;
190
+ query(sql: string): RuntimeSqliteStatement;
191
+ close(): void;
192
+ }
193
+ /**
194
+ * 歸檔項目 -- 支援多種資料來源
195
+ * @public
196
+ */
197
+ export interface ArchiveEntry {
198
+ /** 歸檔中的路徑(自動正規化為正斜線) */
199
+ readonly path: string;
200
+ /** 資料內容 */
201
+ readonly data: string | Blob | ArrayBuffer | Uint8Array;
202
+ }
203
+ /**
204
+ * 歸檔建立選項
205
+ * @public
206
+ */
207
+ export interface ArchiveCreateOptions {
208
+ /** 壓縮演算法(目前僅支援 gzip) */
209
+ compress?: 'gzip';
210
+ /** 壓縮等級(1-12,預設 6) */
211
+ level?: number;
212
+ }
213
+ /**
214
+ * 歸檔提取選項
215
+ * @public
216
+ */
217
+ export interface ArchiveExtractOptions {
218
+ /** Glob 模式過濾(僅提取匹配的檔案) */
219
+ glob?: string | readonly string[];
220
+ }
221
+ /**
222
+ * 歸檔中的檔案資訊
223
+ * @public
224
+ */
225
+ export interface ArchiveFileInfo {
226
+ /** 檔案路徑 */
227
+ readonly path: string;
228
+ /** 檔案大小(bytes) */
229
+ readonly size: number;
230
+ /** 最後修改時間 */
231
+ readonly lastModified: number;
232
+ /** 讀取文字內容 */
233
+ text(): Promise<string>;
234
+ /** 讀取為 ArrayBuffer */
235
+ arrayBuffer(): Promise<ArrayBuffer>;
236
+ }
237
+ /**
238
+ * 歸檔操作的運行時抽象
239
+ * @public
240
+ */
241
+ export interface RuntimeArchiveAdapter {
242
+ /**
243
+ * 從檔案/目錄映射建立歸檔
244
+ * @param entries - 路徑到內容的映射
245
+ * @param options - 壓縮選項
246
+ * @returns 歸檔的二進位資料
247
+ */
248
+ create(entries: Record<string, string | Blob | ArrayBuffer | Uint8Array>, options?: ArchiveCreateOptions): Promise<Uint8Array>;
249
+ /**
250
+ * 提取歸檔到指定目錄
251
+ * @param data - 歸檔二進位資料
252
+ * @param targetDir - 目標目錄(自動建立)
253
+ * @param options - 提取選項(glob 過濾)
254
+ * @returns 提取的檔案數量
255
+ */
256
+ extract(data: Blob | ArrayBuffer | Uint8Array, targetDir: string, options?: ArchiveExtractOptions): Promise<number>;
257
+ /**
258
+ * 讀取歸檔中的檔案列表(不提取)
259
+ * @param data - 歸檔二進位資料
260
+ * @param glob - 可選的 glob 過濾
261
+ * @returns 路徑到檔案資訊的映射
262
+ */
263
+ list(data: Blob | ArrayBuffer | Uint8Array, glob?: string | readonly string[]): Promise<Map<string, ArchiveFileInfo>>;
264
+ /**
265
+ * 從歸檔中讀取單一檔案
266
+ * @param data - 歸檔二進位資料
267
+ * @param filePath - 檔案路徑
268
+ * @returns 檔案內容,若不存在則回傳 null
269
+ */
270
+ readFile(data: Blob | ArrayBuffer | Uint8Array, filePath: string): Promise<Uint8Array | null>;
271
+ }
272
+ /**
273
+ * 壓縮選項
274
+ * @public
275
+ */
276
+ export interface CompressionOptions {
277
+ /** 壓縮等級(1-9,預設 6) */
278
+ level?: number;
279
+ }
280
+ /**
281
+ * 壓縮操作的運行時抽象
282
+ * @public
283
+ */
284
+ export interface RuntimeCompressionAdapter {
285
+ /**
286
+ * Gzip 壓縮(同步)
287
+ * @param data - 原始資料
288
+ * @param options - 壓縮選項
289
+ * @returns 壓縮後的資料
290
+ */
291
+ gzipSync(data: Uint8Array, options?: CompressionOptions): Uint8Array;
292
+ /**
293
+ * Gzip 解壓縮(同步)
294
+ * @param data - 壓縮資料
295
+ * @returns 原始資料
296
+ */
297
+ gunzipSync(data: Uint8Array): Uint8Array;
298
+ /**
299
+ * Deflate 壓縮(同步)
300
+ * @param data - 原始資料
301
+ * @param options - 壓縮選項
302
+ * @returns 壓縮後的資料
303
+ */
304
+ deflateSync(data: Uint8Array, options?: CompressionOptions): Uint8Array;
305
+ /**
306
+ * Inflate 解壓縮(同步)
307
+ * @param data - 壓縮資料
308
+ * @returns 原始資料
309
+ */
310
+ inflateSync(data: Uint8Array): Uint8Array;
311
+ /**
312
+ * Gzip 壓縮(非同步)
313
+ * @param data - 原始資料
314
+ * @param options - 壓縮選項
315
+ * @returns 壓縮後的資料
316
+ */
317
+ gzip(data: Uint8Array, options?: CompressionOptions): Promise<Uint8Array>;
318
+ /**
319
+ * Gzip 解壓縮(非同步)
320
+ * @param data - 壓縮資料
321
+ * @returns 原始資料
322
+ */
323
+ gunzip(data: Uint8Array): Promise<Uint8Array>;
324
+ }
325
+ /**
326
+ * archiveFromDirectory 的選項
327
+ * @public
328
+ */
329
+ export interface ArchiveFromDirectoryOptions {
330
+ /** 歸檔格式 */
331
+ format?: 'tar' | 'zip';
332
+ /** 壓縮選項 */
333
+ compress?: 'gzip';
334
+ /** 壓縮等級(1-12) */
335
+ level?: number;
336
+ /** Glob 模式過濾 */
337
+ glob?: string;
338
+ }
339
+ /**
340
+ * Markdown 渲染選項
341
+ * @public
342
+ */
343
+ export interface MarkdownRenderOptions {
344
+ /** 是否啟用 GFM 擴展(表格、刪除線、任務列表)。預設 true */
345
+ gfm?: boolean;
346
+ }
347
+ /**
348
+ * Markdown render() 自訂渲染回調集合。
349
+ *
350
+ * 每個回調攔截對應的 Markdown 元素,回傳自訂 HTML 字串。
351
+ * 僅在 Bun 原生環境(Bun.markdown.render)下完全支援;
352
+ * Fallback 環境下透過 marked Renderer 模擬。
353
+ *
354
+ * @public
355
+ */
356
+ export interface MarkdownRenderCallbacks {
357
+ /** 標題回調:(content, { level }) => html */
358
+ heading?: (content: string, opts: {
359
+ level: number;
360
+ }) => string;
361
+ /** 連結回調:(content, { href, title? }) => html */
362
+ link?: (content: string, opts: {
363
+ href: string;
364
+ title?: string;
365
+ }) => string;
366
+ /** 程式碼區塊回調:(code, { language? }) => html */
367
+ code?: (code: string, opts: {
368
+ language?: string;
369
+ }) => string;
370
+ /** 行內程式碼回調:(code) => html */
371
+ codespan?: (code: string) => string;
372
+ /** 圖片回調:(alt, { src, title? }) => html */
373
+ image?: (alt: string, opts: {
374
+ src: string;
375
+ title?: string;
376
+ }) => string;
377
+ /** 原始 HTML 回調:(rawHtml) => html(用於 XSS 過濾) */
378
+ html?: (rawHtml: string) => string;
379
+ /** 段落回調:(content) => html */
380
+ paragraph?: (content: string) => string;
381
+ /** 粗體回調:(content) => html */
382
+ strong?: (content: string) => string;
383
+ /** 斜體回調:(content) => html */
384
+ em?: (content: string) => string;
385
+ /** 刪除線回調:(content) => html */
386
+ del?: (content: string) => string;
387
+ /** 列表回調:(content, { ordered, start? }) => html */
388
+ list?: (content: string, opts: {
389
+ ordered: boolean;
390
+ start?: number;
391
+ }) => string;
392
+ /** 列表項回調:(content) => html */
393
+ listItem?: (content: string) => string;
394
+ /** 引用區塊回調:(content) => html */
395
+ blockquote?: (content: string) => string;
396
+ /** 表格回調:(content) => html */
397
+ table?: (content: string) => string;
398
+ /** 水平線回調:() => html */
399
+ hr?: () => string;
400
+ }
401
+ /**
402
+ * Markdown 操作的運行時抽象
403
+ * @public
404
+ */
405
+ export interface RuntimeMarkdownAdapter {
406
+ /**
407
+ * 將 Markdown 轉換為 HTML 字串。
408
+ * 在 Bun 環境下使用原生 C++ 解析器(10-100x 更快)。
409
+ *
410
+ * @param markdown - Markdown 原始文字
411
+ * @param options - 渲染選項
412
+ * @returns HTML 字串
413
+ */
414
+ html(markdown: string, options?: MarkdownRenderOptions): string;
415
+ /**
416
+ * 使用自訂回調渲染 Markdown。
417
+ * 允許攔截個別元素的渲染過程。
418
+ *
419
+ * @param markdown - Markdown 原始文字
420
+ * @param callbacks - 自訂渲染回調
421
+ * @returns 渲染後的字串
422
+ */
423
+ render(markdown: string, callbacks?: MarkdownRenderCallbacks): string;
424
+ /**
425
+ * 將 Markdown 轉換為 React 元素結構。
426
+ * 僅在 Bun 原生環境下可用,其餘回傳 null。
427
+ *
428
+ * @param markdown - Markdown 原始文字
429
+ * @returns React 元素物件或 null
430
+ */
431
+ react(markdown: string): unknown | null;
432
+ /**
433
+ * 是否使用原生實作(Bun.markdown)
434
+ */
435
+ readonly isNative: boolean;
436
+ }
@@ -0,0 +1,67 @@
1
+ import { type RuntimeAdapter, type RuntimeFileSink } from './runtime';
2
+ /**
3
+ * Safe append file operation with automatic fallback to node:fs/promises if not supported
4
+ * @public
5
+ */
6
+ export declare function runtimeAppendFile(adapter: RuntimeAdapter, path: string, data: string): Promise<void>;
7
+ /**
8
+ * Safe text file reading with automatic fallback to node:fs/promises if not supported
9
+ * @public
10
+ */
11
+ export declare function runtimeReadText(adapter: RuntimeAdapter, path: string): Promise<string>;
12
+ /**
13
+ * Safe JSON file reading with automatic fallback
14
+ * @public
15
+ */
16
+ export declare function runtimeReadJSON<T = unknown>(adapter: RuntimeAdapter, path: string): Promise<T>;
17
+ /**
18
+ * Safe directory creation with automatic fallback
19
+ * @public
20
+ */
21
+ export declare function runtimeMkdir(adapter: RuntimeAdapter, path: string, options?: {
22
+ recursive?: boolean;
23
+ }): Promise<void>;
24
+ /**
25
+ * Safe directory reading with automatic fallback
26
+ * @public
27
+ */
28
+ export declare function runtimeReadDir(adapter: RuntimeAdapter, path: string): Promise<Array<{
29
+ name: string;
30
+ isFile: boolean;
31
+ isDirectory: boolean;
32
+ }>>;
33
+ /**
34
+ * Safe full file statistics reading with automatic fallback
35
+ * @public
36
+ */
37
+ export declare function runtimeStatFull(adapter: RuntimeAdapter, path: string): Promise<{
38
+ size: number;
39
+ mtimeMs: number;
40
+ isFile: boolean;
41
+ isDirectory: boolean;
42
+ }>;
43
+ /**
44
+ * Safe file rename/move with automatic fallback
45
+ * @public
46
+ */
47
+ export declare function runtimeRename(adapter: RuntimeAdapter, oldPath: string, newPath: string): Promise<void>;
48
+ /**
49
+ * Safe file sink creation with automatic fallback
50
+ * @public
51
+ */
52
+ export declare function runtimeCreateFileSink(adapter: RuntimeAdapter, path: string): RuntimeFileSink;
53
+ /**
54
+ * Safe recursive directory removal with automatic fallback
55
+ * @public
56
+ */
57
+ export declare function runtimeRemoveRecursive(adapter: RuntimeAdapter, path: string): Promise<void>;
58
+ /**
59
+ * Safe exclusive file write with automatic fallback
60
+ * @public
61
+ */
62
+ export declare function runtimeWriteFileExclusive(adapter: RuntimeAdapter, path: string, data: string | Uint8Array): Promise<void>;
63
+ /**
64
+ * Get default runtime adapter instance
65
+ * @public
66
+ */
67
+ export declare function getDefaultRuntimeAdapter(): RuntimeAdapter;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Runtime abstraction module (barrel re-export).
3
+ *
4
+ * This file re-exports all runtime types and functions from the
5
+ * modular runtime/ directory for backward compatibility.
6
+ *
7
+ * @module runtime
8
+ * @since 3.2.0
9
+ */
10
+ export type { ArchiveCreateOptions, ArchiveEntry, ArchiveExtractOptions, ArchiveFileInfo, ArchiveFromDirectoryOptions, CompressionOptions, EscapeHtmlFn, MarkdownRenderCallbacks, MarkdownRenderOptions, OptionalRuntimeResourceUsage, RuntimeAdapter, RuntimeArchiveAdapter, RuntimeCompressionAdapter, RuntimeFileSink, RuntimeFileStat, RuntimeKind, RuntimeMarkdownAdapter, RuntimePasswordAdapter, RuntimeProcess, RuntimeProcessOutput, RuntimeResourceUsage, RuntimeServeConfig, RuntimeServer, RuntimeSpawnOptions, RuntimeSpawnSyncResult, RuntimeSqliteDatabase, RuntimeSqliteStatement, } from './runtime/index';
11
+ export { archiveFromDirectory, createHtmlRenderCallbacks, createSqliteDatabase, getArchiveAdapter, getCompressionAdapter, getEscapeHtml, getMarkdownAdapter, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, getRuntimeKind, toUint8Array, } from './runtime/index';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Options for the Encrypter class.
3
+ * @public
4
+ */
5
+ export interface EncrypterOptions {
6
+ key: string;
7
+ cipher?: string;
8
+ }
9
+ /**
10
+ * Service for OpenSSL encryption/decryption.
11
+ * Compatible with Laravel's encryption format.
12
+ * @public
13
+ */
14
+ export declare class Encrypter {
15
+ private algorithm;
16
+ private key;
17
+ constructor(options: EncrypterOptions);
18
+ /**
19
+ * Encrypt a value
20
+ */
21
+ encrypt(value: unknown, serialize?: boolean): string;
22
+ /**
23
+ * Decrypt a value
24
+ */
25
+ decrypt(payload: string, deserialize?: boolean): unknown;
26
+ private hash;
27
+ private validPayload;
28
+ private validMac;
29
+ /**
30
+ * Generate a new key
31
+ */
32
+ static generateKey(cipher?: string): string;
33
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Hashing interface
3
+ */
4
+ export interface Hasher {
5
+ /**
6
+ * Hash the given value
7
+ */
8
+ make(value: string, options?: Record<string, unknown>): Promise<string>;
9
+ /**
10
+ * Check the given plain value against a hash
11
+ */
12
+ check(value: string, hashedValue: string): Promise<boolean>;
13
+ /**
14
+ * Check if the given hash has been hashed using the given options
15
+ */
16
+ needsRehash(hashedValue: string, options?: Record<string, unknown>): boolean;
17
+ }
18
+ /**
19
+ * Bun Hasher
20
+ * Uses Bun's native password hashing (bcrypt by default)
21
+ */
22
+ export declare class BunHasher implements Hasher {
23
+ make(value: string, options?: {
24
+ algorithm?: 'bcrypt' | 'argon2id';
25
+ cost?: number;
26
+ }): Promise<string>;
27
+ check(value: string, hashedValue: string): Promise<boolean>;
28
+ needsRehash(_hashedValue: string, _options?: Record<string, unknown>): boolean;
29
+ }
@@ -0,0 +1,39 @@
1
+ import type { PlanetCore } from '../PlanetCore';
2
+ import { TestResponse } from './TestResponse';
3
+ /**
4
+ * HttpTester provides a way to simulate HTTP requests against a PlanetCore instance
5
+ * and returns a TestResponse for assertions.
6
+ */
7
+ export declare class HttpTester {
8
+ private core;
9
+ private cookies;
10
+ constructor(core: PlanetCore);
11
+ /**
12
+ * Make a GET request
13
+ */
14
+ get(uri: string, headers?: Record<string, string>): Promise<TestResponse>;
15
+ /**
16
+ * Make a POST request
17
+ */
18
+ post(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
19
+ /**
20
+ * Make a PUT request
21
+ */
22
+ put(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
23
+ /**
24
+ * Make a PATCH request
25
+ */
26
+ patch(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
27
+ /**
28
+ * Make a DELETE request
29
+ */
30
+ delete(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
31
+ /**
32
+ * Core call method
33
+ */
34
+ private call;
35
+ }
36
+ /**
37
+ * Helper to create an HttpTester for a PlanetCore instance
38
+ */
39
+ export declare function createHttpTester(core: PlanetCore): HttpTester;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * TestResponse wraps a standard Fetch Response and provides fluent assertion methods
3
+ * inspired by Laravel's TestResponse.
4
+ */
5
+ export declare class TestResponse {
6
+ readonly response: Response;
7
+ private _jsonData;
8
+ private _textData;
9
+ constructor(response: Response);
10
+ /**
11
+ * Assert the response status code
12
+ */
13
+ assertStatus(status: number): this;
14
+ /**
15
+ * Assert that the response has a 200 status code
16
+ */
17
+ assertOk(): this;
18
+ /**
19
+ * Assert that the response has a 201 status code
20
+ */
21
+ assertCreated(): this;
22
+ /**
23
+ * Assert that the response has a 404 status code
24
+ */
25
+ assertNotFound(): this;
26
+ /**
27
+ * Assert that the response has a 403 status code
28
+ */
29
+ assertForbidden(): this;
30
+ /**
31
+ * Assert that the response has a 401 status code
32
+ */
33
+ assertUnauthorized(): this;
34
+ /**
35
+ * Assert the response is a redirect
36
+ */
37
+ assertRedirect(uri?: string): this;
38
+ /**
39
+ * Assert that the response contains the given JSON data.
40
+ */
41
+ assertJson(data: any): Promise<this>;
42
+ /**
43
+ * Assert that the response contains exactly the given JSON data.
44
+ */
45
+ assertExactJson(data: any): Promise<this>;
46
+ /**
47
+ * Assert the structure of the JSON response.
48
+ */
49
+ assertJsonStructure(structure: any): Promise<this>;
50
+ /**
51
+ * Assert that the response contains the given string.
52
+ */
53
+ assertSee(value: string): Promise<this>;
54
+ /**
55
+ * Assert that the response does not contain the given string.
56
+ */
57
+ assertDontSee(value: string): Promise<this>;
58
+ /**
59
+ * Assert a header exists and matches value
60
+ */
61
+ assertHeader(header: string, value: string): this;
62
+ /**
63
+ * Assert a header does not exist
64
+ */
65
+ assertHeaderMissing(header: string): this;
66
+ /**
67
+ * Get the JSON content
68
+ */
69
+ getJson(): Promise<any>;
70
+ /**
71
+ * Get the text content
72
+ */
73
+ getText(): Promise<string>;
74
+ /**
75
+ * Alias for getText for standard expectations if needed
76
+ */
77
+ get body(): Promise<string>;
78
+ }
@@ -0,0 +1,2 @@
1
+ export * from './HttpTester';
2
+ export * from './TestResponse';