@gravito/echo 3.1.0 → 3.1.1
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.
- package/dist/atlas/src/DB.d.ts +51 -4
- package/dist/atlas/src/config/index.d.ts +1 -1
- package/dist/atlas/src/config/loadConfig.d.ts +0 -7
- package/dist/atlas/src/connection/Connection.d.ts +4 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +75 -6
- package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +16 -3
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +15 -2
- package/dist/atlas/src/index.d.ts +15 -3
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +22 -0
- package/dist/atlas/src/orm/Repository.d.ts +247 -0
- package/dist/atlas/src/orm/index.d.ts +1 -0
- package/dist/atlas/src/orm/model/Model.d.ts +11 -2
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +14 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +5 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +29 -0
- package/dist/atlas/src/orm/model/index.d.ts +1 -1
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +1 -0
- package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +98 -0
- package/dist/atlas/src/pool/PoolHealthChecker.d.ts +91 -0
- package/dist/atlas/src/pool/PoolStrategy.d.ts +129 -0
- package/dist/atlas/src/pool/PoolWarmer.d.ts +92 -0
- package/dist/atlas/src/query/QueryBuilder.d.ts +71 -1
- package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -0
- package/dist/atlas/src/schema/MigrationGenerator.d.ts +45 -0
- package/dist/atlas/src/schema/SchemaDiff.d.ts +73 -0
- package/dist/atlas/src/schema/TypeGenerator.d.ts +57 -0
- package/dist/atlas/src/schema/TypeWriter.d.ts +42 -0
- package/dist/atlas/src/sharding/ShardingManager.d.ts +59 -0
- package/dist/atlas/src/types/index.d.ts +83 -1
- package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -0
- package/dist/core/src/ConfigManager.d.ts +39 -0
- package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/core/src/Container.d.ts +45 -0
- package/dist/core/src/ErrorHandler.d.ts +3 -0
- package/dist/core/src/HookManager.d.ts +95 -0
- package/dist/core/src/PlanetCore.d.ts +89 -0
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/ServiceProvider.d.ts +22 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +4 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
- package/dist/core/src/cli/queue-commands.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +6 -1
- package/dist/core/src/engine/FastContext.d.ts +23 -0
- package/dist/core/src/engine/Gravito.d.ts +0 -1
- package/dist/core/src/engine/MinimalContext.d.ts +21 -0
- package/dist/core/src/engine/types.d.ts +3 -0
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/core/src/events/BackpressureManager.d.ts +215 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
- package/dist/core/src/events/EventBackend.d.ts +2 -1
- package/dist/core/src/events/EventOptions.d.ts +99 -4
- package/dist/core/src/events/EventPriorityQueue.d.ts +105 -6
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
- package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
- package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/core/src/events/RetryScheduler.d.ts +104 -0
- package/dist/core/src/events/WorkerPool.d.ts +98 -0
- package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/core/src/events/aggregation/types.d.ts +117 -0
- package/dist/core/src/events/index.d.ts +11 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +4 -0
- package/dist/core/src/events/types.d.ts +59 -0
- package/dist/core/src/health/HealthProvider.d.ts +67 -0
- package/dist/core/src/http/types.d.ts +19 -0
- package/dist/core/src/index.d.ts +13 -1
- package/dist/core/src/observability/Metrics.d.ts +244 -0
- package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +34 -0
- package/dist/monitor/src/MonitorOrbit.d.ts +43 -0
- package/dist/monitor/src/config.d.ts +106 -0
- package/dist/monitor/src/health/HealthController.d.ts +28 -0
- package/dist/monitor/src/health/HealthRegistry.d.ts +80 -0
- package/dist/monitor/src/health/index.d.ts +36 -0
- package/dist/monitor/src/index.d.ts +13 -0
- package/dist/monitor/src/metrics/MetricsController.d.ts +22 -0
- package/dist/monitor/src/metrics/MetricsRegistry.d.ts +136 -0
- package/dist/monitor/src/metrics/index.d.ts +11 -0
- package/dist/monitor/src/tracing/TracingManager.d.ts +97 -0
- package/dist/monitor/src/tracing/index.d.ts +10 -0
- package/dist/photon/src/index.d.ts +5 -0
- package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - Health Check Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages health check registrations and executions
|
|
5
|
+
*/
|
|
6
|
+
import type { HealthCheckFn, HealthCheckResult, HealthConfig } from '../config';
|
|
7
|
+
/**
|
|
8
|
+
* Aggregated health check report.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface HealthReport {
|
|
12
|
+
status: 'healthy' | 'unhealthy' | 'degraded';
|
|
13
|
+
timestamp: string;
|
|
14
|
+
uptime: number;
|
|
15
|
+
checks: Record<string, HealthCheckResult & {
|
|
16
|
+
name: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Cache statistics
|
|
21
|
+
*/
|
|
22
|
+
export interface CacheStats {
|
|
23
|
+
hits: number;
|
|
24
|
+
misses: number;
|
|
25
|
+
hitRate: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* HealthRegistry manages all health checks
|
|
29
|
+
*/
|
|
30
|
+
export declare class HealthRegistry {
|
|
31
|
+
private checks;
|
|
32
|
+
private startTime;
|
|
33
|
+
private cachedReport;
|
|
34
|
+
private cacheExpiry;
|
|
35
|
+
private timeout;
|
|
36
|
+
private cacheTtl;
|
|
37
|
+
private cacheHits;
|
|
38
|
+
private cacheMisses;
|
|
39
|
+
constructor(config?: HealthConfig);
|
|
40
|
+
/**
|
|
41
|
+
* Register a health check
|
|
42
|
+
*/
|
|
43
|
+
register(name: string, check: HealthCheckFn): this;
|
|
44
|
+
/**
|
|
45
|
+
* Unregister a health check
|
|
46
|
+
*/
|
|
47
|
+
unregister(name: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get all registered check names
|
|
50
|
+
*/
|
|
51
|
+
getCheckNames(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Execute a single health check with timeout
|
|
54
|
+
*/
|
|
55
|
+
private executeCheck;
|
|
56
|
+
/**
|
|
57
|
+
* Execute all health checks and generate report
|
|
58
|
+
*/
|
|
59
|
+
check(): Promise<HealthReport>;
|
|
60
|
+
/**
|
|
61
|
+
* Simple liveness check (is the process running?)
|
|
62
|
+
*/
|
|
63
|
+
liveness(): Promise<{
|
|
64
|
+
status: 'healthy' | 'unhealthy';
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Readiness check (is the app ready to serve traffic?)
|
|
68
|
+
* By default, requires all checks to be healthy
|
|
69
|
+
*/
|
|
70
|
+
readiness(): Promise<{
|
|
71
|
+
status: 'healthy' | 'unhealthy';
|
|
72
|
+
reason?: string;
|
|
73
|
+
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Get cache statistics
|
|
76
|
+
*
|
|
77
|
+
* Useful for monitoring cache effectiveness and tuning cacheTtl
|
|
78
|
+
*/
|
|
79
|
+
getCacheStats(): CacheStats;
|
|
80
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - Built-in Health Checks
|
|
3
|
+
*/
|
|
4
|
+
import type { HealthCheckFn } from '../config';
|
|
5
|
+
export type { CacheStats, HealthReport } from './HealthRegistry';
|
|
6
|
+
/**
|
|
7
|
+
* Create a database health check
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDatabaseCheck(connectionFn: () => Promise<boolean> | boolean): HealthCheckFn;
|
|
10
|
+
/**
|
|
11
|
+
* Create a Redis health check
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRedisCheck(pingFn: () => Promise<string> | string): HealthCheckFn;
|
|
14
|
+
/**
|
|
15
|
+
* Create a memory usage health check
|
|
16
|
+
*/
|
|
17
|
+
export declare function createMemoryCheck(options?: {
|
|
18
|
+
maxHeapUsedPercent?: number;
|
|
19
|
+
}): HealthCheckFn;
|
|
20
|
+
/**
|
|
21
|
+
* Create a custom HTTP endpoint health check
|
|
22
|
+
*/
|
|
23
|
+
export declare function createHttpCheck(url: string, options?: {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
expectedStatus?: number;
|
|
26
|
+
method?: string;
|
|
27
|
+
}): HealthCheckFn;
|
|
28
|
+
/**
|
|
29
|
+
* Create a disk space health check
|
|
30
|
+
*/
|
|
31
|
+
export declare function createDiskCheck(options?: {
|
|
32
|
+
path?: string;
|
|
33
|
+
minFreePercent?: number;
|
|
34
|
+
}): HealthCheckFn;
|
|
35
|
+
export { HealthController } from './HealthController';
|
|
36
|
+
export { HealthRegistry } from './HealthRegistry';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor
|
|
3
|
+
*
|
|
4
|
+
* Observability module for Gravito
|
|
5
|
+
* - Health Checks (Kubernetes probes)
|
|
6
|
+
* - Metrics (Prometheus format)
|
|
7
|
+
* - Tracing (OpenTelemetry OTLP)
|
|
8
|
+
*/
|
|
9
|
+
export { defineMonitorConfig, type HealthCheckFn, type HealthCheckResult, type HealthConfig, type MetricOptions, type MetricsConfig, type MonitorConfig, type TracingConfig, } from './config';
|
|
10
|
+
export { createDatabaseCheck, createDiskCheck, createHttpCheck, createMemoryCheck, createRedisCheck, HealthController, HealthRegistry, type HealthReport, } from './health';
|
|
11
|
+
export { MonitorOrbit, type MonitorService } from './MonitorOrbit';
|
|
12
|
+
export { Counter, createHttpMetricsMiddleware, Gauge, Histogram, MetricsController, MetricsRegistry, } from './metrics';
|
|
13
|
+
export { createTracingMiddleware, type Span, type SpanContext, type SpanEvent, TracingManager, } from './tracing';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - Metrics Controller
|
|
3
|
+
*/
|
|
4
|
+
import type { GravitoContext } from '@gravito/core';
|
|
5
|
+
import type { MetricsRegistry } from './MetricsRegistry';
|
|
6
|
+
/**
|
|
7
|
+
* MetricsController handles the /metrics endpoint
|
|
8
|
+
*/
|
|
9
|
+
export declare class MetricsController {
|
|
10
|
+
private registry;
|
|
11
|
+
constructor(registry: MetricsRegistry);
|
|
12
|
+
/**
|
|
13
|
+
* GET /metrics - Prometheus metrics endpoint
|
|
14
|
+
*/
|
|
15
|
+
metrics(_c: GravitoContext): Promise<Response>;
|
|
16
|
+
/**
|
|
17
|
+
* 更新 health cache metrics
|
|
18
|
+
*
|
|
19
|
+
* 從 HealthRegistry 讀取最新的 cache 統計並更新 gauges
|
|
20
|
+
*/
|
|
21
|
+
private updateHealthCacheMetrics;
|
|
22
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - Metrics Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages metric collection and Prometheus exposition
|
|
5
|
+
*/
|
|
6
|
+
import type { MetricOptions, MetricsConfig } from '../config';
|
|
7
|
+
/**
|
|
8
|
+
* Represents a single metric data point with labels.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface MetricValue {
|
|
12
|
+
value: number;
|
|
13
|
+
labels: Record<string, string>;
|
|
14
|
+
timestamp?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Counter metric - monotonically increasing value
|
|
18
|
+
*/
|
|
19
|
+
export declare class Counter {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly help: string;
|
|
22
|
+
readonly labelNames: string[];
|
|
23
|
+
private values;
|
|
24
|
+
constructor(name: string, help: string, labelNames?: string[]);
|
|
25
|
+
/**
|
|
26
|
+
* Increment the counter
|
|
27
|
+
*/
|
|
28
|
+
inc(labels?: Record<string, string>, delta?: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get current values
|
|
31
|
+
*/
|
|
32
|
+
getValues(): MetricValue[];
|
|
33
|
+
/**
|
|
34
|
+
* Reset all values
|
|
35
|
+
*/
|
|
36
|
+
reset(): void;
|
|
37
|
+
private labelsToKey;
|
|
38
|
+
private keyToLabels;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gauge metric - value that can go up or down
|
|
42
|
+
*/
|
|
43
|
+
export declare class Gauge {
|
|
44
|
+
readonly name: string;
|
|
45
|
+
readonly help: string;
|
|
46
|
+
readonly labelNames: string[];
|
|
47
|
+
private values;
|
|
48
|
+
constructor(name: string, help: string, labelNames?: string[]);
|
|
49
|
+
/**
|
|
50
|
+
* Set the gauge value
|
|
51
|
+
*/
|
|
52
|
+
set(value: number, labels?: Record<string, string>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Increment the gauge
|
|
55
|
+
*/
|
|
56
|
+
inc(labels?: Record<string, string>, delta?: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Decrement the gauge
|
|
59
|
+
*/
|
|
60
|
+
dec(labels?: Record<string, string>, delta?: number): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get current values
|
|
63
|
+
*/
|
|
64
|
+
getValues(): MetricValue[];
|
|
65
|
+
private labelsToKey;
|
|
66
|
+
private keyToLabels;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Histogram metric - tracks distribution of values
|
|
70
|
+
*/
|
|
71
|
+
export declare class Histogram {
|
|
72
|
+
readonly name: string;
|
|
73
|
+
readonly help: string;
|
|
74
|
+
readonly labelNames: string[];
|
|
75
|
+
private bucketCounts;
|
|
76
|
+
private sums;
|
|
77
|
+
private counts;
|
|
78
|
+
readonly buckets: number[];
|
|
79
|
+
constructor(name: string, help: string, labelNames?: string[], buckets?: number[]);
|
|
80
|
+
/**
|
|
81
|
+
* Observe a value
|
|
82
|
+
*/
|
|
83
|
+
observe(value: number, labels?: Record<string, string>): void;
|
|
84
|
+
/**
|
|
85
|
+
* Start a timer and return a function to stop it
|
|
86
|
+
*/
|
|
87
|
+
startTimer(labels?: Record<string, string>): () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Get values for Prometheus format
|
|
90
|
+
*/
|
|
91
|
+
getValues(): {
|
|
92
|
+
buckets: Map<string, Map<number, number>>;
|
|
93
|
+
sums: Map<string, number>;
|
|
94
|
+
counts: Map<string, number>;
|
|
95
|
+
};
|
|
96
|
+
private labelsToKey;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* MetricsRegistry manages all metrics
|
|
100
|
+
*/
|
|
101
|
+
export declare class MetricsRegistry {
|
|
102
|
+
private counters;
|
|
103
|
+
private gauges;
|
|
104
|
+
private histograms;
|
|
105
|
+
private startTime;
|
|
106
|
+
private prefix;
|
|
107
|
+
private defaultLabels;
|
|
108
|
+
private collectDefaultMetrics;
|
|
109
|
+
constructor(config?: MetricsConfig);
|
|
110
|
+
/**
|
|
111
|
+
* Create or get a counter
|
|
112
|
+
*/
|
|
113
|
+
counter(options: MetricOptions): Counter;
|
|
114
|
+
/**
|
|
115
|
+
* Create or get a gauge
|
|
116
|
+
*/
|
|
117
|
+
gauge(options: MetricOptions): Gauge;
|
|
118
|
+
/**
|
|
119
|
+
* Create or get a histogram
|
|
120
|
+
*/
|
|
121
|
+
histogram(options: MetricOptions): Histogram;
|
|
122
|
+
/**
|
|
123
|
+
* Initialize default runtime metrics
|
|
124
|
+
*/
|
|
125
|
+
private initDefaultMetrics;
|
|
126
|
+
/**
|
|
127
|
+
* Update default metrics with current values
|
|
128
|
+
*/
|
|
129
|
+
private updateDefaultMetrics;
|
|
130
|
+
/**
|
|
131
|
+
* Export metrics in Prometheus format
|
|
132
|
+
*/
|
|
133
|
+
toPrometheus(): string;
|
|
134
|
+
private formatLabels;
|
|
135
|
+
private keyToLabels;
|
|
136
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - HTTP Metrics Middleware
|
|
3
|
+
*/
|
|
4
|
+
import type { GravitoContext } from '@gravito/core';
|
|
5
|
+
import type { MetricsRegistry } from './MetricsRegistry';
|
|
6
|
+
/**
|
|
7
|
+
* Create middleware that collects HTTP metrics
|
|
8
|
+
*/
|
|
9
|
+
export declare function createHttpMetricsMiddleware(registry: MetricsRegistry): (c: GravitoContext, next: () => Promise<void>) => Promise<Response | undefined>;
|
|
10
|
+
export { MetricsController } from './MetricsController';
|
|
11
|
+
export { Counter, Gauge, Histogram, MetricsRegistry } from './MetricsRegistry';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - Tracing Manager
|
|
3
|
+
*
|
|
4
|
+
* OpenTelemetry OTLP tracing integration
|
|
5
|
+
*/
|
|
6
|
+
import type { TracingConfig } from '../config';
|
|
7
|
+
/**
|
|
8
|
+
* Span interface for tracing
|
|
9
|
+
*/
|
|
10
|
+
export interface Span {
|
|
11
|
+
name: string;
|
|
12
|
+
traceId: string;
|
|
13
|
+
spanId: string;
|
|
14
|
+
parentSpanId?: string;
|
|
15
|
+
startTime: number;
|
|
16
|
+
endTime?: number;
|
|
17
|
+
attributes: Record<string, string | number | boolean>;
|
|
18
|
+
status: 'ok' | 'error' | 'unset';
|
|
19
|
+
events: SpanEvent[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Event recorded within a span.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface SpanEvent {
|
|
26
|
+
name: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
attributes?: Record<string, string | number | boolean>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Span context for propagation
|
|
32
|
+
*/
|
|
33
|
+
export interface SpanContext {
|
|
34
|
+
traceId: string;
|
|
35
|
+
spanId: string;
|
|
36
|
+
traceFlags: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* TracingManager handles distributed tracing
|
|
40
|
+
*/
|
|
41
|
+
export declare class TracingManager {
|
|
42
|
+
private otelSdk;
|
|
43
|
+
private spans;
|
|
44
|
+
private isInitialized;
|
|
45
|
+
private serviceName;
|
|
46
|
+
private serviceVersion;
|
|
47
|
+
private endpoint;
|
|
48
|
+
private resourceAttributes;
|
|
49
|
+
constructor(config?: TracingConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Initialize OpenTelemetry SDK if available
|
|
52
|
+
*/
|
|
53
|
+
initialize(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Shutdown tracing
|
|
56
|
+
*/
|
|
57
|
+
shutdown(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Start a new span
|
|
60
|
+
*/
|
|
61
|
+
startSpan(name: string, options?: {
|
|
62
|
+
attributes?: Record<string, string | number | boolean>;
|
|
63
|
+
parentSpan?: Span;
|
|
64
|
+
}): Span;
|
|
65
|
+
/**
|
|
66
|
+
* End a span
|
|
67
|
+
*/
|
|
68
|
+
endSpan(span: Span, status?: 'ok' | 'error'): void;
|
|
69
|
+
/**
|
|
70
|
+
* Add an event to a span
|
|
71
|
+
*/
|
|
72
|
+
addEvent(span: Span, name: string, attributes?: Record<string, string | number | boolean>): void;
|
|
73
|
+
/**
|
|
74
|
+
* Set span attribute
|
|
75
|
+
*/
|
|
76
|
+
setAttribute(span: Span, key: string, value: string | number | boolean): void;
|
|
77
|
+
/**
|
|
78
|
+
* Get the currently active span
|
|
79
|
+
*/
|
|
80
|
+
getActiveSpan(): Span | null;
|
|
81
|
+
/**
|
|
82
|
+
* Extract trace context from headers
|
|
83
|
+
*/
|
|
84
|
+
extractContext(headers: Headers): SpanContext | null;
|
|
85
|
+
/**
|
|
86
|
+
* Inject trace context into headers
|
|
87
|
+
*/
|
|
88
|
+
injectContext(headers: Headers, span: Span): void;
|
|
89
|
+
/**
|
|
90
|
+
* Get all collected spans (for debugging)
|
|
91
|
+
*/
|
|
92
|
+
getSpans(): Span[];
|
|
93
|
+
/**
|
|
94
|
+
* Clear collected spans
|
|
95
|
+
*/
|
|
96
|
+
clearSpans(): void;
|
|
97
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/monitor - Tracing Middleware
|
|
3
|
+
*/
|
|
4
|
+
import type { GravitoContext } from '@gravito/core';
|
|
5
|
+
import type { TracingManager } from './TracingManager';
|
|
6
|
+
/**
|
|
7
|
+
* Create middleware that traces HTTP requests
|
|
8
|
+
*/
|
|
9
|
+
export declare function createTracingMiddleware(tracer: TracingManager): (c: GravitoContext, next: () => Promise<void>) => Promise<Response | undefined>;
|
|
10
|
+
export { type Span, type SpanContext, type SpanEvent, TracingManager } from './TracingManager';
|
|
@@ -77,6 +77,11 @@ export * from './middleware/htmx';
|
|
|
77
77
|
* @public
|
|
78
78
|
*/
|
|
79
79
|
export * from './middleware/ratelimit';
|
|
80
|
+
/**
|
|
81
|
+
* Redis-based rate limiting storage.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export * from './middleware/ratelimit-redis';
|
|
80
85
|
/**
|
|
81
86
|
* OpenAPI utilities
|
|
82
87
|
* @public
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RateLimitState, RateLimitStore } from './ratelimit';
|
|
2
|
+
/**
|
|
3
|
+
* Redis-based storage for Rate Limiting.
|
|
4
|
+
*
|
|
5
|
+
* Implements atomic rate limiting using Lua scripts to prevent race conditions
|
|
6
|
+
* in distributed environments.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This store is recommended for production environments with multiple application
|
|
10
|
+
* instances. It requires a Redis client (like ioredis or node-redis).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import Redis from 'ioredis'
|
|
15
|
+
* import { rateLimit } from '@gravito/photon/middleware'
|
|
16
|
+
* import { RedisStore } from '@gravito/photon/middleware/ratelimit-redis'
|
|
17
|
+
*
|
|
18
|
+
* const redis = new Redis()
|
|
19
|
+
* const app = new Photon()
|
|
20
|
+
*
|
|
21
|
+
* app.use(rateLimit({
|
|
22
|
+
* maxRequests: 100,
|
|
23
|
+
* windowMs: 60000,
|
|
24
|
+
* store: new RedisStore(redis, { maxRequests: 100, windowMs: 60000 })
|
|
25
|
+
* }))
|
|
26
|
+
* ```
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare class RedisStore implements RateLimitStore {
|
|
30
|
+
private client;
|
|
31
|
+
private config;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new RedisStore.
|
|
34
|
+
*
|
|
35
|
+
* @param client - Redis client instance (must support .eval())
|
|
36
|
+
* @param config - Rate limit configuration
|
|
37
|
+
*/
|
|
38
|
+
constructor(client: any, config: {
|
|
39
|
+
maxRequests: number;
|
|
40
|
+
windowMs: number;
|
|
41
|
+
prefix?: string;
|
|
42
|
+
});
|
|
43
|
+
private get prefix();
|
|
44
|
+
/**
|
|
45
|
+
* Atomic increment and TTL management using Lua.
|
|
46
|
+
*/
|
|
47
|
+
increment(key: string): Promise<RateLimitState>;
|
|
48
|
+
reset(key: string): Promise<void>;
|
|
49
|
+
get(key: string): Promise<RateLimitState | null>;
|
|
50
|
+
}
|
|
@@ -88,11 +88,15 @@ export interface RateLimitState {
|
|
|
88
88
|
export declare class MemoryStore implements RateLimitStore {
|
|
89
89
|
private config;
|
|
90
90
|
private store;
|
|
91
|
+
private head?;
|
|
92
|
+
private tail?;
|
|
91
93
|
private cleanupInterval;
|
|
92
94
|
constructor(config: {
|
|
93
95
|
maxRequests: number;
|
|
94
96
|
windowMs: number;
|
|
95
97
|
}, cleanupIntervalMs?: number);
|
|
98
|
+
private addNode;
|
|
99
|
+
private removeNode;
|
|
96
100
|
increment(key: string): Promise<RateLimitState>;
|
|
97
101
|
reset(key: string): Promise<void>;
|
|
98
102
|
get(key: string): Promise<RateLimitState | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravito/echo",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Enterprise-grade webhook handling for Gravito. Secure receiving and reliable sending.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/gravito-framework/gravito#readme",
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@gravito/core": "
|
|
46
|
+
"@gravito/core": "^1.6.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"bun-types": "latest",
|