@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,31 @@
1
+ import type { GravitoRequest, ValidationTarget } from '../../http/types';
2
+ /**
3
+ * Bun-optimized implementation of GravitoRequest.
4
+ * @internal
5
+ */
6
+ export declare class BunRequest implements GravitoRequest {
7
+ readonly raw: Request;
8
+ private _url;
9
+ private _params;
10
+ private _query;
11
+ private _validated;
12
+ constructor(raw: Request, params?: Record<string, string>);
13
+ setParams(params: Record<string, string>): void;
14
+ get url(): string;
15
+ get method(): string;
16
+ get path(): string;
17
+ param(name: string): string | undefined;
18
+ params(): Record<string, string>;
19
+ query(name: string): string | undefined;
20
+ queries(): Record<string, string | string[]>;
21
+ header(name: string): string | undefined;
22
+ header(): Record<string, string>;
23
+ json<T = unknown>(): Promise<T>;
24
+ text(): Promise<string>;
25
+ formData(): Promise<FormData>;
26
+ arrayBuffer(): Promise<ArrayBuffer>;
27
+ parseBody<T = unknown>(): Promise<T>;
28
+ setValidated(target: ValidationTarget, data: unknown): void;
29
+ valid<T = unknown>(target: ValidationTarget): T;
30
+ private parseQuery;
31
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * WebSocket 路由管理器
3
+ *
4
+ * 負責註冊和分發 WebSocket 事件到相應的路由處理器
5
+ */
6
+ export interface WebSocketRouteHandlers {
7
+ open?: (ws: unknown) => void | Promise<void>;
8
+ message?: (ws: unknown, data: string | Buffer | Uint8Array) => void | Promise<void>;
9
+ close?: (ws: unknown, code: number, reason: string) => void | Promise<void>;
10
+ drain?: (ws: unknown) => void | Promise<void>;
11
+ }
12
+ export declare class BunWebSocketHandler {
13
+ private routes;
14
+ /**
15
+ * 註冊 WebSocket 路由
16
+ */
17
+ register(path: string, handlers: WebSocketRouteHandlers): void;
18
+ /**
19
+ * 檢查是否有該路由
20
+ * 支援精確匹配和 wildcard 匹配
21
+ */
22
+ hasRoute(path: string): boolean;
23
+ /**
24
+ * 檢查是否有任何已註冊的路由
25
+ */
26
+ hasAnyRoute(): boolean;
27
+ /**
28
+ * 將 handlers 轉換為 Bun.serve websocket config
29
+ */
30
+ toHandler(): {
31
+ open?: (ws: unknown) => void | Promise<void>;
32
+ message?: (ws: unknown, data: string | Buffer | Uint8Array) => void | Promise<void>;
33
+ close?: (ws: unknown, code: number, reason: string) => void | Promise<void>;
34
+ drain?: (ws: unknown) => void | Promise<void>;
35
+ };
36
+ /**
37
+ * 尋找符合路徑的 handler
38
+ * 優先精確匹配,再 wildcard 匹配
39
+ */
40
+ private findHandler;
41
+ /**
42
+ * 路徑匹配邏輯
43
+ * 支援:
44
+ * - 精確匹配:/chat
45
+ * - Wildcard:/api/*, /api*
46
+ */
47
+ private matchesPath;
48
+ }
@@ -0,0 +1,19 @@
1
+ import type { HttpMethod } from '../../http/types';
2
+ import { NodeType, type RouteHandler } from './types';
3
+ /**
4
+ * Node in the Radix Router tree.
5
+ * @internal
6
+ */
7
+ export declare class RadixNode {
8
+ segment: string;
9
+ type: NodeType;
10
+ children: Map<string, RadixNode>;
11
+ paramChild: RadixNode | null;
12
+ wildcardChild: RadixNode | null;
13
+ handlers: Map<HttpMethod, RouteHandler[]>;
14
+ paramName: string | null;
15
+ regex: RegExp | null;
16
+ constructor(segment?: string, type?: NodeType);
17
+ toJSON(): any;
18
+ static fromJSON(json: any): RadixNode;
19
+ }
@@ -0,0 +1,32 @@
1
+ import type { HttpMethod } from '../../http/types';
2
+ import { type RouteHandler, type RouteMatch } from './types';
3
+ /**
4
+ * High-performance Radix Tree Router for Bun
5
+ */
6
+ export declare class RadixRouter {
7
+ private root;
8
+ private globalConstraints;
9
+ private routeCache;
10
+ /**
11
+ * Add a generic parameter constraint
12
+ */
13
+ where(param: string, regex: RegExp): void;
14
+ /**
15
+ * Register a route
16
+ */
17
+ add(method: HttpMethod, path: string, handlers: RouteHandler[]): void;
18
+ /**
19
+ * Match a request
20
+ */
21
+ match(method: string, path: string): RouteMatch | null;
22
+ private matchRecursive;
23
+ private splitPath;
24
+ /**
25
+ * Serialize the router to a JSON string
26
+ */
27
+ serialize(): string;
28
+ /**
29
+ * Restore a router from a serialized JSON string
30
+ */
31
+ static fromSerialized(json: string): RadixRouter;
32
+ }
@@ -0,0 +1,7 @@
1
+ export * from './BunContext';
2
+ export * from './BunNativeAdapter';
3
+ export * from './BunRequest';
4
+ export * from './BunWebSocketHandler';
5
+ export * from './RadixNode';
6
+ export * from './RadixRouter';
7
+ export * from './types';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Route Handler type (simplified for internal use)
3
+ * In the full framework this will align with GravitoHandler
4
+ */
5
+ export type RouteHandler = Function;
6
+ /**
7
+ * Route Match Result
8
+ */
9
+ export interface RouteMatch {
10
+ handlers: RouteHandler[];
11
+ params: Record<string, string>;
12
+ }
13
+ /**
14
+ * Radix Node Type
15
+ */
16
+ export declare enum NodeType {
17
+ STATIC = 0,
18
+ PARAM = 1,
19
+ WILDCARD = 2
20
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Adapters Module
3
+ *
4
+ * Export all adapter-related types and implementations.
5
+ *
6
+ * @module @gravito/core/adapters
7
+ * @since 2.0.0
8
+ */
9
+ export * from './bun';
10
+ export { GravitoEngineAdapter } from './GravitoEngineAdapter';
11
+ export type { AdapterConfig, AdapterFactory, HttpAdapter, RouteDefinition, } from './types';
12
+ export { isHttpAdapter } from './types';
@@ -0,0 +1,235 @@
1
+ /**
2
+ * @fileoverview HTTP Adapter Interface for Gravito Framework
3
+ *
4
+ * This module defines the contract that all HTTP adapters must implement.
5
+ * By programming to this interface, Gravito can swap out the underlying
6
+ * HTTP engine without changing application code.
7
+ *
8
+ * @module @gravito/core/adapters
9
+ * @since 2.0.0
10
+ */
11
+ import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, GravitoVariables, HttpMethod } from '../http/types';
12
+ /**
13
+ * Configuration options for HTTP adapters
14
+ */
15
+ export interface AdapterConfig {
16
+ /**
17
+ * Base path prefix for all routes
18
+ * @default ''
19
+ */
20
+ basePath?: string;
21
+ /**
22
+ * Whether to enable strict routing (trailing slashes matter)
23
+ * @default false
24
+ */
25
+ strictRouting?: boolean;
26
+ /**
27
+ * Custom options passed to the underlying HTTP engine
28
+ */
29
+ engineOptions?: Record<string, unknown>;
30
+ }
31
+ /**
32
+ * Route definition structure
33
+ */
34
+ export interface RouteDefinition {
35
+ method: HttpMethod;
36
+ path: string;
37
+ handlers: (GravitoHandler | GravitoMiddleware)[];
38
+ name?: string;
39
+ middleware?: GravitoMiddleware[];
40
+ }
41
+ /**
42
+ * HttpAdapter - The core interface for HTTP engine abstraction
43
+ *
44
+ * Any HTTP engine (Photon, Express, Fastify, custom Bun implementation)
45
+ * must implement this interface to be usable with Gravito.
46
+ *
47
+ * @typeParam V - Context variables type
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Using the default Photon adapter
52
+ * import { PhotonAdapter } from '@gravito/core/adapters'
53
+ *
54
+ * const core = new PlanetCore({
55
+ * adapter: new PhotonAdapter()
56
+ * })
57
+ *
58
+ * // Using a custom adapter
59
+ * import { BunNativeAdapter } from '@gravito/adapter-bun'
60
+ *
61
+ * const core = new PlanetCore({
62
+ * adapter: new BunNativeAdapter()
63
+ * })
64
+ * ```
65
+ */
66
+ export interface HttpAdapter<V extends GravitoVariables = GravitoVariables> {
67
+ /**
68
+ * Adapter name for identification
69
+ * @example 'photon', 'bun-native', 'express'
70
+ */
71
+ readonly name: string;
72
+ /**
73
+ * Adapter version
74
+ */
75
+ readonly version: string;
76
+ /**
77
+ * Access the underlying native HTTP engine instance.
78
+ *
79
+ * ⚠️ WARNING: Using this ties your code to a specific adapter.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // For Photon adapter
84
+ * const photonApp = adapter.native as Photon
85
+ *
86
+ * // For custom Bun adapter
87
+ * const bunApp = adapter.native as BunApp
88
+ * ```
89
+ */
90
+ readonly native: unknown;
91
+ /**
92
+ * Register a route with the adapter
93
+ *
94
+ * @param method - HTTP method
95
+ * @param path - Route path (may include parameters like ':id')
96
+ * @param handlers - One or more handlers for this route (handlers or middleware)
97
+ */
98
+ route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
99
+ /**
100
+ * Register multiple routes at once
101
+ *
102
+ * @param routes - Array of route definitions
103
+ */
104
+ routes(routes: RouteDefinition[]): void;
105
+ /**
106
+ * Register a middleware for a path
107
+ *
108
+ * @param path - Path pattern to match
109
+ * @param middleware - One or more middleware functions
110
+ */
111
+ use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
112
+ /**
113
+ * Register a global middleware (applied to all routes)
114
+ *
115
+ * @param middleware - Middleware function
116
+ */
117
+ useGlobal(...middleware: GravitoMiddleware<V>[]): void;
118
+ /**
119
+ * Register a scoped middleware for Orbit-level isolation
120
+ *
121
+ * Unlike regular `use()`, this method enforces stricter scoping rules:
122
+ * - REJECTS '*' wildcard paths (prevents global middleware in Orbits)
123
+ * - ENFORCES that all middleware paths must include the scope prefix
124
+ * - Throws error if attempting to register global middleware within an Orbit scope
125
+ *
126
+ * This is designed to prevent accidental middleware cross-contamination
127
+ * when multiple Orbits are mounted to a single PlanetCore instance.
128
+ *
129
+ * @param scope - The scope/path prefix (e.g., '/api', '/blog')
130
+ * @param path - Path pattern to match (cannot be '*')
131
+ * @param middleware - One or more middleware functions
132
+ * @throws {Error} If path is '*' when in Orbit scope
133
+ * @since 2.3.0
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // Correct: Scoped to specific path
138
+ * adapter.useScoped('/api', '/users/*', authMiddleware)
139
+ *
140
+ * // Error: Cannot use wildcard in Orbit scope
141
+ * adapter.useScoped('/api', '*', loggerMiddleware)
142
+ * ```
143
+ */
144
+ useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
145
+ /**
146
+ * Mount a sub-adapter at a path
147
+ *
148
+ * @param path - Mount path
149
+ * @param subAdapter - The adapter to mount
150
+ */
151
+ mount(path: string, subAdapter: HttpAdapter<V>): void;
152
+ /**
153
+ * Set the error handler
154
+ *
155
+ * @param handler - Error handler function
156
+ */
157
+ onError(handler: GravitoErrorHandler<V>): void;
158
+ /**
159
+ * Set the not-found handler
160
+ *
161
+ * @param handler - Not-found handler function
162
+ */
163
+ onNotFound(handler: GravitoNotFoundHandler<V>): void;
164
+ /**
165
+ * The main fetch handler for serving requests.
166
+ *
167
+ * This is compatible with `Bun.serve()`, Cloudflare Workers,
168
+ * and other fetch-based runtimes.
169
+ *
170
+ * @param request - Incoming HTTP request
171
+ * @param server - Optional server context (Bun.Server, etc.)
172
+ * @returns HTTP response
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * // With Bun.serve
177
+ * Bun.serve({
178
+ * port: 3000,
179
+ * fetch: adapter.fetch
180
+ * })
181
+ * ```
182
+ */
183
+ fetch(request: Request, server?: unknown): Response | Promise<Response>;
184
+ /**
185
+ * Predictive Route Warming (JIT Optimization)
186
+ *
187
+ * Simulates requests to specified routes to trigger JIT compilation (FTL)
188
+ * before real traffic arrives.
189
+ *
190
+ * @param paths List of paths to warm up (e.g. ['/api/users', '/health'])
191
+ * @since 2.1.0
192
+ */
193
+ warmup?(paths: string[]): Promise<void>;
194
+ /**
195
+ * WebSocket Handler for Bun.serve
196
+ *
197
+ * @since 2.2.0
198
+ */
199
+ websocket?: {
200
+ open?(ws: unknown): void | Promise<void>;
201
+ message?(ws: unknown, message: string | Buffer | Uint8Array): void | Promise<void>;
202
+ close?(ws: unknown, code: number, message: string): void | Promise<void>;
203
+ drain?(ws: unknown): void | Promise<void>;
204
+ [key: string]: unknown;
205
+ };
206
+ /**
207
+ * Initialize the adapter
208
+ *
209
+ * Called during PlanetCore.boot()
210
+ */
211
+ init?(): void | Promise<void>;
212
+ /**
213
+ * Cleanup resources
214
+ *
215
+ * Called during graceful shutdown
216
+ */
217
+ shutdown?(): void | Promise<void>;
218
+ /**
219
+ * Create a GravitoContext from a raw request.
220
+ *
221
+ * This is used internally for testing and advanced scenarios.
222
+ *
223
+ * @param request - Raw HTTP request
224
+ * @returns Gravito context
225
+ */
226
+ createContext(request: Request): GravitoContext<V>;
227
+ }
228
+ /**
229
+ * Factory function type for creating adapters
230
+ */
231
+ export type AdapterFactory<V extends GravitoVariables = GravitoVariables> = (config?: AdapterConfig) => HttpAdapter<V>;
232
+ /**
233
+ * Check if a value is an HttpAdapter
234
+ */
235
+ export declare function isHttpAdapter(value: unknown): value is HttpAdapter;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * BinaryUtils - 統一的二進制轉換工具類
3
+ *
4
+ * 支援 Bun 原生 API 優化,並提供 Node.js 回退路徑。
5
+ * 設計為 isomorphic,可在 Bun 和 Node.js 環境中運行。
6
+ * @public
7
+ */
8
+ /**
9
+ * BinaryUtils - 提供統一的二進制轉換、編碼、壓縮工具
10
+ * 所有方法均為靜態方法,可直接呼叫
11
+ * @public
12
+ */
13
+ export declare class BinaryUtils {
14
+ /**
15
+ * 將各種資料類型轉換為 Uint8Array
16
+ * @param data - 輸入資料(Blob、Buffer、string、ArrayBuffer 或 Uint8Array)
17
+ * @returns Uint8Array
18
+ * @public
19
+ */
20
+ static toUint8Array(data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
21
+ /**
22
+ * 將各種資料類型轉換為 ArrayBuffer
23
+ * @param data - 輸入資料
24
+ * @returns ArrayBuffer
25
+ * @public
26
+ */
27
+ static toArrayBuffer(data: Blob | Buffer | string | Uint8Array | ArrayBuffer): Promise<ArrayBuffer>;
28
+ /**
29
+ * 將 Uint8Array 編碼為 Base64 字串
30
+ * 在 Bun 環境中使用原生 toBase64(),否則使用 Buffer
31
+ * @param data - 輸入的 Uint8Array
32
+ * @returns Base64 字串
33
+ * @public
34
+ */
35
+ static toBase64(data: Uint8Array): string;
36
+ /**
37
+ * 將 Base64 字串解碼為 Uint8Array
38
+ * @param base64 - Base64 字串
39
+ * @returns Uint8Array
40
+ * @public
41
+ */
42
+ static fromBase64(base64: string): Uint8Array;
43
+ /**
44
+ * 將 Uint8Array 編碼為 Base64URL 字串(URL 安全,無填充)
45
+ * @param data - 輸入的 Uint8Array
46
+ * @returns Base64URL 字串
47
+ * @public
48
+ */
49
+ static toBase64Url(data: Uint8Array): string;
50
+ /**
51
+ * 將 Base64URL 字串解碼為 Uint8Array
52
+ * @param base64url - Base64URL 字串
53
+ * @returns Uint8Array
54
+ * @public
55
+ */
56
+ static fromBase64Url(base64url: string): Uint8Array;
57
+ /**
58
+ * 將 Uint8Array 編碼為十六進制字串
59
+ * 在 Bun 環境中使用原生 toHex(),否則使用 Buffer
60
+ * @param data - 輸入的 Uint8Array
61
+ * @returns 十六進制字串(小寫)
62
+ * @public
63
+ */
64
+ static toHex(data: Uint8Array): string;
65
+ /**
66
+ * 將十六進制字串解碼為 Uint8Array
67
+ * @param hex - 十六進制字串
68
+ * @returns Uint8Array
69
+ * @throws {TypeError} 如果輸入不是有效的十六進制字串
70
+ * @public
71
+ */
72
+ static fromHex(hex: string): Uint8Array;
73
+ /**
74
+ * 使用 gzip 壓縮資料
75
+ * 在 Bun 環境中使用原生 Bun.gzipSync(),在 Node.js 中使用 zlib
76
+ * @param data - 輸入資料
77
+ * @param level - 壓縮等級(0-9),預設為 6
78
+ * @returns 壓縮後的 Uint8Array
79
+ * @public
80
+ */
81
+ static gzip(data: Uint8Array, level?: number): Promise<Uint8Array>;
82
+ /**
83
+ * 解壓縮 gzip 資料
84
+ * 在 Bun 環境中使用原生 Bun.gunzipSync(),在 Node.js 中使用 zlib
85
+ * @param data - gzip 壓縮的 Uint8Array
86
+ * @returns 解壓縮後的 Uint8Array
87
+ * @public
88
+ */
89
+ static gunzip(data: Uint8Array): Promise<Uint8Array>;
90
+ /**
91
+ * 將 ReadableStream<Uint8Array> 讀取為 Uint8Array
92
+ * 在 Bun 環境中使用原生 Bun.readableStreamToBytes(),否則手動讀取 chunks
93
+ * @param stream - 輸入的 ReadableStream
94
+ * @returns Uint8Array
95
+ * @public
96
+ */
97
+ static readableStreamToBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;
98
+ /**
99
+ * 將 ReadableStream<Uint8Array> 讀取為 ArrayBuffer
100
+ * @param stream - 輸入的 ReadableStream
101
+ * @returns ArrayBuffer
102
+ * @public
103
+ */
104
+ static readableStreamToArrayBuffer(stream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>;
105
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Binary utilities module for @gravito/core
3
+ * @packageDocumentation
4
+ */
5
+ export { BinaryUtils } from './BinaryUtils';
@@ -0,0 +1,6 @@
1
+ import type { CommandKernel } from '../CommandKernel';
2
+ import type { QueueDashboard } from '../observability/QueueDashboard';
3
+ /**
4
+ * Register queue management commands with CommandKernel
5
+ */
6
+ export declare function registerQueueCommands(kernel: CommandKernel, dashboard: QueueDashboard): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Browser-safe AsyncLocalStorage mock
3
+ */
4
+ export declare class AsyncLocalStorage<T> {
5
+ private store;
6
+ run<R>(store: T, fn: () => R): R;
7
+ getStore(): T | undefined;
8
+ disable(): void;
9
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Universal AsyncLocalStorage wrapper.
3
+ * Automatically switches between node:async_hooks and a browser mock.
4
+ */
5
+ export declare const AsyncLocalStorage: {
6
+ new <_T>(): any;
7
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Browser-safe crypto mock
3
+ */
4
+ export declare const randomUUID: () => string;
5
+ export declare const randomBytes: (size: number) => Buffer;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Universal Crypto wrapper.
3
+ * Automatically switches between node:crypto and globalThis.crypto.
4
+ */
5
+ export declare const randomUUID: () => string;
6
+ export declare const randomBytes: (size: number) => any;
package/dist/compat.cjs CHANGED
@@ -1,18 +1,49 @@
1
- "use strict";
1
+ // @bun @bun-cjs
2
+ (function(exports, require, module, __filename, __dirname) {var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
2
4
  var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
8
+ var __toESM = (mod, isNodeMode, target) => {
9
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
10
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
+ for (let key of __getOwnPropNames(mod))
12
+ if (!__hasOwnProp.call(to, key))
13
+ __defProp(to, key, {
14
+ get: () => mod[key],
15
+ enumerable: true
16
+ });
12
17
  return to;
13
18
  };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
20
+ var __toCommonJS = (from) => {
21
+ var entry = __moduleCache.get(from), desc;
22
+ if (entry)
23
+ return entry;
24
+ entry = __defProp({}, "__esModule", { value: true });
25
+ if (from && typeof from === "object" || typeof from === "function")
26
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
27
+ get: () => from[key],
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ }));
30
+ __moduleCache.set(from, entry);
31
+ return entry;
32
+ };
33
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
34
+ var __export = (target, all) => {
35
+ for (var name in all)
36
+ __defProp(target, name, {
37
+ get: all[name],
38
+ enumerable: true,
39
+ configurable: true,
40
+ set: (newValue) => all[name] = () => newValue
41
+ });
42
+ };
15
43
 
16
44
  // src/compat.ts
17
- var compat_exports = {};
18
- module.exports = __toCommonJS(compat_exports);
45
+ var exports_compat = {};
46
+ module.exports = __toCommonJS(exports_compat);
47
+ })
48
+
49
+ //# debugId=13536C28A77644A064756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "13536C28A77644A064756E2164756E21",
8
+ "names": []
9
+ }
package/dist/compat.d.ts CHANGED
@@ -1 +1,23 @@
1
- export { C as ContentfulStatusCode, e as Context, e as GravitoContext, c as GravitoErrorHandler, a as GravitoHandler, b as GravitoMiddleware, g as GravitoNext, d as GravitoNotFoundHandler, f as GravitoRequest, G as GravitoVariables, a as Handler, H as HttpMethod, b as MiddlewareHandler, g as Next, S as StatusCode, V as ValidationTarget, G as Variables } from './compat-CI8hiulX.js';
1
+ /**
2
+ * @fileoverview Type Compatibility Layer
3
+ *
4
+ * This module provides type aliases for backward compatibility with
5
+ * code that directly imports from Photon. Users can gradually migrate
6
+ * to the Gravito abstractions.
7
+ *
8
+ * @module @gravito/core/compat
9
+ * @since 2.0.0
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Before (Photon-coupled):
14
+ * import type { Context, MiddlewareHandler } from '@gravito/photon'
15
+ *
16
+ * // After (Gravito abstraction):
17
+ * import type { GravitoContext, GravitoMiddleware } from '@gravito/core'
18
+ *
19
+ * // Or using compat aliases during migration:
20
+ * import type { Context, MiddlewareHandler } from '@gravito/core/compat'
21
+ * ```
22
+ */
23
+ export type { ContentfulStatusCode, GravitoContext as Context, GravitoContext, GravitoErrorHandler, GravitoHandler as Handler, GravitoHandler, GravitoMiddleware as MiddlewareHandler, GravitoMiddleware, GravitoNext as Next, GravitoNext, GravitoNotFoundHandler, GravitoRequest, GravitoVariables as Variables, GravitoVariables, HttpMethod, StatusCode, ValidationTarget, } from './http/types';
package/dist/compat.js CHANGED
@@ -0,0 +1,3 @@
1
+ // @bun
2
+
3
+ //# debugId=3ADB5C7D268C6CEC64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "3ADB5C7D268C6CEC64756E2164756E21",
8
+ "names": []
9
+ }