@gravito/ripple 3.0.0 → 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.
Files changed (118) hide show
  1. package/README.md +179 -6
  2. package/README.zh-TW.md +104 -2
  3. package/dist/core/src/Application.d.ts +215 -0
  4. package/dist/core/src/ConfigManager.d.ts +26 -0
  5. package/dist/core/src/Container.d.ts +78 -0
  6. package/dist/core/src/ErrorHandler.d.ts +63 -0
  7. package/dist/core/src/Event.d.ts +5 -0
  8. package/dist/core/src/EventManager.d.ts +123 -0
  9. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  10. package/dist/core/src/GravitoServer.d.ts +28 -0
  11. package/dist/core/src/HookManager.d.ts +84 -0
  12. package/dist/core/src/Listener.d.ts +4 -0
  13. package/dist/core/src/Logger.d.ts +20 -0
  14. package/dist/core/src/PlanetCore.d.ts +289 -0
  15. package/dist/core/src/Route.d.ts +36 -0
  16. package/dist/core/src/Router.d.ts +288 -0
  17. package/dist/core/src/ServiceProvider.d.ts +156 -0
  18. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +26 -0
  19. package/dist/core/src/adapters/PhotonAdapter.d.ts +170 -0
  20. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  21. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +30 -0
  22. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  23. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  24. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  25. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  26. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  27. package/dist/core/src/adapters/types.d.ts +208 -0
  28. package/dist/core/src/engine/AOTRouter.d.ts +134 -0
  29. package/dist/core/src/engine/FastContext.d.ts +98 -0
  30. package/dist/core/src/engine/Gravito.d.ts +137 -0
  31. package/dist/core/src/engine/MinimalContext.d.ts +77 -0
  32. package/dist/core/src/engine/analyzer.d.ts +27 -0
  33. package/dist/core/src/engine/constants.d.ts +23 -0
  34. package/dist/core/src/engine/index.d.ts +26 -0
  35. package/dist/core/src/engine/path.d.ts +26 -0
  36. package/dist/core/src/engine/pool.d.ts +83 -0
  37. package/dist/core/src/engine/types.d.ts +138 -0
  38. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  39. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  40. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  41. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  42. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  43. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  44. package/dist/core/src/exceptions/index.d.ts +6 -0
  45. package/dist/core/src/helpers/Arr.d.ts +19 -0
  46. package/dist/core/src/helpers/Str.d.ts +23 -0
  47. package/dist/core/src/helpers/data.d.ts +25 -0
  48. package/dist/core/src/helpers/errors.d.ts +34 -0
  49. package/dist/core/src/helpers/response.d.ts +41 -0
  50. package/dist/core/src/helpers.d.ts +338 -0
  51. package/dist/core/src/http/CookieJar.d.ts +51 -0
  52. package/dist/core/src/http/cookie.d.ts +29 -0
  53. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  54. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  55. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  56. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  57. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  58. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  59. package/dist/core/src/http/types.d.ts +334 -0
  60. package/dist/core/src/index.d.ts +67 -0
  61. package/dist/core/src/runtime.d.ts +119 -0
  62. package/dist/core/src/security/Encrypter.d.ts +33 -0
  63. package/dist/core/src/security/Hasher.d.ts +29 -0
  64. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  65. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  66. package/dist/core/src/testing/index.d.ts +2 -0
  67. package/dist/core/src/types/events.d.ts +94 -0
  68. package/dist/index.js +10206 -37
  69. package/dist/index.js.map +69 -10
  70. package/dist/photon/src/index.d.ts +70 -0
  71. package/dist/photon/src/middleware/binary.d.ts +31 -0
  72. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  73. package/dist/ripple/src/OrbitRipple.d.ts +64 -0
  74. package/dist/ripple/src/RippleServer.d.ts +518 -0
  75. package/dist/{channels → ripple/src/channels}/Channel.d.ts +6 -1
  76. package/dist/ripple/src/channels/ChannelManager.d.ts +173 -0
  77. package/dist/{channels → ripple/src/channels}/index.d.ts +0 -1
  78. package/dist/ripple/src/drivers/LocalDriver.d.ts +61 -0
  79. package/dist/ripple/src/drivers/RedisDriver.d.ts +141 -0
  80. package/dist/ripple/src/drivers/index.d.ts +2 -0
  81. package/dist/ripple/src/errors/RippleError.d.ts +48 -0
  82. package/dist/ripple/src/errors/index.d.ts +1 -0
  83. package/dist/ripple/src/events/BroadcastEvent.d.ts +123 -0
  84. package/dist/ripple/src/events/BroadcastManager.d.ts +100 -0
  85. package/dist/ripple/src/events/Broadcaster.d.ts +264 -0
  86. package/dist/{events → ripple/src/events}/index.d.ts +1 -1
  87. package/dist/ripple/src/health/HealthChecker.d.ts +93 -0
  88. package/dist/ripple/src/health/index.d.ts +1 -0
  89. package/dist/ripple/src/index.d.ts +60 -0
  90. package/dist/ripple/src/logging/Logger.d.ts +99 -0
  91. package/dist/ripple/src/logging/index.d.ts +1 -0
  92. package/dist/ripple/src/tracking/ConnectionTracker.d.ts +116 -0
  93. package/dist/ripple/src/tracking/index.d.ts +1 -0
  94. package/dist/ripple/src/types.d.ts +753 -0
  95. package/dist/ripple/src/utils/MessageSerializer.d.ts +44 -0
  96. package/dist/ripple/src/utils/index.d.ts +1 -0
  97. package/package.json +14 -5
  98. package/dist/OrbitRipple.d.ts +0 -80
  99. package/dist/OrbitRipple.d.ts.map +0 -1
  100. package/dist/RippleServer.d.ts +0 -126
  101. package/dist/RippleServer.d.ts.map +0 -1
  102. package/dist/channels/Channel.d.ts.map +0 -1
  103. package/dist/channels/ChannelManager.d.ts +0 -79
  104. package/dist/channels/ChannelManager.d.ts.map +0 -1
  105. package/dist/channels/index.d.ts.map +0 -1
  106. package/dist/drivers/LocalDriver.d.ts +0 -30
  107. package/dist/drivers/LocalDriver.d.ts.map +0 -1
  108. package/dist/drivers/index.d.ts +0 -2
  109. package/dist/drivers/index.d.ts.map +0 -1
  110. package/dist/events/BroadcastEvent.d.ts +0 -52
  111. package/dist/events/BroadcastEvent.d.ts.map +0 -1
  112. package/dist/events/Broadcaster.d.ts +0 -68
  113. package/dist/events/Broadcaster.d.ts.map +0 -1
  114. package/dist/events/index.d.ts.map +0 -1
  115. package/dist/index.d.ts +0 -38
  116. package/dist/index.d.ts.map +0 -1
  117. package/dist/types.d.ts +0 -163
  118. package/dist/types.d.ts.map +0 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @gravito/photon - High-performance web engine for the Gravito Galaxy Architecture.
3
+ *
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.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { Photon } from '@gravito/photon'
16
+ *
17
+ * const app = new Photon()
18
+ *
19
+ * app.get('/welcome', (c) => c.text('Welcome to the Galaxy!'))
20
+ *
21
+ * export default app
22
+ * ```
23
+ * @packageDocumentation
24
+ */
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
+ */
52
+ export { Hono as Photon } from 'hono';
53
+ /**
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
60
+ */
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';
@@ -0,0 +1,31 @@
1
+ import type { MiddlewareHandler } from 'hono';
2
+ /**
3
+ * Binary Middleware for Photon.
4
+ *
5
+ * Automatically detects 'Accept: application/cbor' and encodes
6
+ * JSON responses using the CBOR binary format for high-performance communication.
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
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Photon } from '@gravito/photon'
18
+ * import { binaryMiddleware } from '@gravito/photon/middleware/binary'
19
+ *
20
+ * const app = new Photon()
21
+ * app.use(binaryMiddleware())
22
+ *
23
+ * app.get('/api/data', (c) => c.json({ items: [1, 2, 3] }))
24
+ * ```
25
+ *
26
+ * @performance
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.
30
+ */
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;
@@ -0,0 +1,64 @@
1
+ import type { GravitoOrbit, PlanetCore } from '@gravito/core';
2
+ import { BroadcastManager } from './events/BroadcastManager';
3
+ import { RippleServer } from './RippleServer';
4
+ import type { RippleConfig } from './types';
5
+ /**
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.
10
+ *
11
+ * @example
12
+ * ```typescript
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
+ * }))
23
+ * ```
24
+ */
25
+ export declare class OrbitRipple implements GravitoOrbit {
26
+ private server;
27
+ private config;
28
+ /**
29
+ * Create a new OrbitRipple.
30
+ *
31
+ * @param config - Ripple configuration options
32
+ */
33
+ constructor(config?: RippleConfig);
34
+ /**
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
42
+ */
43
+ install(core: PlanetCore): void;
44
+ /**
45
+ * Get the underlying RippleServer instance.
46
+ *
47
+ * @returns The RippleServer instance
48
+ */
49
+ getServer(): RippleServer;
50
+ /**
51
+ * Get the WebSocket handler for Bun.serve.
52
+ *
53
+ * @returns The WebSocket handler object
54
+ */
55
+ getHandler(): import("./types").WebSocketHandlerConfig;
56
+ }
57
+ declare module '@gravito/core' {
58
+ interface GravitoVariables {
59
+ /** RippleServer instance available in context */
60
+ ripple?: RippleServer;
61
+ /** BroadcastManager instance available in context */
62
+ broadcast?: BroadcastManager;
63
+ }
64
+ }