@gravito/radiance 1.0.3 → 1.0.5

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 (149) hide show
  1. package/README.md +30 -7
  2. package/README.zh-TW.md +238 -3
  3. package/dist/core/src/Application.d.ts +256 -0
  4. package/dist/core/src/CommandKernel.d.ts +33 -0
  5. package/dist/core/src/ConfigManager.d.ts +65 -0
  6. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/core/src/Container.d.ts +153 -0
  9. package/dist/core/src/ErrorHandler.d.ts +66 -0
  10. package/dist/core/src/Event.d.ts +5 -0
  11. package/dist/core/src/EventManager.d.ts +123 -0
  12. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  13. package/dist/core/src/GravitoServer.d.ts +28 -0
  14. package/dist/core/src/HookManager.d.ts +435 -0
  15. package/dist/core/src/Listener.d.ts +4 -0
  16. package/dist/core/src/Logger.d.ts +20 -0
  17. package/dist/core/src/PlanetCore.d.ts +402 -0
  18. package/dist/core/src/RequestContext.d.ts +97 -0
  19. package/dist/core/src/Route.d.ts +36 -0
  20. package/dist/core/src/Router.d.ts +270 -0
  21. package/dist/core/src/ServiceProvider.d.ts +178 -0
  22. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
  23. package/dist/core/src/adapters/bun/BunContext.d.ts +54 -0
  24. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +66 -0
  25. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  26. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  27. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  28. package/dist/core/src/adapters/bun/RadixRouter.d.ts +32 -0
  29. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  30. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  31. package/dist/core/src/adapters/types.d.ts +235 -0
  32. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  33. package/dist/core/src/binary/index.d.ts +5 -0
  34. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  35. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  36. package/dist/core/src/compat/crypto.d.ts +6 -0
  37. package/dist/core/src/engine/AOTRouter.d.ts +139 -0
  38. package/dist/core/src/engine/FastContext.d.ts +141 -0
  39. package/dist/core/src/engine/Gravito.d.ts +131 -0
  40. package/dist/core/src/engine/MinimalContext.d.ts +102 -0
  41. package/dist/core/src/engine/analyzer.d.ts +113 -0
  42. package/dist/core/src/engine/constants.d.ts +23 -0
  43. package/dist/core/src/engine/index.d.ts +26 -0
  44. package/dist/core/src/engine/path.d.ts +26 -0
  45. package/dist/core/src/engine/pool.d.ts +83 -0
  46. package/dist/core/src/engine/types.d.ts +149 -0
  47. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  48. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  49. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  50. package/dist/core/src/events/DeadLetterQueue.d.ts +219 -0
  51. package/dist/core/src/events/EventBackend.d.ts +12 -0
  52. package/dist/core/src/events/EventOptions.d.ts +204 -0
  53. package/dist/core/src/events/EventPriorityQueue.d.ts +63 -0
  54. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  55. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  56. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  57. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  58. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  59. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  60. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  61. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  62. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  63. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  64. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  65. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  66. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  67. package/dist/core/src/events/index.d.ts +26 -0
  68. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  69. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  70. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  71. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +332 -0
  72. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  73. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  74. package/dist/core/src/events/observability/index.d.ts +24 -0
  75. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  76. package/dist/core/src/events/queue-core.d.ts +77 -0
  77. package/dist/core/src/events/task-executor.d.ts +51 -0
  78. package/dist/core/src/events/types.d.ts +134 -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/CircularDependencyException.d.ts +9 -0
  82. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  83. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  84. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  85. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  86. package/dist/core/src/exceptions/index.d.ts +7 -0
  87. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  88. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  89. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  90. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  91. package/dist/core/src/ffi/index.d.ts +10 -0
  92. package/dist/core/src/ffi/types.d.ts +135 -0
  93. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  94. package/dist/core/src/helpers/Arr.d.ts +19 -0
  95. package/dist/core/src/helpers/Str.d.ts +38 -0
  96. package/dist/core/src/helpers/data.d.ts +25 -0
  97. package/dist/core/src/helpers/errors.d.ts +34 -0
  98. package/dist/core/src/helpers/response.d.ts +41 -0
  99. package/dist/core/src/helpers.d.ts +338 -0
  100. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  101. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  102. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  103. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  104. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  105. package/dist/core/src/hooks/types.d.ts +107 -0
  106. package/dist/core/src/http/CookieJar.d.ts +51 -0
  107. package/dist/core/src/http/cookie.d.ts +29 -0
  108. package/dist/core/src/http/types.d.ts +395 -0
  109. package/dist/core/src/index.d.ts +565 -0
  110. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  111. package/dist/core/src/observability/contracts.d.ts +137 -0
  112. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +349 -0
  113. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  114. package/dist/core/src/reliability/index.d.ts +6 -0
  115. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  116. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  117. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  118. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  119. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  120. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  121. package/dist/core/src/runtime/archive.d.ts +17 -0
  122. package/dist/core/src/runtime/compression.d.ts +21 -0
  123. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  124. package/dist/core/src/runtime/detection.d.ts +22 -0
  125. package/dist/core/src/runtime/escape.d.ts +34 -0
  126. package/dist/core/src/runtime/index.d.ts +44 -0
  127. package/dist/core/src/runtime/markdown.d.ts +44 -0
  128. package/dist/core/src/runtime/types.d.ts +436 -0
  129. package/dist/core/src/runtime-helpers.d.ts +67 -0
  130. package/dist/core/src/runtime.d.ts +11 -0
  131. package/dist/core/src/security/Encrypter.d.ts +33 -0
  132. package/dist/core/src/security/Hasher.d.ts +29 -0
  133. package/dist/core/src/testing/HttpTester.d.ts +40 -0
  134. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  135. package/dist/core/src/testing/index.d.ts +2 -0
  136. package/dist/core/src/transpiler-utils.d.ts +170 -0
  137. package/dist/core/src/types/events.d.ts +94 -0
  138. package/dist/index.js +1 -274
  139. package/dist/index.js.map +3 -10
  140. package/dist/radiance/src/BroadcastManager.d.ts +124 -0
  141. package/dist/radiance/src/OrbitRadiance.d.ts +98 -0
  142. package/dist/radiance/src/channels/Channel.d.ts +86 -0
  143. package/dist/radiance/src/drivers/AblyDriver.d.ts +73 -0
  144. package/dist/radiance/src/drivers/BroadcastDriver.d.ts +50 -0
  145. package/dist/radiance/src/drivers/PusherDriver.d.ts +95 -0
  146. package/dist/radiance/src/drivers/RedisDriver.d.ts +83 -0
  147. package/dist/radiance/src/drivers/WebSocketDriver.d.ts +89 -0
  148. package/dist/radiance/src/index.d.ts +39 -0
  149. package/package.json +10 -6
@@ -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;
@@ -0,0 +1,338 @@
1
+ import type { ContentfulStatusCode } from './http/types';
2
+ import type { PlanetCore } from './PlanetCore';
3
+ import type { Router } from './Router';
4
+ export { Arr } from './helpers/Arr';
5
+ export * from './helpers/data';
6
+ export * from './helpers/errors';
7
+ export * from './helpers/response';
8
+ export { Str } from './helpers/Str';
9
+ /**
10
+ * Error subclass used for dump and die functionality.
11
+ * @internal
12
+ */
13
+ export declare class DumpDieError extends Error {
14
+ readonly values: unknown[];
15
+ name: string;
16
+ constructor(values: unknown[]);
17
+ }
18
+ /**
19
+ * Options for dump output
20
+ * @public
21
+ */
22
+ export type DumpOptions = {
23
+ depth?: number | null;
24
+ colors?: boolean;
25
+ };
26
+ /**
27
+ * Dump data to console for debugging.
28
+ *
29
+ * Uses `console.dir` with configurable depth and colors to provide a
30
+ * readable representation of any value.
31
+ *
32
+ * @param values - One or more values to dump to the console.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * dump(user, { meta: 'data' });
37
+ * ```
38
+ *
39
+ * @public
40
+ * @since 3.0.0
41
+ */
42
+ export declare function dump(...values: unknown[]): void;
43
+ /**
44
+ * Dump data to console and exit process (or throw in HTTP context).
45
+ *
46
+ * Short for "Dump and Die". In a CLI environment, it exits the process.
47
+ * In an HTTP context (like a web request), it throws a `DumpDieError`
48
+ * which is caught by the exception handler to display the debug output.
49
+ *
50
+ * @param values - One or more values to dump and then die.
51
+ * @throws {DumpDieError} Always throws this error to halt execution.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * dd(user.permissions);
56
+ * ```
57
+ *
58
+ * @public
59
+ * @since 3.0.0
60
+ */
61
+ export declare function dd(...values: unknown[]): never;
62
+ /**
63
+ * Tap into a value, execute a callback, and return the value.
64
+ *
65
+ * This allows you to perform "side effects" on a value without breaking
66
+ * the chain of operations.
67
+ *
68
+ * @param value - The value to tap into.
69
+ * @param callback - A callback that receives the value.
70
+ * @returns The original value.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const user = tap(new User(), (u) => {
75
+ * u.name = 'Alice';
76
+ * u.save();
77
+ * });
78
+ * ```
79
+ *
80
+ * @public
81
+ * @since 3.0.0
82
+ */
83
+ export declare function tap<T>(value: T, callback: (value: T) => unknown): T;
84
+ /**
85
+ * Return the default value of the given value.
86
+ *
87
+ * If the value is a function, it will be executed with the provided arguments
88
+ * and its result will be returned. Otherwise, the value itself is returned.
89
+ * This is useful for handling optional lazy-loaded values.
90
+ *
91
+ * @param valueOrFactory - The value or a factory function.
92
+ * @param args - Arguments to pass to the factory function if it is a function.
93
+ * @returns The resolved value.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * value(10); // 10
98
+ * value(() => 10); // 10
99
+ * value((name) => `Hello ${name}`, 'World'); // "Hello World"
100
+ * ```
101
+ *
102
+ * @public
103
+ * @since 3.0.0
104
+ */
105
+ export declare function value<TArgs extends readonly unknown[], TResult>(valueOrFactory: TResult | ((...args: TArgs) => TResult), ...args: TArgs): TResult;
106
+ /**
107
+ * Determine if the given value is "blank".
108
+ *
109
+ * A value is considered blank if it is:
110
+ * - `null` or `undefined`
111
+ * - An empty string or a string containing only whitespace
112
+ * - An empty array
113
+ * - An empty object
114
+ * - An empty Map or Set
115
+ *
116
+ * @param value - The value to check.
117
+ * @returns `true` if the value is blank, `false` otherwise.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * blank(''); // true
122
+ * blank(' '); // true
123
+ * blank([]); // true
124
+ * blank({}); // true
125
+ * blank(0); // false
126
+ * ```
127
+ *
128
+ * @public
129
+ * @since 3.0.0
130
+ */
131
+ export declare function blank(value: unknown): boolean;
132
+ /**
133
+ * Determine if the given value is "filled" (not blank).
134
+ *
135
+ * This is the inverse of `blank()`.
136
+ *
137
+ * @param value - The value to check.
138
+ * @returns `true` if the value is not blank, `false` otherwise.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * filled('hello'); // true
143
+ * filled([1, 2, 3]); // true
144
+ * filled(''); // false
145
+ * ```
146
+ *
147
+ * @public
148
+ * @since 3.0.0
149
+ */
150
+ export declare function filled(value: unknown): boolean;
151
+ /**
152
+ * Throw an exception if the given condition is true.
153
+ *
154
+ * @param condition - The condition to evaluate.
155
+ * @param error - The exception to throw, a factory function, or an error message string.
156
+ * @throws {Error} If the condition evaluates to true.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * throwIf(user.isBanned, 'User is banned from the system');
161
+ * throwIf(count > 100, () => new ValidationError('Too many items'));
162
+ * ```
163
+ *
164
+ * @public
165
+ * @since 3.0.0
166
+ */
167
+ export declare function throwIf(condition: unknown, error?: Error | string | (() => Error)): void;
168
+ /**
169
+ * Throw an exception unless the given condition is true.
170
+ *
171
+ * @param condition - The condition to evaluate.
172
+ * @param error - The exception to throw, a factory function, or an error message string.
173
+ * @throws {Error} If the condition evaluates to false.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * throwUnless(user.isAdmin, 'Unauthorized access');
178
+ * ```
179
+ *
180
+ * @public
181
+ * @since 3.0.0
182
+ */
183
+ export declare function throwUnless(condition: unknown, error?: Error | string | (() => Error)): void;
184
+ /**
185
+ * Get the value of an environment variable.
186
+ *
187
+ * Automatically detects the runtime environment (Bun or Node.js) to retrieve
188
+ * the variable.
189
+ *
190
+ * @param key - The environment variable name.
191
+ * @param defaultValue - An optional default value to return if the variable is not defined.
192
+ * @returns The environment variable value or the default value.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const debug = env('DEBUG', 'false');
197
+ * const apiKey = env('API_KEY');
198
+ * ```
199
+ *
200
+ * @public
201
+ * @since 3.0.0
202
+ */
203
+ export declare function env<TDefault = string | undefined>(key: string, defaultValue?: TDefault): string | TDefault;
204
+ /**
205
+ * Set the global application instance.
206
+ *
207
+ * This is used internally during the bootstrap process to provide global
208
+ * access to the application instance via the `app()` helper.
209
+ *
210
+ * @param core - The PlanetCore instance to set as global.
211
+ * @internal
212
+ */
213
+ export declare function setApp(core: PlanetCore | null): void;
214
+ /**
215
+ * Check if the global application instance has been initialized and set.
216
+ *
217
+ * @returns `true` if the application instance is set, `false` otherwise.
218
+ *
219
+ * @public
220
+ * @since 3.0.0
221
+ */
222
+ export declare function hasApp(): boolean;
223
+ /**
224
+ * Get the global application instance.
225
+ *
226
+ * Provides access to the core application container, configuration, and services.
227
+ *
228
+ * @returns The initialized PlanetCore instance.
229
+ * @throws {Error} If the application has not been initialized.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const core = app();
234
+ * console.log(core.version);
235
+ * ```
236
+ *
237
+ * @public
238
+ * @since 3.0.0
239
+ */
240
+ export declare function app(): PlanetCore;
241
+ /**
242
+ * Get a configuration value from the application.
243
+ *
244
+ * Supports dot notation for accessing nested configuration properties.
245
+ *
246
+ * @param key - The configuration key in dot notation (e.g., 'app.name').
247
+ * @param defaultValue - An optional default value to return if the key is not found.
248
+ * @returns The configuration value or the default value.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const appName = config('app.name');
253
+ * const port = config('app.port', 3000);
254
+ * ```
255
+ *
256
+ * @public
257
+ * @since 3.0.0
258
+ */
259
+ export declare function config<T = unknown>(key: string, defaultValue?: T): T;
260
+ /**
261
+ * Get the global logger instance.
262
+ *
263
+ * Shortcut for `app().logger`.
264
+ *
265
+ * @returns The application's logger instance.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * logger().info('Operation completed successfully');
270
+ * ```
271
+ *
272
+ * @public
273
+ * @since 3.0.0
274
+ */
275
+ export declare function logger(): import("@gravito/core").Logger;
276
+ /**
277
+ * Get the application's primary router instance.
278
+ *
279
+ * Shortcut for `app().router`.
280
+ *
281
+ * @returns The router instance.
282
+ *
283
+ * @public
284
+ * @since 3.0.0
285
+ */
286
+ export declare function router(): Router;
287
+ /**
288
+ * Abort the current request with an HTTP exception.
289
+ *
290
+ * Throws an `HttpException` with the specified status code and optional message.
291
+ *
292
+ * @param status - The HTTP status code to return.
293
+ * @param message - An optional custom error message.
294
+ * @throws {HttpException} Always throws this exception.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * abort(403, 'You do not have permission to access this resource');
299
+ * ```
300
+ *
301
+ * @public
302
+ * @since 3.0.0
303
+ */
304
+ export declare function abort(status: ContentfulStatusCode, message?: string): never;
305
+ /**
306
+ * Abort the request if the given condition is true.
307
+ *
308
+ * @param condition - The condition to evaluate.
309
+ * @param status - The HTTP status code to return.
310
+ * @param message - An optional custom error message.
311
+ * @throws {HttpException} If the condition is true.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * abortIf(!user.isActive, 403, 'Account is deactivated');
316
+ * ```
317
+ *
318
+ * @public
319
+ * @since 3.0.0
320
+ */
321
+ export declare function abortIf(condition: unknown, status: ContentfulStatusCode, message?: string): void;
322
+ /**
323
+ * Abort the request unless the given condition is true.
324
+ *
325
+ * @param condition - The condition to evaluate.
326
+ * @param status - The HTTP status code to return.
327
+ * @param message - An optional custom error message.
328
+ * @throws {HttpException} If the condition is false.
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * abortUnless(request.hasValidToken(), 401, 'Invalid authentication token');
333
+ * ```
334
+ *
335
+ * @public
336
+ * @since 3.0.0
337
+ */
338
+ export declare function abortUnless(condition: unknown, status: ContentfulStatusCode, message?: string): void;