@gravito/ripple 4.0.0 → 4.0.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.
Files changed (91) hide show
  1. package/dist/atlas/src/DB.d.ts +51 -4
  2. package/dist/atlas/src/config/index.d.ts +1 -1
  3. package/dist/atlas/src/config/loadConfig.d.ts +0 -7
  4. package/dist/atlas/src/connection/Connection.d.ts +4 -0
  5. package/dist/atlas/src/connection/ConnectionManager.d.ts +75 -6
  6. package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -0
  7. package/dist/atlas/src/drivers/MySQLDriver.d.ts +16 -3
  8. package/dist/atlas/src/drivers/PostgresDriver.d.ts +15 -2
  9. package/dist/atlas/src/index.d.ts +15 -3
  10. package/dist/atlas/src/observability/AtlasMetrics.d.ts +22 -0
  11. package/dist/atlas/src/orm/Repository.d.ts +247 -0
  12. package/dist/atlas/src/orm/index.d.ts +1 -0
  13. package/dist/atlas/src/orm/model/Model.d.ts +11 -2
  14. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +14 -0
  15. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +5 -0
  16. package/dist/atlas/src/orm/model/decorators.d.ts +29 -0
  17. package/dist/atlas/src/orm/model/index.d.ts +1 -1
  18. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +1 -0
  19. package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +98 -0
  20. package/dist/atlas/src/pool/PoolHealthChecker.d.ts +91 -0
  21. package/dist/atlas/src/pool/PoolStrategy.d.ts +129 -0
  22. package/dist/atlas/src/pool/PoolWarmer.d.ts +92 -0
  23. package/dist/atlas/src/query/QueryBuilder.d.ts +71 -1
  24. package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -0
  25. package/dist/atlas/src/schema/MigrationGenerator.d.ts +45 -0
  26. package/dist/atlas/src/schema/SchemaDiff.d.ts +73 -0
  27. package/dist/atlas/src/schema/TypeGenerator.d.ts +57 -0
  28. package/dist/atlas/src/schema/TypeWriter.d.ts +42 -0
  29. package/dist/atlas/src/sharding/ShardingManager.d.ts +59 -0
  30. package/dist/atlas/src/types/index.d.ts +83 -1
  31. package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -0
  32. package/dist/core/src/ConfigManager.d.ts +39 -0
  33. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  34. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  35. package/dist/core/src/Container.d.ts +45 -0
  36. package/dist/core/src/ErrorHandler.d.ts +3 -0
  37. package/dist/core/src/HookManager.d.ts +95 -0
  38. package/dist/core/src/PlanetCore.d.ts +89 -0
  39. package/dist/core/src/RequestContext.d.ts +97 -0
  40. package/dist/core/src/ServiceProvider.d.ts +22 -0
  41. package/dist/core/src/adapters/PhotonAdapter.d.ts +4 -0
  42. package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
  43. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  44. package/dist/core/src/engine/AOTRouter.d.ts +6 -1
  45. package/dist/core/src/engine/FastContext.d.ts +23 -0
  46. package/dist/core/src/engine/Gravito.d.ts +0 -1
  47. package/dist/core/src/engine/MinimalContext.d.ts +21 -0
  48. package/dist/core/src/engine/types.d.ts +3 -0
  49. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  50. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  51. package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
  52. package/dist/core/src/events/EventBackend.d.ts +2 -1
  53. package/dist/core/src/events/EventOptions.d.ts +99 -4
  54. package/dist/core/src/events/EventPriorityQueue.d.ts +105 -6
  55. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -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 +11 -0
  68. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
  69. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  70. package/dist/core/src/events/observability/index.d.ts +4 -0
  71. package/dist/core/src/events/types.d.ts +59 -0
  72. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  73. package/dist/core/src/http/types.d.ts +19 -0
  74. package/dist/core/src/index.d.ts +13 -1
  75. package/dist/core/src/observability/Metrics.d.ts +244 -0
  76. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  77. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +34 -0
  78. package/dist/index.js +403 -40
  79. package/dist/index.js.map +11 -9
  80. package/dist/photon/src/index.d.ts +5 -0
  81. package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
  82. package/dist/photon/src/middleware/ratelimit.d.ts +4 -0
  83. package/dist/ripple/src/RippleServer.d.ts +0 -1
  84. package/dist/ripple/src/engines/UWebSocketsEngine.d.ts +97 -0
  85. package/dist/ripple/src/engines/WsEngine.d.ts +69 -0
  86. package/dist/ripple/src/engines/index.d.ts +4 -0
  87. package/dist/ripple/src/serializers/ISerializer.d.ts +1 -1
  88. package/dist/ripple/src/serializers/JsonSerializer.d.ts +1 -1
  89. package/dist/ripple/src/serializers/ProtobufSerializer.d.ts +6 -3
  90. package/dist/ripple/src/types.d.ts +11 -0
  91. package/package.json +3 -2
@@ -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>;
@@ -80,7 +80,6 @@ export declare class RippleServer {
80
80
  private broadcastBinaryToChannel;
81
81
  broadcastBinary(channel: string, event: string, data: ArrayBuffer): void;
82
82
  private handleClose;
83
- private handleDrain;
84
83
  private handleSubscribe;
85
84
  private handleUnsubscribe;
86
85
  private handleWhisper;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @fileoverview uWebSockets.js engine implementation for Node.js
3
+ *
4
+ * Wraps uWebSockets.js API to implement the IRippleEngine interface.
5
+ * This engine provides high performance on Node.js, close to Bun's native performance.
6
+ *
7
+ * @module @gravito/ripple/engines
8
+ * @since 5.0.0
9
+ */
10
+ import type { ClientData } from '../types';
11
+ import type { IRippleEngine, RippleSocket } from './IRippleEngine';
12
+ interface WebSocket {
13
+ send(message: string | ArrayBuffer, isBinary?: boolean, compress?: boolean): number;
14
+ close(): void;
15
+ getBufferedAmount(): number;
16
+ subscribe(topic: string): void;
17
+ unsubscribe(topic: string): void;
18
+ publish(topic: string, message: string | ArrayBuffer, isBinary?: boolean, compress?: boolean): boolean;
19
+ getUserData(): ClientData;
20
+ }
21
+ /**
22
+ * Wrapper around uWebSockets.js WebSocket to implement RippleSocket interface.
23
+ *
24
+ * This is a zero-overhead wrapper that delegates all operations to the uWebSockets.js
25
+ * WebSocket object.
26
+ */
27
+ export declare class UWebSocketsRippleSocket implements RippleSocket {
28
+ private ws;
29
+ constructor(ws: WebSocket);
30
+ get id(): string;
31
+ get data(): ClientData;
32
+ send(data: string | Uint8Array, compress?: boolean): void;
33
+ close(_code?: number, _reason?: string): void;
34
+ getBufferedAmount(): number;
35
+ subscribe(topic: string): void;
36
+ unsubscribe(topic: string): void;
37
+ publish(topic: string, data: string | Uint8Array): void;
38
+ get raw(): WebSocket;
39
+ }
40
+ /**
41
+ * Configuration for uWebSocketsEngine.
42
+ */
43
+ export interface UWebSocketsEngineConfig {
44
+ /** Port to listen on */
45
+ port?: number;
46
+ /** Hostname to bind to */
47
+ hostname?: string;
48
+ /** TLS configuration */
49
+ tls?: {
50
+ cert: string;
51
+ key: string;
52
+ };
53
+ /** Compression mode (0 = disabled, 1 = shared, 3 = dedicated 3KB) */
54
+ compression?: number;
55
+ /** Maximum payload length in bytes (default: 16MB) */
56
+ maxPayloadLength?: number;
57
+ /** Idle timeout in seconds (default: 120) */
58
+ idleTimeout?: number;
59
+ /** Maximum backpressure in bytes (default: 1MB) */
60
+ maxBackpressure?: number;
61
+ /** Development mode (enables verbose logging) */
62
+ development?: boolean;
63
+ }
64
+ /**
65
+ * uWebSockets.js engine for Node.js.
66
+ *
67
+ * Leverages uWebSockets.js high-performance WebSocket implementation with native pub/sub support.
68
+ * This engine provides excellent performance on Node.js (~90% of Bun's performance).
69
+ */
70
+ export declare class UWebSocketsEngine implements IRippleEngine {
71
+ private config;
72
+ readonly name = "node-uws";
73
+ private app?;
74
+ private uws?;
75
+ private connectionHandler?;
76
+ private disconnectionHandler?;
77
+ private messageHandler?;
78
+ private sockets;
79
+ private listenSocket?;
80
+ constructor(config?: UWebSocketsEngineConfig);
81
+ onConnection(handler: (socket: RippleSocket) => void): void;
82
+ onDisconnection(handler: (socket: RippleSocket, code: number, reason: string) => void): void;
83
+ onMessage(handler: (socket: RippleSocket, message: string | Uint8Array) => void): void;
84
+ listen(port: number): Promise<void>;
85
+ close(): Promise<void>;
86
+ broadcast(topic: string, data: string | Uint8Array, excludeSocketId?: string): void;
87
+ getConnectedSockets(): RippleSocket[];
88
+ getSocket(id: string): RippleSocket | undefined;
89
+ /**
90
+ * Upgrade an HTTP request to WebSocket.
91
+ *
92
+ * Note: This method is not used in the engine-based architecture.
93
+ * uWebSockets.js handles upgrades internally via the ws() route.
94
+ */
95
+ upgrade(_req: Request, _data?: Record<string, unknown>): boolean;
96
+ }
97
+ export {};
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @fileoverview Node.js ws engine implementation
3
+ *
4
+ * Wraps the 'ws' library to implement the IRippleEngine interface.
5
+ * Implements in-memory pub/sub since the ws library does not support it natively.
6
+ *
7
+ * @module @gravito/ripple/engines
8
+ * @since 5.0.0
9
+ */
10
+ import { type WebSocket } from 'ws';
11
+ import type { ClientData } from '../types';
12
+ import type { IRippleEngine, RippleSocket } from './IRippleEngine';
13
+ /**
14
+ * Wrapper around 'ws' WebSocket to implement RippleSocket interface.
15
+ */
16
+ export declare class WsRippleSocket implements RippleSocket {
17
+ private ws;
18
+ private clientData;
19
+ private engine;
20
+ constructor(ws: WebSocket, clientData: ClientData, engine: WsEngine);
21
+ get id(): string;
22
+ get data(): ClientData;
23
+ send(data: string | Uint8Array, compress?: boolean): void;
24
+ close(code?: number, reason?: string): void;
25
+ getBufferedAmount(): number;
26
+ subscribe(topic: string): void;
27
+ unsubscribe(topic: string): void;
28
+ publish(topic: string, data: string | Uint8Array): void;
29
+ get raw(): WebSocket;
30
+ }
31
+ /**
32
+ * Configuration for WsEngine.
33
+ */
34
+ export interface WsEngineConfig {
35
+ /** Port to listen on */
36
+ port?: number;
37
+ /** Hostname to bind to */
38
+ hostname?: string;
39
+ /** Development mode */
40
+ development?: boolean;
41
+ /** WebSocket path */
42
+ path?: string;
43
+ }
44
+ /**
45
+ * Node.js ws engine.
46
+ *
47
+ * Uses the popular 'ws' library. Provides standard compatibility but
48
+ * uses application-layer pub/sub.
49
+ */
50
+ export declare class WsEngine implements IRippleEngine {
51
+ private config;
52
+ readonly name = "node-ws";
53
+ private wss?;
54
+ private connectionHandler?;
55
+ private disconnectionHandler?;
56
+ private messageHandler?;
57
+ private sockets;
58
+ private subscriptions;
59
+ constructor(config?: WsEngineConfig);
60
+ onConnection(handler: (socket: RippleSocket) => void): void;
61
+ onDisconnection(handler: (socket: RippleSocket, code: number, reason: string) => void): void;
62
+ onMessage(handler: (socket: RippleSocket, message: string | Uint8Array) => void): void;
63
+ listen(port: number): Promise<void>;
64
+ close(): Promise<void>;
65
+ subscribe(socketId: string, topic: string): void;
66
+ unsubscribe(socketId: string, topic: string): void;
67
+ private cleanupSocket;
68
+ broadcast(topic: string, data: string | Uint8Array, excludeSocketId?: string): void;
69
+ }
@@ -9,3 +9,7 @@
9
9
  export type { BunEngineConfig } from './BunEngine';
10
10
  export { BunEngine, BunRippleSocket } from './BunEngine';
11
11
  export type { EngineFactory, IRippleEngine, RippleSocket } from './IRippleEngine';
12
+ export type { UWebSocketsEngineConfig } from './UWebSocketsEngine';
13
+ export { UWebSocketsEngine, UWebSocketsRippleSocket } from './UWebSocketsEngine';
14
+ export type { WsEngineConfig } from './WsEngine';
15
+ export { WsEngine, WsRippleSocket } from './WsEngine';
@@ -21,7 +21,7 @@ export interface ISerializer {
21
21
  * @param data - The raw data received from the client
22
22
  * @returns Parsed ClientMessage object
23
23
  */
24
- deserialize(data: string | Buffer | ArrayBuffer): ClientMessage;
24
+ deserialize(data: string | Buffer | ArrayBuffer | Uint8Array): ClientMessage;
25
25
  /**
26
26
  * Serialize message for broadcasting with caching optimization.
27
27
  *
@@ -12,7 +12,7 @@ export declare class JsonSerializer implements ISerializer {
12
12
  /** Cached serialized string for the current broadcast operation */
13
13
  private broadcastCache;
14
14
  serialize(message: ServerMessage): string;
15
- deserialize(data: string | Buffer | ArrayBuffer): ClientMessage;
15
+ deserialize(data: string | Buffer | ArrayBuffer | Uint8Array): ClientMessage;
16
16
  serializeForBroadcast(message: ServerMessage): string;
17
17
  clearBroadcastCache(): void;
18
18
  getPongMessage(): string;
@@ -7,11 +7,14 @@ import type { ISerializer } from './ISerializer';
7
7
  * Requires 'protobufjs' to be installed.
8
8
  */
9
9
  export declare class ProtobufSerializer implements ISerializer {
10
- private protoPath?;
10
+ private options;
11
11
  readonly contentType = "protobuf";
12
12
  private broadcastCache;
13
13
  private initialized;
14
- constructor(protoPath?: string | undefined);
14
+ constructor(options?: {
15
+ protoPath?: string;
16
+ pure?: boolean;
17
+ });
15
18
  /**
16
19
  * Resolves the proto file path using a multi-level fallback strategy.
17
20
  *
@@ -26,7 +29,7 @@ export declare class ProtobufSerializer implements ISerializer {
26
29
  */
27
30
  init(): Promise<void>;
28
31
  serialize(message: ServerMessage): Uint8Array;
29
- deserialize(data: string | Buffer | ArrayBuffer): ClientMessage;
32
+ deserialize(data: string | Buffer | ArrayBuffer | Uint8Array): ClientMessage;
30
33
  serializeForBroadcast(message: ServerMessage): Uint8Array;
31
34
  clearBroadcastCache(): void;
32
35
  getPongMessage(): Uint8Array;
@@ -34,6 +34,8 @@ export interface ClientData {
34
34
  reconnectionToken?: string;
35
35
  /** Session expiry timestamp (v3.6+) */
36
36
  sessionExpiry?: number;
37
+ /** Remote IP address (v5.0+) */
38
+ remoteAddress?: string;
37
39
  }
38
40
  /**
39
41
  * Supported WebSocket channel types.
@@ -769,6 +771,15 @@ export interface RippleConfig {
769
771
  * Install with: npm install protobufjs
770
772
  */
771
773
  serializer?: 'json' | 'protobuf';
774
+ /**
775
+ * Configuration for the serializer (v5.0+).
776
+ */
777
+ serializerOptions?: {
778
+ /** Path to custom .proto file (Protobuf only) */
779
+ protoPath?: string;
780
+ /** Enable pure binary mode (no JSON envelope for payload) - Protobuf only (default: false) */
781
+ pure?: boolean;
782
+ };
772
783
  /**
773
784
  * Performance & Backpressure (v3.7+).
774
785
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/ripple",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Bun-native WebSocket broadcasting for Gravito. Channel-based real-time communication.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "homepage": "https://github.com/gravito-framework/gravito#readme",
46
46
  "peerDependencies": {
47
- "@gravito/core": "workspace:*",
47
+ "@gravito/core": "^1.6.1",
48
48
  "ioredis": "^5.0.0",
49
49
  "nats": "^2.23.0",
50
50
  "protobufjs": "^8.0.0",
@@ -65,6 +65,7 @@
65
65
  }
66
66
  },
67
67
  "devDependencies": {
68
+ "@types/ws": "^8.18.1",
68
69
  "bun-types": "latest",
69
70
  "ioredis": "^5.4.2",
70
71
  "protobufjs": "^8.0.0",