@gravito/radiance 1.0.4 → 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 (160) hide show
  1. package/README.md +30 -7
  2. package/dist/core/src/Application.d.ts +256 -0
  3. package/dist/core/src/CommandKernel.d.ts +33 -0
  4. package/dist/core/src/ConfigManager.d.ts +65 -0
  5. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  6. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  7. package/dist/core/src/Container.d.ts +153 -0
  8. package/dist/core/src/ErrorHandler.d.ts +66 -0
  9. package/dist/core/src/Event.d.ts +5 -0
  10. package/dist/core/src/EventManager.d.ts +123 -0
  11. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  12. package/dist/core/src/GravitoServer.d.ts +28 -0
  13. package/dist/core/src/HookManager.d.ts +435 -0
  14. package/dist/core/src/Listener.d.ts +4 -0
  15. package/dist/core/src/Logger.d.ts +20 -0
  16. package/dist/core/src/PlanetCore.d.ts +408 -0
  17. package/dist/core/src/RequestContext.d.ts +97 -0
  18. package/dist/core/src/Route.d.ts +36 -0
  19. package/dist/core/src/Router.d.ts +270 -0
  20. package/dist/core/src/ServiceProvider.d.ts +178 -0
  21. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
  22. package/dist/core/src/adapters/bun/BunContext.d.ts +54 -0
  23. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +66 -0
  24. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  25. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  26. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  27. package/dist/core/src/adapters/bun/RadixRouter.d.ts +32 -0
  28. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  29. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  30. package/dist/core/src/adapters/types.d.ts +235 -0
  31. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  32. package/dist/core/src/binary/index.d.ts +5 -0
  33. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  34. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  35. package/dist/core/src/compat/crypto.d.ts +6 -0
  36. package/dist/core/src/engine/AOTRouter.d.ts +139 -0
  37. package/dist/core/src/engine/FastContext.d.ts +141 -0
  38. package/dist/core/src/engine/Gravito.d.ts +131 -0
  39. package/dist/core/src/engine/MinimalContext.d.ts +102 -0
  40. package/dist/core/src/engine/analyzer.d.ts +113 -0
  41. package/dist/core/src/engine/constants.d.ts +23 -0
  42. package/dist/core/src/engine/index.d.ts +26 -0
  43. package/dist/core/src/engine/path.d.ts +26 -0
  44. package/dist/core/src/engine/pool.d.ts +83 -0
  45. package/dist/core/src/engine/types.d.ts +149 -0
  46. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  47. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  48. package/dist/core/src/events/CircuitBreaker.d.ts +241 -0
  49. package/dist/core/src/events/DeadLetterQueue.d.ts +219 -0
  50. package/dist/core/src/events/EventBackend.d.ts +12 -0
  51. package/dist/core/src/events/EventOptions.d.ts +204 -0
  52. package/dist/core/src/events/EventPriorityQueue.d.ts +63 -0
  53. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  54. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  55. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  56. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  57. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  58. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  59. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  60. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  61. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  62. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  63. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  64. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  65. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  66. package/dist/core/src/events/index.d.ts +26 -0
  67. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  68. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  69. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  70. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +332 -0
  71. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  72. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  73. package/dist/core/src/events/observability/index.d.ts +24 -0
  74. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  75. package/dist/core/src/events/queue-core.d.ts +77 -0
  76. package/dist/core/src/events/task-executor.d.ts +51 -0
  77. package/dist/core/src/events/types.d.ts +134 -0
  78. package/dist/core/src/exceptions/AuthException.d.ts +10 -0
  79. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  80. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  81. package/dist/core/src/exceptions/CacheException.d.ts +9 -0
  82. package/dist/core/src/exceptions/CircularDependencyException.d.ts +10 -0
  83. package/dist/core/src/exceptions/ConfigurationException.d.ts +9 -0
  84. package/dist/core/src/exceptions/DatabaseException.d.ts +9 -0
  85. package/dist/core/src/exceptions/DomainException.d.ts +9 -0
  86. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  87. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  88. package/dist/core/src/exceptions/InfrastructureException.d.ts +17 -0
  89. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  90. package/dist/core/src/exceptions/QueueException.d.ts +9 -0
  91. package/dist/core/src/exceptions/StorageException.d.ts +9 -0
  92. package/dist/core/src/exceptions/StreamException.d.ts +9 -0
  93. package/dist/core/src/exceptions/SystemException.d.ts +9 -0
  94. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  95. package/dist/core/src/exceptions/index.d.ts +17 -0
  96. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  97. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  98. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  99. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  100. package/dist/core/src/ffi/index.d.ts +10 -0
  101. package/dist/core/src/ffi/types.d.ts +135 -0
  102. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  103. package/dist/core/src/helpers/Arr.d.ts +19 -0
  104. package/dist/core/src/helpers/Str.d.ts +38 -0
  105. package/dist/core/src/helpers/data.d.ts +25 -0
  106. package/dist/core/src/helpers/errors.d.ts +34 -0
  107. package/dist/core/src/helpers/response.d.ts +41 -0
  108. package/dist/core/src/helpers.d.ts +338 -0
  109. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  110. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  111. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  112. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  113. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  114. package/dist/core/src/hooks/types.d.ts +107 -0
  115. package/dist/core/src/http/CookieJar.d.ts +51 -0
  116. package/dist/core/src/http/cookie.d.ts +29 -0
  117. package/dist/core/src/http/types.d.ts +395 -0
  118. package/dist/core/src/index.d.ts +565 -0
  119. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  120. package/dist/core/src/observability/contracts.d.ts +137 -0
  121. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +349 -0
  122. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  123. package/dist/core/src/reliability/index.d.ts +6 -0
  124. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  125. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  126. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  127. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  128. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  129. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  130. package/dist/core/src/runtime/archive.d.ts +17 -0
  131. package/dist/core/src/runtime/compression.d.ts +21 -0
  132. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  133. package/dist/core/src/runtime/detection.d.ts +22 -0
  134. package/dist/core/src/runtime/escape.d.ts +34 -0
  135. package/dist/core/src/runtime/index.d.ts +44 -0
  136. package/dist/core/src/runtime/markdown.d.ts +44 -0
  137. package/dist/core/src/runtime/types.d.ts +436 -0
  138. package/dist/core/src/runtime-helpers.d.ts +67 -0
  139. package/dist/core/src/runtime.d.ts +11 -0
  140. package/dist/core/src/security/Encrypter.d.ts +33 -0
  141. package/dist/core/src/security/Hasher.d.ts +29 -0
  142. package/dist/core/src/testing/HttpTester.d.ts +40 -0
  143. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  144. package/dist/core/src/testing/index.d.ts +2 -0
  145. package/dist/core/src/transpiler-utils.d.ts +170 -0
  146. package/dist/core/src/types/events.d.ts +94 -0
  147. package/dist/index.js +3 -294
  148. package/dist/index.js.map +3 -10
  149. package/dist/radiance/src/BroadcastManager.d.ts +124 -0
  150. package/dist/radiance/src/OrbitRadiance.d.ts +98 -0
  151. package/dist/radiance/src/channels/Channel.d.ts +86 -0
  152. package/dist/radiance/src/drivers/AblyDriver.d.ts +73 -0
  153. package/dist/radiance/src/drivers/BroadcastDriver.d.ts +50 -0
  154. package/dist/radiance/src/drivers/PusherDriver.d.ts +95 -0
  155. package/dist/radiance/src/drivers/RedisDriver.d.ts +83 -0
  156. package/dist/radiance/src/drivers/WebSocketDriver.d.ts +89 -0
  157. package/dist/radiance/src/errors/RadianceError.d.ts +29 -0
  158. package/dist/radiance/src/errors/codes.d.ts +18 -0
  159. package/dist/radiance/src/index.d.ts +42 -0
  160. package/package.json +4 -2
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 雜湊加速器 JavaScript 回退實現
3
+ * 基於 node:crypto 標準庫
4
+ *
5
+ * 使用場景:
6
+ * - 非 Bun 環境(Node.js、Deno 等)
7
+ * - Bun CryptoHasher 不可用的情況
8
+ *
9
+ * 性能特性:
10
+ * - 短 key (<100 bytes):~1-2x 慢於 Bun.CryptoHasher(N-API 橋接開銷)
11
+ * - 長 payload:差異較小(主要計算時間)
12
+ * - 一致性:與 node:crypto 標準行為完全相同
13
+ */
14
+ import type { HashAccelerator } from './types';
15
+ /**
16
+ * Node.js crypto 回退實現
17
+ * 適用於非 Bun 環境
18
+ */
19
+ export declare class HashFallback implements HashAccelerator {
20
+ /**
21
+ * SHA-256 計算(回退實現)
22
+ * @param input - 輸入(字串或 Uint8Array)
23
+ * @returns 十六進制編碼的 SHA-256 雜湊值
24
+ */
25
+ sha256(input: string | Uint8Array): string;
26
+ /**
27
+ * HMAC-SHA256 計算(回退實現)
28
+ * @param key - 密鑰
29
+ * @param data - 要雜湊的數據
30
+ * @returns 十六進制編碼的 HMAC-SHA256 值
31
+ */
32
+ hmacSha256(key: string, data: string): string;
33
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * FFI (Foreign Function Interface) 模組導出
3
+ * 提供原生加速層支持(CBOR 編碼/解碼、雜湊計算)
4
+ */
5
+ export { CborFallbackDecoder, CborFallbackEncoder } from './cbor-fallback';
6
+ export { HashFallback } from './hash-fallback';
7
+ export { NativeAccelerator } from './NativeAccelerator';
8
+ export { NativeHasher } from './NativeHasher';
9
+ export type { CborAccelerator, FfiConfig, HashAccelerator, NativeAcceleratorStatus, NativeHasherStatus, } from './types';
10
+ export { CBOR_LENGTH_ENCODING, CBOR_MAJOR_TYPES, CBOR_SIMPLE_VALUES, } from './types';
@@ -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;