@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,76 @@
1
+ /**
2
+ * Worker Pool Metrics Recorder for OpenTelemetry integration.
3
+ *
4
+ * Tracks Worker Pool statistics and emits OpenTelemetry metrics.
5
+ *
6
+ * @internal
7
+ */
8
+ import type { Meter } from '@opentelemetry/api';
9
+ /**
10
+ * Worker job status for metrics.
11
+ */
12
+ export declare enum WorkerJobStatus {
13
+ COMPLETED = "completed",
14
+ FAILED = "failed"
15
+ }
16
+ /**
17
+ * Stream Worker Metrics Recorder.
18
+ *
19
+ * Collects and records metrics related to Worker Pool execution:
20
+ * - Pool size and utilization
21
+ * - Job execution duration
22
+ * - Job success/failure counts
23
+ * - Queue depth
24
+ */
25
+ export declare class StreamWorkerMetrics {
26
+ private meter;
27
+ private jobDurationHistogram?;
28
+ private jobCounterCompleted?;
29
+ constructor(meter: Meter);
30
+ /**
31
+ * Initialize OpenTelemetry metrics.
32
+ */
33
+ private initializeMetrics;
34
+ /**
35
+ * Record job execution duration.
36
+ *
37
+ * @param durationSeconds - Duration in seconds
38
+ * @param status - Job status (completed or failed)
39
+ * @param queue - Queue name
40
+ */
41
+ recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
42
+ /**
43
+ * Record pool size change.
44
+ *
45
+ * @param poolSize - Current pool size
46
+ * @param callback - Optional callback to fetch pool size dynamically
47
+ */
48
+ setPoolSizeProvider(callback: () => number): void;
49
+ private poolSizeCallback?;
50
+ /**
51
+ * Get current pool size.
52
+ */
53
+ getPoolSize(): number;
54
+ /**
55
+ * Record queue depth change.
56
+ *
57
+ * @param depth - Current queue depth
58
+ * @param callback - Optional callback to fetch queue depth dynamically
59
+ */
60
+ setQueueDepthProvider(callback: () => number): void;
61
+ private queueDepthCallback?;
62
+ /**
63
+ * Get current queue depth.
64
+ */
65
+ getQueueDepth(): number;
66
+ }
67
+ /**
68
+ * Worker Metrics Recorder interface for dependency injection.
69
+ */
70
+ export interface WorkerMetricsRecorder {
71
+ recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
72
+ setPoolSizeProvider(callback: () => number): void;
73
+ setQueueDepthProvider(callback: () => number): void;
74
+ getPoolSize(): number;
75
+ getQueueDepth(): number;
76
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export { EventMetrics } from './EventMetrics';
5
+ /**
6
+ * @public
7
+ */
8
+ export { EventTracer } from './EventTracer';
9
+ /**
10
+ * @public
11
+ */
12
+ export { EventTracing, type EventTracingConfig, getEventTracing } from './EventTracing';
13
+ /**
14
+ * @public
15
+ */
16
+ export { type ObservabilityConfig, ObservableHookManager } from './ObservableHookManager';
17
+ /**
18
+ * @public
19
+ */
20
+ export { OTelEventMetrics, type QueueDepthCallback } from './OTelEventMetrics';
21
+ /**
22
+ * @public
23
+ */
24
+ export { StreamWorkerMetrics, WorkerJobStatus, type WorkerMetricsRecorder, } from './StreamWorkerMetrics';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Minimal metric types for event observability.
3
+ * Avoids importing @gravito/monitor from core to prevent circular dependency.
4
+ * Runtime implementations are provided by @gravito/monitor MetricsRegistry.
5
+ *
6
+ * @internal
7
+ */
8
+ export interface EventMetricCounter {
9
+ inc(labels: Record<string, string>): void;
10
+ }
11
+ export interface EventMetricGauge {
12
+ set(value: number, labels: Record<string, string>): void;
13
+ }
14
+ export interface EventMetricHistogram {
15
+ observe(value: number, labels: Record<string, string>): void;
16
+ }
@@ -0,0 +1,77 @@
1
+ import { BackpressureManager } from './BackpressureManager';
2
+ import type { DeadLetterQueue } from './DeadLetterQueue';
3
+ import type { OTelEventMetrics } from './observability/OTelEventMetrics';
4
+ import { type PriorityStatistics } from './PriorityEscalationManager';
5
+ import type { BackpressureStrategy, EventQueueConfig, EventTask, MultiPriorityQueueDepth } from './types';
6
+ /**
7
+ * Result of an enqueue operation.
8
+ *
9
+ * - `{ status: 'queued', id }` - Task successfully queued
10
+ * - `{ status: 'dropped' }` - Task dropped due to backpressure
11
+ * - `{ status: 'delayed', id, delayMs }` - Task should be re-enqueued after delayMs
12
+ *
13
+ * @internal
14
+ */
15
+ export type EnqueueResult = {
16
+ status: 'queued';
17
+ id: string;
18
+ } | {
19
+ status: 'dropped';
20
+ } | {
21
+ status: 'delayed';
22
+ id: string;
23
+ delayMs: number;
24
+ };
25
+ /**
26
+ * Priority queue core: manages event task queues and backpressure.
27
+ *
28
+ * Handles enqueueing, dequeuing, backpressure logic, and priority escalation.
29
+ * This class is used internally by EventPriorityQueue as a composition target.
30
+ *
31
+ * @internal
32
+ */
33
+ export declare class QueueCore {
34
+ criticalPriority: EventTask[];
35
+ highPriority: EventTask[];
36
+ normalPriority: EventTask[];
37
+ lowPriority: EventTask[];
38
+ processingPartitions: Set<string>;
39
+ private taskIdCounter;
40
+ private dlq?;
41
+ private otelEventMetrics?;
42
+ private backpressureManager?;
43
+ private priorityStats?;
44
+ private config;
45
+ constructor(config?: EventQueueConfig);
46
+ setDeadLetterQueue(dlq: DeadLetterQueue): void;
47
+ setOTelEventMetrics(metrics: OTelEventMetrics): void;
48
+ setPriorityStatistics(stats: PriorityStatistics): void;
49
+ getPriorityStatistics(): PriorityStatistics | undefined;
50
+ getBackpressureManager(): BackpressureManager | undefined;
51
+ getConfig(): EventQueueConfig;
52
+ getDLQ(): DeadLetterQueue | undefined;
53
+ createTaskId(): string;
54
+ /**
55
+ * Enqueue a task into the appropriate priority queue.
56
+ * Applies priority escalation and backpressure logic.
57
+ */
58
+ enqueue(task: EventTask): EnqueueResult;
59
+ /**
60
+ * Dequeue the next task based on priority and partition ordering.
61
+ * Priority order: CRITICAL > HIGH > NORMAL > LOW
62
+ */
63
+ dequeue(): EventTask | undefined;
64
+ /**
65
+ * Re-enqueue a task for retry.
66
+ */
67
+ enqueueRetry(task: EventTask): void;
68
+ getDepth(): number;
69
+ getDepthByPriority(priority: 'critical' | 'high' | 'normal' | 'low'): number;
70
+ getQueueDepthByPriority(): MultiPriorityQueueDepth;
71
+ clear(): void;
72
+ syncBackpressure(): void;
73
+ private handleBackpressure;
74
+ private dropOldest;
75
+ private dequeueFromPriority;
76
+ }
77
+ export type { BackpressureStrategy, EventQueueConfig, EventTask };
@@ -0,0 +1,51 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import { CircuitBreaker } from './CircuitBreaker';
3
+ import type { DeadLetterQueue } from './DeadLetterQueue';
4
+ import type { EventOptions } from './EventOptions';
5
+ import type { EventMetrics } from './observability/EventMetrics';
6
+ import type { EventTracing } from './observability/EventTracing';
7
+ import type { OTelEventMetrics } from './observability/OTelEventMetrics';
8
+ import type { RetryScheduler } from './RetryScheduler';
9
+ import type { EventTask } from './types';
10
+ /**
11
+ * Executes event tasks with circuit breaker protection, retry logic,
12
+ * exponential backoff, DLQ integration, and distributed tracing.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare class TaskExecutor {
17
+ private eventCircuitBreakers;
18
+ private eventMetrics?;
19
+ private otelEventMetrics?;
20
+ private eventTracing?;
21
+ private currentDispatchSpan?;
22
+ private retryScheduler?;
23
+ private dlq?;
24
+ private persistentDLQHandler?;
25
+ private enqueueRetryFn?;
26
+ setDeadLetterQueue(dlq: DeadLetterQueue): void;
27
+ setPersistentDLQHandler(handler: (hook: string, args: unknown, options: EventOptions, error: Error, retryCount: number, firstFailedAt: number) => Promise<void>): void;
28
+ setEventMetrics(metrics: EventMetrics): void;
29
+ setOTelEventMetrics(metrics: OTelEventMetrics): void;
30
+ setEventTracing(tracing: EventTracing): void;
31
+ setCurrentDispatchSpan(span: Span | undefined): void;
32
+ getCurrentDispatchSpan(): Span | undefined;
33
+ setRetryScheduler(scheduler: RetryScheduler): void;
34
+ getRetryScheduler(): RetryScheduler | undefined;
35
+ /**
36
+ * Set the callback to use when re-enqueueing a task after a retry delay.
37
+ */
38
+ setEnqueueRetryFn(fn: (task: EventTask) => void): void;
39
+ getCircuitBreaker(hook: string): CircuitBreaker;
40
+ getCircuitBreakers(): Map<string, CircuitBreaker>;
41
+ resetCircuitBreaker(hook: string): boolean;
42
+ /**
43
+ * Execute an event task by running all its callbacks.
44
+ * Implements circuit breaker protection, retry logic, and DLQ integration.
45
+ */
46
+ executeTask(task: EventTask, processingPartitions: Set<string>): Promise<void>;
47
+ private sendToDLQ;
48
+ private getOrCreateEventCircuitBreaker;
49
+ private calculateRetryDelay;
50
+ private executeWithTimeout;
51
+ }
@@ -0,0 +1,134 @@
1
+ import type { ActionCallback } from '../HookManager';
2
+ import type { BackpressureConfig } from './BackpressureManager';
3
+ import type { EventOptions } from './EventOptions';
4
+ /**
5
+ * Event task for priority queue processing.
6
+ * @internal
7
+ */
8
+ export interface EventTask {
9
+ /**
10
+ * Unique identifier for this event task.
11
+ */
12
+ id: string;
13
+ /**
14
+ * Event hook name.
15
+ */
16
+ hook: string;
17
+ /**
18
+ * Event payload/arguments.
19
+ */
20
+ args: unknown;
21
+ /**
22
+ * Event options.
23
+ */
24
+ options: EventOptions;
25
+ /**
26
+ * Callbacks to execute for this event.
27
+ */
28
+ callbacks: ActionCallback[];
29
+ /**
30
+ * Timestamp when the event was created.
31
+ */
32
+ createdAt: number;
33
+ /**
34
+ * Timestamp when the event was enqueued (added to the queue).
35
+ * Used for priority escalation calculations.
36
+ * @internal
37
+ */
38
+ enqueuedAt: number;
39
+ /**
40
+ * Partition key for ordering (if applicable).
41
+ */
42
+ partitionKey?: string;
43
+ /**
44
+ * Number of retry attempts made.
45
+ * @internal
46
+ */
47
+ retryCount?: number;
48
+ /**
49
+ * Timestamp when the event first failed.
50
+ * @internal
51
+ */
52
+ firstFailedAt?: number;
53
+ /**
54
+ * Last error encountered.
55
+ * @internal
56
+ */
57
+ lastError?: Error;
58
+ }
59
+ /**
60
+ * Strategy for handling backpressure when the queue is full.
61
+ */
62
+ export type BackpressureStrategy = 'reject' | 'drop-oldest' | 'drop-newest' | 'ignore';
63
+ /**
64
+ * Configuration for the event priority queue.
65
+ */
66
+ export interface EventQueueConfig {
67
+ /**
68
+ * Maximum number of pending events in the queue.
69
+ * If exceeded, the backpressure strategy is applied.
70
+ * @default undefined (unbounded)
71
+ */
72
+ maxSize?: number;
73
+ /**
74
+ * Strategy to use when the queue is full.
75
+ * - 'reject': Throw an error (default)
76
+ * - 'drop-oldest': Drop the oldest lowest-priority event
77
+ * - 'drop-newest': Drop the incoming event
78
+ * - 'ignore': Silently drop the incoming event
79
+ * @default 'reject'
80
+ */
81
+ strategy?: BackpressureStrategy;
82
+ /**
83
+ * Advanced backpressure management configuration.
84
+ * When enabled, provides state-based flow control with multi-strategy support.
85
+ * If not provided, falls back to simple strategy-based backpressure.
86
+ * @default undefined (disabled, uses simple strategy)
87
+ */
88
+ backpressure?: BackpressureConfig;
89
+ }
90
+ /**
91
+ * Multi-priority queue depth snapshot (FS-103)
92
+ * Represents the current queue depth for each priority level.
93
+ * @internal
94
+ */
95
+ export interface MultiPriorityQueueDepth {
96
+ /** Queue depth for CRITICAL priority events */
97
+ critical: number;
98
+ /** Queue depth for HIGH priority events */
99
+ high: number;
100
+ /** Queue depth for NORMAL priority events */
101
+ normal: number;
102
+ /** Queue depth for LOW priority events */
103
+ low: number;
104
+ /** Total queue depth across all priorities */
105
+ total: number;
106
+ }
107
+ /**
108
+ * Window adjustment record for backpressure feedback (FS-103)
109
+ * Records when and why the aggregation window was adjusted.
110
+ * @internal
111
+ */
112
+ export interface WindowAdjustment {
113
+ /** Timestamp of the adjustment */
114
+ timestamp: number;
115
+ /** Previous window size in milliseconds */
116
+ from: number;
117
+ /** New window size in milliseconds */
118
+ to: number;
119
+ /** Backpressure state that triggered the adjustment */
120
+ reason: string;
121
+ }
122
+ /**
123
+ * Dead letter queue routing decision (FS-103)
124
+ * Determines whether an event should be routed to the DLQ.
125
+ * @internal
126
+ */
127
+ export interface DeadLetterDecision {
128
+ /** Whether the event should be routed to DLQ */
129
+ shouldRoute: boolean;
130
+ /** Reason for the decision (if applicable) */
131
+ reason?: string;
132
+ /** Suggested retry strategy */
133
+ retryStrategy?: 'immediate' | 'delayed' | 'dlq-only';
134
+ }
@@ -0,0 +1,8 @@
1
+ import { GravitoException } from './GravitoException';
2
+ /**
3
+ * Exception thrown when authentication fails.
4
+ * @public
5
+ */
6
+ export declare class AuthenticationException extends GravitoException {
7
+ constructor(message?: string);
8
+ }
@@ -0,0 +1,8 @@
1
+ import { GravitoException } from './GravitoException';
2
+ /**
3
+ * Exception thrown when user is not authorized to perform an action.
4
+ * @public
5
+ */
6
+ export declare class AuthorizationException extends GravitoException {
7
+ constructor(message?: string);
8
+ }
@@ -0,0 +1,9 @@
1
+ import type { ServiceKey } from '../Container';
2
+ /**
3
+ * CircularDependencyException - Thrown when the container detects an infinite loop.
4
+ *
5
+ * @module @gravito/core
6
+ */
7
+ export declare class CircularDependencyException extends Error {
8
+ constructor(key: ServiceKey, stack: ServiceKey[]);
9
+ }
@@ -0,0 +1,23 @@
1
+ import type { ContentfulStatusCode } from '../http/types';
2
+ /**
3
+ * Options for creating a GravitoException
4
+ * @public
5
+ */
6
+ export interface ExceptionOptions {
7
+ message?: string;
8
+ cause?: unknown;
9
+ i18nKey?: string;
10
+ i18nParams?: Record<string, string | number>;
11
+ }
12
+ /**
13
+ * Base exception class for consistent error handling.
14
+ * @public
15
+ */
16
+ export declare abstract class GravitoException extends Error {
17
+ readonly status: ContentfulStatusCode;
18
+ readonly code: string;
19
+ readonly i18nKey?: string;
20
+ readonly i18nParams?: Record<string, string | number>;
21
+ constructor(status: number, code: string, options?: ExceptionOptions);
22
+ getLocalizedMessage(t: (key: string, params?: Record<string, string | number>) => string): string;
23
+ }
@@ -0,0 +1,9 @@
1
+ import type { ContentfulStatusCode } from '../http/types';
2
+ import { type ExceptionOptions, GravitoException } from './GravitoException';
3
+ /**
4
+ * Generic HTTP Exception
5
+ * @public
6
+ */
7
+ export declare class HttpException extends GravitoException {
8
+ constructor(status: ContentfulStatusCode, options?: ExceptionOptions);
9
+ }
@@ -0,0 +1,10 @@
1
+ import { GravitoException } from './GravitoException';
2
+ /**
3
+ * Exception thrown when a database model is not found.
4
+ * @public
5
+ */
6
+ export declare class ModelNotFoundException extends GravitoException {
7
+ readonly model: string;
8
+ readonly id?: string | number;
9
+ constructor(model: string, id?: string | number);
10
+ }
@@ -0,0 +1,22 @@
1
+ import { GravitoException } from './GravitoException';
2
+ /**
3
+ * Structure of a validation error
4
+ * @public
5
+ */
6
+ export interface ValidationError {
7
+ field: string;
8
+ message: string;
9
+ code?: string;
10
+ }
11
+ /**
12
+ * Exception thrown when data validation fails.
13
+ * @public
14
+ */
15
+ export declare class ValidationException extends GravitoException {
16
+ readonly errors: ValidationError[];
17
+ redirectTo?: string;
18
+ input?: unknown;
19
+ constructor(errors: ValidationError[], message?: string);
20
+ withRedirect(url: string): this;
21
+ withInput(input: unknown): this;
22
+ }
@@ -0,0 +1,7 @@
1
+ export * from './AuthenticationException';
2
+ export * from './AuthorizationException';
3
+ export * from './CircularDependencyException';
4
+ export * from './GravitoException';
5
+ export * from './HttpException';
6
+ export * from './ModelNotFoundException';
7
+ export * from './ValidationException';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * 原生加速器統一入口
3
+ * 遵循 Galaxy Architecture 的運行時自適應模式
4
+ * 與 RuntimeAdapter 模式保持一致
5
+ */
6
+ import type { CborAccelerator, NativeAcceleratorStatus } from './types';
7
+ /**
8
+ * 原生加速器類別
9
+ * 提供運行時自適應的 CBOR 編碼/解碼加速
10
+ * - 在 Bun 環境下優先使用 C 編譯器實現(bun:ffi)
11
+ * - 在非 Bun 環境或 FFI 不可用時自動降級到 JavaScript 實現
12
+ */
13
+ export declare class NativeAccelerator {
14
+ private static readonly DEBUG_ENV;
15
+ private static readonly DISABLE_ENV;
16
+ /**
17
+ * FFI 可用性緩存
18
+ * null: 未檢測, true: 可用, false: 不可用
19
+ */
20
+ private static available;
21
+ /**
22
+ * 當前加速器實例緩存
23
+ */
24
+ private static cborAccelerator;
25
+ /**
26
+ * 當前狀態
27
+ */
28
+ private static status;
29
+ /**
30
+ * 檢測原生 FFI 是否可用
31
+ * 偵測邏輯:
32
+ * 1. 檢查 GRAVITO_FFI_DISABLE 環境變數
33
+ * 2. 檢查 Bun 運行時可用性
34
+ * 3. 檢查 bun:ffi 的 cc() 是否可用
35
+ */
36
+ static isAvailable(): boolean;
37
+ /**
38
+ * 取得 CBOR 加速器實例
39
+ * 優先使用 Native,失敗則降級到 Fallback
40
+ */
41
+ static getCborAccelerator(): CborAccelerator;
42
+ /**
43
+ * 取得加速器狀態
44
+ */
45
+ static getStatus(): NativeAcceleratorStatus;
46
+ /**
47
+ * 重置加速器狀態(用於測試)
48
+ */
49
+ static reset(): void;
50
+ /**
51
+ * 解析 C 原始碼路徑
52
+ * 支援從原始碼目錄或 npm 套件的 src/ffi/native 目錄載入
53
+ */
54
+ private static resolveCSourcePath;
55
+ /**
56
+ * 載入原生 C 實現
57
+ * 使用 bun:ffi 的 cc() 動態編譯 C 代碼
58
+ * 優先從檔案載入完整實現,避免內聯限制
59
+ */
60
+ private static loadNativeImplementation;
61
+ /**
62
+ * 檢查是否啟用調試模式
63
+ */
64
+ private static isDebugEnabled;
65
+ /**
66
+ * 更新狀態
67
+ */
68
+ private static updateStatus;
69
+ }