@gravito/ripple 3.0.1 → 3.1.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.
- package/README.md +179 -6
- package/README.zh-TW.md +104 -2
- package/dist/core/src/Application.d.ts +43 -17
- package/dist/core/src/Container.d.ts +37 -3
- package/dist/core/src/HookManager.d.ts +6 -4
- package/dist/core/src/PlanetCore.d.ts +52 -7
- package/dist/core/src/Router.d.ts +40 -2
- package/dist/core/src/ServiceProvider.d.ts +14 -8
- package/dist/core/src/adapters/types.d.ts +12 -0
- package/dist/core/src/engine/Gravito.d.ts +1 -1
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/index.d.ts +1 -0
- package/dist/index.js +531 -64
- package/dist/index.js.map +16 -10
- package/dist/photon/src/index.d.ts +55 -5
- package/dist/photon/src/middleware/binary.d.ts +12 -15
- package/dist/photon/src/middleware/htmx.d.ts +39 -0
- package/dist/ripple/src/OrbitRipple.d.ts +34 -12
- package/dist/ripple/src/RippleServer.d.ts +418 -25
- package/dist/ripple/src/channels/ChannelManager.d.ts +107 -12
- package/dist/ripple/src/drivers/LocalDriver.d.ts +43 -11
- package/dist/ripple/src/drivers/RedisDriver.d.ts +106 -28
- package/dist/ripple/src/errors/RippleError.d.ts +48 -0
- package/dist/ripple/src/errors/index.d.ts +1 -0
- package/dist/ripple/src/events/BroadcastEvent.d.ts +78 -6
- package/dist/ripple/src/events/BroadcastManager.d.ts +100 -0
- package/dist/ripple/src/events/Broadcaster.d.ts +211 -14
- package/dist/ripple/src/events/index.d.ts +1 -0
- package/dist/ripple/src/health/HealthChecker.d.ts +93 -0
- package/dist/ripple/src/health/index.d.ts +1 -0
- package/dist/ripple/src/index.d.ts +40 -17
- package/dist/ripple/src/logging/Logger.d.ts +99 -0
- package/dist/ripple/src/logging/index.d.ts +1 -0
- package/dist/ripple/src/tracking/ConnectionTracker.d.ts +116 -0
- package/dist/ripple/src/tracking/index.d.ts +1 -0
- package/dist/ripple/src/types.d.ts +592 -19
- package/dist/ripple/src/utils/MessageSerializer.d.ts +44 -0
- package/dist/ripple/src/utils/index.d.ts +1 -0
- package/package.json +5 -3
|
@@ -1,20 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @gravito/photon - High-performance web
|
|
2
|
+
* @gravito/photon - High-performance web engine for the Gravito Galaxy Architecture.
|
|
3
3
|
*
|
|
4
|
-
* Photon
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Photon serves as the foundational HTTP layer for Gravito, providing an ultra-fast,
|
|
5
|
+
* type-safe routing system based on Hono. It is designed to be the "light" that
|
|
6
|
+
* connects Satellites (domain plugins) and Orbits (infrastructure) within the ecosystem.
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Zero-overhead routing and middleware.
|
|
10
|
+
* - Full TypeScript inference for request parameters and body.
|
|
11
|
+
* - Built-in support for HTMX and binary (CBOR) protocols.
|
|
7
12
|
*
|
|
8
13
|
* @example
|
|
9
14
|
* ```typescript
|
|
10
15
|
* import { Photon } from '@gravito/photon'
|
|
16
|
+
*
|
|
11
17
|
* const app = new Photon()
|
|
12
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* app.get('/welcome', (c) => c.text('Welcome to the Galaxy!'))
|
|
20
|
+
*
|
|
21
|
+
* export default app
|
|
13
22
|
* ```
|
|
23
|
+
* @packageDocumentation
|
|
14
24
|
*/
|
|
15
25
|
export * from 'hono';
|
|
26
|
+
/**
|
|
27
|
+
* The primary application class for Photon.
|
|
28
|
+
*
|
|
29
|
+
* An alias for `Hono`, providing the core routing and middleware capabilities.
|
|
30
|
+
* Use this to define your API structure and mount domain-specific Satellites.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Photon extends Hono's capabilities with Gravito-specific optimizations.
|
|
34
|
+
* It serves as the entry point for defining routes, applying middleware,
|
|
35
|
+
* and handling the request-response lifecycle.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const app = new Photon()
|
|
40
|
+
*
|
|
41
|
+
* // Basic routing
|
|
42
|
+
* app.get('/api/health', (c) => c.json({ status: 'ok' }))
|
|
43
|
+
*
|
|
44
|
+
* // Middleware integration
|
|
45
|
+
* app.use('/api/*', myMiddleware)
|
|
46
|
+
*
|
|
47
|
+
* // Mounting sub-routers
|
|
48
|
+
* app.route('/v1', v1Router)
|
|
49
|
+
* ```
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
16
52
|
export { Hono as Photon } from 'hono';
|
|
17
53
|
/**
|
|
18
54
|
* Binary-related middleware for Photon.
|
|
55
|
+
*
|
|
56
|
+
* Provides utilities for handling binary data formats like CBOR,
|
|
57
|
+
* optimizing payload size and serialization speed for high-performance APIs.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
19
60
|
*/
|
|
20
61
|
export * from './middleware/binary';
|
|
62
|
+
/**
|
|
63
|
+
* HTMX-related middleware for Photon.
|
|
64
|
+
*
|
|
65
|
+
* Enhances Photon with first-class support for HTMX, including
|
|
66
|
+
* automatic request detection and simplified header access for hypermedia-driven UIs.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export * from './middleware/htmx';
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { MiddlewareHandler } from 'hono';
|
|
2
2
|
/**
|
|
3
|
-
* Binary Middleware for Photon
|
|
3
|
+
* Binary Middleware for Photon.
|
|
4
4
|
*
|
|
5
5
|
* Automatically detects 'Accept: application/cbor' and encodes
|
|
6
6
|
* JSON responses using the CBOR binary format for high-performance communication.
|
|
7
7
|
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This middleware is essential for high-frequency API calls where payload size
|
|
10
|
+
* and serialization speed are critical. It leverages the `cborg` library for
|
|
11
|
+
* efficient binary encoding.
|
|
12
|
+
*
|
|
13
|
+
* @returns A Hono middleware handler that intercepts JSON responses.
|
|
14
|
+
*
|
|
8
15
|
* @example
|
|
9
16
|
* ```typescript
|
|
10
17
|
* import { Photon } from '@gravito/photon'
|
|
@@ -13,22 +20,12 @@ import type { MiddlewareHandler } from 'hono';
|
|
|
13
20
|
* const app = new Photon()
|
|
14
21
|
* app.use(binaryMiddleware())
|
|
15
22
|
*
|
|
16
|
-
* app.get('/api/data', (c) => c.json({ items: [
|
|
23
|
+
* app.get('/api/data', (c) => c.json({ items: [1, 2, 3] }))
|
|
17
24
|
* ```
|
|
18
25
|
*
|
|
19
26
|
* @performance
|
|
20
|
-
* - CBOR encoding is ~2-3x faster than JSON.stringify for large objects
|
|
21
|
-
* - Binary format reduces payload size by 20-40% on average
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
* @client_usage
|
|
25
|
-
* ```typescript
|
|
26
|
-
* import { decode } from 'cborg'
|
|
27
|
-
*
|
|
28
|
-
* const res = await fetch('/api/data', {
|
|
29
|
-
* headers: { Accept: 'application/cbor' }
|
|
30
|
-
* })
|
|
31
|
-
* const data = decode(new Uint8Array(await res.arrayBuffer()))
|
|
32
|
-
* ```
|
|
27
|
+
* - CBOR encoding is ~2-3x faster than JSON.stringify for large objects.
|
|
28
|
+
* - Binary format reduces payload size by 20-40% on average.
|
|
29
|
+
* - Optimized to read body directly without clone(), saving ~30% overhead.
|
|
33
30
|
*/
|
|
34
31
|
export declare const binaryMiddleware: () => MiddlewareHandler;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* HTMX Middleware for Photon.
|
|
4
|
+
*
|
|
5
|
+
* Automatically detects HTMX requests and populates the context with
|
|
6
|
+
* HTMX-specific headers and state.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This middleware enables hypermedia-driven UIs by providing first-class
|
|
10
|
+
* support for HTMX. It allows handlers to easily distinguish between
|
|
11
|
+
* full-page loads and partial updates.
|
|
12
|
+
*
|
|
13
|
+
* @returns A Hono middleware handler that populates HTMX context variables.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { Photon } from '@gravito/photon'
|
|
18
|
+
* import { htmxMiddleware } from '@gravito/photon/middleware/htmx'
|
|
19
|
+
*
|
|
20
|
+
* const app = new Photon()
|
|
21
|
+
* app.use(htmxMiddleware())
|
|
22
|
+
*
|
|
23
|
+
* app.get('/search', async (c) => {
|
|
24
|
+
* // Check if request is from HTMX
|
|
25
|
+
* if (c.get('htmx')) {
|
|
26
|
+
* return c.html('<div>Search results...</div>')
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* return c.html('<html>...</html>')
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @context_variables
|
|
34
|
+
* - `htmx`: Boolean indicating if the request is an HTMX request.
|
|
35
|
+
* - `htmx.boosted`: Boolean indicating if the request was boosted.
|
|
36
|
+
* - `htmx.target`: The ID of the target element.
|
|
37
|
+
* - `htmx.trigger`: The ID of the trigger element.
|
|
38
|
+
*/
|
|
39
|
+
export declare const htmxMiddleware: () => MiddlewareHandler;
|
|
@@ -1,42 +1,64 @@
|
|
|
1
1
|
import type { GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
2
|
+
import { BroadcastManager } from './events/BroadcastManager';
|
|
2
3
|
import { RippleServer } from './RippleServer';
|
|
3
4
|
import type { RippleConfig } from './types';
|
|
4
5
|
/**
|
|
5
|
-
* OrbitRipple
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* OrbitRipple integrates the Ripple WebSocket module into the Gravito framework.
|
|
7
|
+
*
|
|
8
|
+
* It handles the registration of the RippleServer in the IoC container,
|
|
9
|
+
* adds middleware for context access, and manages the server lifecycle.
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```typescript
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* import { PlanetCore } from '@gravito/core'
|
|
14
|
+
* import { OrbitRipple } from '@gravito/ripple'
|
|
15
|
+
*
|
|
16
|
+
* const core = new PlanetCore()
|
|
17
|
+
*
|
|
18
|
+
* // Install Ripple as an Orbit
|
|
19
|
+
* core.install(new OrbitRipple({
|
|
20
|
+
* path: '/ws',
|
|
21
|
+
* authorizer: async (channel, userId) => userId !== undefined
|
|
22
|
+
* }))
|
|
13
23
|
* ```
|
|
14
|
-
* @public
|
|
15
24
|
*/
|
|
16
25
|
export declare class OrbitRipple implements GravitoOrbit {
|
|
17
26
|
private server;
|
|
18
27
|
private config;
|
|
19
28
|
/**
|
|
20
|
-
* Create a new OrbitRipple
|
|
21
|
-
*
|
|
29
|
+
* Create a new OrbitRipple.
|
|
30
|
+
*
|
|
31
|
+
* @param config - Ripple configuration options
|
|
22
32
|
*/
|
|
23
33
|
constructor(config?: RippleConfig);
|
|
24
34
|
/**
|
|
25
|
-
* Install the
|
|
35
|
+
* Install the orbit into the Gravito core.
|
|
36
|
+
*
|
|
37
|
+
* - Registers 'ripple' (RippleServer) and 'broadcast' (BroadcastManager) in the container.
|
|
38
|
+
* - Adds middleware to inject 'ripple' and 'broadcast' into GravitoContext.
|
|
39
|
+
* - Initializes the server and registers shutdown hooks.
|
|
40
|
+
*
|
|
41
|
+
* @param core - The PlanetCore instance
|
|
26
42
|
*/
|
|
27
43
|
install(core: PlanetCore): void;
|
|
28
44
|
/**
|
|
29
|
-
* Get the underlying RippleServer instance
|
|
45
|
+
* Get the underlying RippleServer instance.
|
|
46
|
+
*
|
|
47
|
+
* @returns The RippleServer instance
|
|
30
48
|
*/
|
|
31
49
|
getServer(): RippleServer;
|
|
32
50
|
/**
|
|
33
|
-
* Get WebSocket handler for Bun.serve
|
|
51
|
+
* Get the WebSocket handler for Bun.serve.
|
|
52
|
+
*
|
|
53
|
+
* @returns The WebSocket handler object
|
|
34
54
|
*/
|
|
35
55
|
getHandler(): import("./types").WebSocketHandlerConfig;
|
|
36
56
|
}
|
|
37
57
|
declare module '@gravito/core' {
|
|
38
58
|
interface GravitoVariables {
|
|
39
|
-
/**
|
|
59
|
+
/** RippleServer instance available in context */
|
|
40
60
|
ripple?: RippleServer;
|
|
61
|
+
/** BroadcastManager instance available in context */
|
|
62
|
+
broadcast?: BroadcastManager;
|
|
41
63
|
}
|
|
42
64
|
}
|