@gravito/ripple 4.0.1 → 5.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 (226) hide show
  1. package/README.md +26 -10
  2. package/dist/{ripple/src/OrbitRipple.d.ts → OrbitRipple.d.ts} +1 -0
  3. package/dist/{ripple/src/RippleServer.d.ts → RippleServer.d.ts} +32 -1
  4. package/dist/core/src/Application.d.ts +41 -0
  5. package/dist/core/src/HookManager.d.ts +33 -189
  6. package/dist/core/src/PlanetCore.d.ts +31 -1
  7. package/dist/core/src/Router.d.ts +32 -46
  8. package/dist/core/src/adapters/bun/BunContext.d.ts +6 -1
  9. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
  10. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  11. package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
  12. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  13. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  14. package/dist/core/src/binary/index.d.ts +5 -0
  15. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  16. package/dist/core/src/compat/crypto.d.ts +6 -0
  17. package/dist/core/src/engine/AOTRouter.d.ts +10 -0
  18. package/dist/core/src/engine/FastContext.d.ts +19 -1
  19. package/dist/core/src/engine/Gravito.d.ts +13 -18
  20. package/dist/core/src/engine/MinimalContext.d.ts +2 -0
  21. package/dist/core/src/engine/analyzer.d.ts +92 -6
  22. package/dist/core/src/engine/types.d.ts +3 -0
  23. package/dist/core/src/events/CircuitBreaker.d.ts +12 -0
  24. package/dist/core/src/events/EventPriorityQueue.d.ts +18 -256
  25. package/dist/core/src/events/index.d.ts +12 -11
  26. package/dist/core/src/events/queue-core.d.ts +77 -0
  27. package/dist/core/src/events/task-executor.d.ts +51 -0
  28. package/dist/core/src/exceptions/AuthException.d.ts +10 -0
  29. package/dist/core/src/exceptions/AuthenticationException.d.ts +2 -2
  30. package/dist/core/src/exceptions/AuthorizationException.d.ts +2 -2
  31. package/dist/core/src/exceptions/CacheException.d.ts +9 -0
  32. package/dist/core/src/exceptions/CircularDependencyException.d.ts +2 -1
  33. package/dist/core/src/exceptions/ConfigurationException.d.ts +9 -0
  34. package/dist/core/src/exceptions/DatabaseException.d.ts +9 -0
  35. package/dist/core/src/exceptions/DomainException.d.ts +9 -0
  36. package/dist/core/src/exceptions/InfrastructureException.d.ts +17 -0
  37. package/dist/core/src/exceptions/QueueException.d.ts +9 -0
  38. package/dist/core/src/exceptions/StorageException.d.ts +9 -0
  39. package/dist/core/src/exceptions/StreamException.d.ts +9 -0
  40. package/dist/core/src/exceptions/SystemException.d.ts +9 -0
  41. package/dist/core/src/exceptions/ValidationException.d.ts +2 -2
  42. package/dist/core/src/exceptions/index.d.ts +10 -0
  43. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  44. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  45. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  46. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  47. package/dist/core/src/ffi/index.d.ts +10 -0
  48. package/dist/core/src/ffi/types.d.ts +135 -0
  49. package/dist/core/src/helpers/Str.d.ts +15 -0
  50. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  51. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  52. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  53. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  54. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  55. package/dist/core/src/hooks/types.d.ts +107 -0
  56. package/dist/core/src/http/CookieJar.d.ts +2 -2
  57. package/dist/core/src/http/types.d.ts +24 -3
  58. package/dist/core/src/index.d.ts +491 -14
  59. package/dist/core/src/observability/contracts.d.ts +137 -0
  60. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +2 -3
  61. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  62. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  63. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  64. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  65. package/dist/core/src/runtime/archive.d.ts +17 -0
  66. package/dist/core/src/runtime/compression.d.ts +21 -0
  67. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  68. package/dist/core/src/runtime/detection.d.ts +22 -0
  69. package/dist/core/src/runtime/escape.d.ts +34 -0
  70. package/dist/core/src/runtime/index.d.ts +44 -0
  71. package/dist/core/src/runtime/markdown.d.ts +44 -0
  72. package/dist/core/src/runtime/types.d.ts +436 -0
  73. package/dist/core/src/runtime-helpers.d.ts +67 -0
  74. package/dist/core/src/runtime.d.ts +10 -118
  75. package/dist/core/src/testing/HttpTester.d.ts +1 -0
  76. package/dist/core/src/transpiler-utils.d.ts +170 -0
  77. package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
  78. package/dist/errors/RippleError.d.ts +66 -0
  79. package/dist/index.js +1 -7502
  80. package/dist/index.js.map +3 -71
  81. package/package.json +6 -2
  82. package/dist/atlas/src/DB.d.ts +0 -348
  83. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  84. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  85. package/dist/atlas/src/config/index.d.ts +0 -7
  86. package/dist/atlas/src/config/loadConfig.d.ts +0 -41
  87. package/dist/atlas/src/connection/Connection.d.ts +0 -112
  88. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -180
  89. package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +0 -54
  90. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  91. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  92. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  93. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -79
  94. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -96
  95. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  96. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  97. package/dist/atlas/src/drivers/types.d.ts +0 -260
  98. package/dist/atlas/src/errors/index.d.ts +0 -45
  99. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  100. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  101. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  102. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  103. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  104. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  105. package/dist/atlas/src/index.d.ts +0 -79
  106. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  107. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  108. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  109. package/dist/atlas/src/migration/index.d.ts +0 -6
  110. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -33
  111. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  112. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  113. package/dist/atlas/src/observability/index.d.ts +0 -9
  114. package/dist/atlas/src/orm/Repository.d.ts +0 -247
  115. package/dist/atlas/src/orm/index.d.ts +0 -6
  116. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  117. package/dist/atlas/src/orm/model/Model.d.ts +0 -458
  118. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  119. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -150
  120. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  121. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -92
  122. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  123. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  124. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  125. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  126. package/dist/atlas/src/orm/model/decorators.d.ts +0 -138
  127. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  128. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  129. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  130. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  131. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -124
  132. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  133. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  134. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  135. package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +0 -98
  136. package/dist/atlas/src/pool/PoolHealthChecker.d.ts +0 -91
  137. package/dist/atlas/src/pool/PoolStrategy.d.ts +0 -129
  138. package/dist/atlas/src/pool/PoolWarmer.d.ts +0 -92
  139. package/dist/atlas/src/query/Expression.d.ts +0 -60
  140. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  141. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -643
  142. package/dist/atlas/src/query/RelationshipResolver.d.ts +0 -23
  143. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  144. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  145. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  146. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  147. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  148. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  149. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  150. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  151. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  152. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  153. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  154. package/dist/atlas/src/schema/MigrationGenerator.d.ts +0 -45
  155. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  156. package/dist/atlas/src/schema/SchemaDiff.d.ts +0 -73
  157. package/dist/atlas/src/schema/TypeGenerator.d.ts +0 -57
  158. package/dist/atlas/src/schema/TypeWriter.d.ts +0 -42
  159. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  160. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  161. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  162. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  163. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  164. package/dist/atlas/src/schema/index.d.ts +0 -8
  165. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  166. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  167. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  168. package/dist/atlas/src/seed/index.d.ts +0 -6
  169. package/dist/atlas/src/sharding/ShardingManager.d.ts +0 -59
  170. package/dist/atlas/src/types/index.d.ts +0 -1182
  171. package/dist/atlas/src/utils/CursorEncoding.d.ts +0 -63
  172. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  173. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -175
  174. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  175. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  176. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  177. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  178. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  179. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  180. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  181. package/dist/core/src/instrumentation/index.d.ts +0 -35
  182. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  183. package/dist/core/src/instrumentation/types.d.ts +0 -182
  184. package/dist/core/src/observability/Metrics.d.ts +0 -244
  185. package/dist/photon/src/index.d.ts +0 -89
  186. package/dist/photon/src/middleware/binary.d.ts +0 -31
  187. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  188. package/dist/photon/src/middleware/ratelimit-redis.d.ts +0 -50
  189. package/dist/photon/src/middleware/ratelimit.d.ts +0 -161
  190. package/dist/photon/src/openapi.d.ts +0 -19
  191. package/dist/ripple/src/errors/RippleError.d.ts +0 -48
  192. /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
  193. /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
  194. /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
  195. /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
  196. /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
  197. /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
  198. /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
  199. /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
  200. /package/dist/{ripple/src/engines → engines}/UWebSocketsEngine.d.ts +0 -0
  201. /package/dist/{ripple/src/engines → engines}/WsEngine.d.ts +0 -0
  202. /package/dist/{ripple/src/engines → engines}/index.d.ts +0 -0
  203. /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
  204. /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
  205. /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
  206. /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
  207. /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
  208. /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
  209. /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
  210. /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
  211. /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
  212. /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
  213. /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
  214. /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
  215. /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
  216. /package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +0 -0
  217. /package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +0 -0
  218. /package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +0 -0
  219. /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
  220. /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
  221. /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
  222. /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
  223. /package/dist/{ripple/src/types.d.ts → types.d.ts} +0 -0
  224. /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
  225. /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
  226. /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @gravito/core - Observability Contracts
3
+ *
4
+ * Abstract interfaces for observability providers, decoupling core from OpenTelemetry.
5
+ * This allows @gravito/monitor to provide complete OTel implementations while core
6
+ * remains dependency-free.
7
+ */
8
+ /**
9
+ * Represents a tracing span for distributed tracing.
10
+ * @public
11
+ */
12
+ export interface TracingSpan {
13
+ /**
14
+ * Add an event to the span.
15
+ *
16
+ * @param name - Event name
17
+ * @param attributes - Optional event attributes
18
+ */
19
+ addEvent(name: string, attributes?: Record<string, string | number>): void;
20
+ /**
21
+ * Set the span status.
22
+ *
23
+ * @param code - Status code: 'OK' or 'ERROR'
24
+ * @param message - Optional error message
25
+ */
26
+ setStatus(code: 'OK' | 'ERROR', message?: string): void;
27
+ /**
28
+ * End the span.
29
+ */
30
+ end(): void;
31
+ }
32
+ /**
33
+ * Event tracing provider for distributed tracing of events.
34
+ * @public
35
+ */
36
+ export interface EventTracingProvider {
37
+ /**
38
+ * Start a new tracing span for an event.
39
+ *
40
+ * @param name - Span name
41
+ * @returns A TracingSpan instance
42
+ */
43
+ startSpan(name: string): TracingSpan;
44
+ /**
45
+ * Record custom metrics for an event.
46
+ *
47
+ * @param eventName - Name of the event
48
+ * @param metrics - Metrics to record (e.g., duration, count)
49
+ */
50
+ recordMetrics(eventName: string, metrics: Record<string, number>): void;
51
+ }
52
+ /**
53
+ * Event metrics recorder for monitoring event processing.
54
+ * @public
55
+ */
56
+ export interface EventMetricsRecorder {
57
+ /**
58
+ * Record event processing completion.
59
+ *
60
+ * @param eventName - Name of the event
61
+ * @param duration - Processing duration in milliseconds
62
+ * @param success - Whether processing was successful
63
+ */
64
+ recordEventProcessed(eventName: string, duration: number, success: boolean): void;
65
+ /**
66
+ * Record event publication.
67
+ *
68
+ * @param eventName - Name of the event
69
+ */
70
+ recordEventPublished(eventName: string): void;
71
+ /**
72
+ * Record event processing error.
73
+ *
74
+ * @param eventName - Name of the event
75
+ * @param error - The error that occurred
76
+ */
77
+ recordEventError(eventName: string, error: Error): void;
78
+ }
79
+ /**
80
+ * Worker metrics provider for monitoring worker pool operations.
81
+ * @public
82
+ */
83
+ export interface WorkerMetricsProvider {
84
+ /**
85
+ * Record worker pool startup.
86
+ *
87
+ * @param poolId - ID of the worker pool
88
+ */
89
+ recordWorkerStartup(poolId: string): void;
90
+ /**
91
+ * Record task execution in a worker pool.
92
+ *
93
+ * @param poolId - ID of the worker pool
94
+ * @param duration - Task duration in milliseconds
95
+ * @param success - Whether task execution was successful
96
+ */
97
+ recordTaskExecution(poolId: string, duration: number, success: boolean): void;
98
+ /**
99
+ * Record worker pool error.
100
+ *
101
+ * @param poolId - ID of the worker pool
102
+ * @param error - The error that occurred
103
+ */
104
+ recordWorkerError(poolId: string, error: Error): void;
105
+ }
106
+ /**
107
+ * Main observability provider interface combining all observability capabilities.
108
+ * @public
109
+ */
110
+ export interface ObservabilityProvider {
111
+ /**
112
+ * Event tracing provider (optional).
113
+ */
114
+ eventTracing?: EventTracingProvider;
115
+ /**
116
+ * Event metrics recorder (optional).
117
+ */
118
+ eventMetrics?: EventMetricsRecorder;
119
+ /**
120
+ * Worker metrics provider (optional).
121
+ */
122
+ workerMetrics?: WorkerMetricsProvider;
123
+ /**
124
+ * General tracing provider (optional).
125
+ */
126
+ tracing?: {
127
+ startSpan(name: string): TracingSpan;
128
+ };
129
+ }
130
+ /**
131
+ * Create a no-op observability provider.
132
+ * Used by default when no observability implementation is provided.
133
+ *
134
+ * @returns An ObservabilityProvider with all no-op implementations
135
+ * @internal
136
+ */
137
+ export declare function createNoOpObservabilityProvider(): ObservabilityProvider;
@@ -4,7 +4,6 @@
4
4
  * 管理失敗事件的持久化存儲
5
5
  * 支持 CRUD、重新入隊、批量重試和統計功能
6
6
  */
7
- import type { ConnectionContract } from '@gravito/atlas';
8
7
  import type { EventOptions } from '../events/EventOptions';
9
8
  import type { RetryPolicy } from './RetryPolicy';
10
9
  /**
@@ -66,7 +65,7 @@ export interface DLQStats {
66
65
  *
67
66
  * @example
68
67
  * ```typescript
69
- * const db = container.make('db') as ConnectionContract
68
+ * const db = container.make('db') as any
70
69
  * const dlqManager = new DeadLetterQueueManager(db)
71
70
  *
72
71
  * // 將失敗事件移至 DLQ
@@ -94,7 +93,7 @@ export interface DLQStats {
94
93
  export declare class DeadLetterQueueManager {
95
94
  private db;
96
95
  private retryEngine;
97
- constructor(db: ConnectionContract);
96
+ constructor(db: any);
98
97
  /**
99
98
  * 將失敗事件移至死信隊列
100
99
  *
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Bun runtime adapter implementation.
3
+ *
4
+ * @module runtime/adapter-bun
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for the Bun runtime.
10
+ * @internal
11
+ */
12
+ export declare function createBunAdapter(): RuntimeAdapter;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Deno runtime adapter implementation.
3
+ *
4
+ * @module runtime/adapter-deno
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for the Deno runtime.
10
+ * @internal
11
+ */
12
+ export declare function createDenoAdapter(): RuntimeAdapter;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Node.js runtime adapter implementation.
3
+ *
4
+ * @module runtime/adapter-node
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for the Node.js runtime.
10
+ * @internal
11
+ */
12
+ export declare function createNodeAdapter(): RuntimeAdapter;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Unknown runtime adapter implementation (fallback).
3
+ *
4
+ * @module runtime/adapter-unknown
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeAdapter } from './types';
8
+ /**
9
+ * Create a RuntimeAdapter for unsupported runtimes.
10
+ * All methods throw with descriptive error messages.
11
+ * @internal
12
+ */
13
+ export declare function createUnknownAdapter(): RuntimeAdapter;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Runtime archive adapter implementations.
3
+ *
4
+ * @module runtime/archive
5
+ * @since 3.2.0
6
+ */
7
+ import type { ArchiveFromDirectoryOptions, RuntimeArchiveAdapter } from './types';
8
+ /**
9
+ * 取得封裝操作 adapter
10
+ * @public
11
+ */
12
+ export declare function getArchiveAdapter(): RuntimeArchiveAdapter;
13
+ /**
14
+ * 將目錄封裝為歸檔檔案
15
+ * @public
16
+ */
17
+ export declare function archiveFromDirectory(dirPath: string, archivePath: string, options?: ArchiveFromDirectoryOptions): Promise<Uint8Array>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Runtime compression adapter implementations.
3
+ *
4
+ * Provides unified gzip/deflate compression across Bun and Node.js runtimes.
5
+ * Bun uses native C++ implementations (Bun.gzipSync etc.) for 2-5x better performance.
6
+ * Node.js falls back to the standard node:zlib module.
7
+ *
8
+ * @module runtime/compression
9
+ * @since 3.2.0
10
+ */
11
+ import type { RuntimeCompressionAdapter } from './types';
12
+ /**
13
+ * 取得壓縮操作 adapter(依運行時自動選擇最佳實作)
14
+ *
15
+ * - Bun: 使用原生 C++ 壓縮(2-5x 更快)
16
+ * - Node.js: 使用 node:zlib
17
+ * - Deno/Unknown: 拋出錯誤
18
+ *
19
+ * @public
20
+ */
21
+ export declare function getCompressionAdapter(): RuntimeCompressionAdapter;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Deep equality comparison abstraction.
3
+ *
4
+ * Provides unified deep equality checking across Bun, Node.js, and Deno runtimes.
5
+ * Uses Bun.deepEquals() when available, falls back to recursive comparison.
6
+ *
7
+ * @module runtime/deep-equals
8
+ * @since 3.2.0
9
+ */
10
+ /**
11
+ * Options for deep equality comparison.
12
+ * @public
13
+ */
14
+ export interface DeepEqualsOptions {
15
+ /**
16
+ * When true, uses strict equality semantics:
17
+ * - NaN !== NaN
18
+ * - +0 !== -0
19
+ *
20
+ * When false (default), uses lenient semantics:
21
+ * - NaN === NaN
22
+ * - +0 === -0
23
+ */
24
+ strict?: boolean;
25
+ }
26
+ /**
27
+ * Function signature for deep equality comparison.
28
+ * @public
29
+ */
30
+ export type DeepEqualsFn = (a: unknown, b: unknown, options?: DeepEqualsOptions) => boolean;
31
+ /**
32
+ * Get the optimized deep equality comparison function for the current runtime.
33
+ *
34
+ * - **Bun**: Uses native Bun.deepEquals() for maximum performance (C++ optimized)
35
+ * - **Node.js/Deno/Unknown**: Uses fallback recursive implementation with cycle detection
36
+ *
37
+ * Results are cached after first invocation for efficiency.
38
+ *
39
+ * @returns A function that performs deep equality comparison
40
+ * @public
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const deepEquals = getDeepEquals()
45
+ *
46
+ * const obj1 = { a: [1, 2], b: { c: 3 } }
47
+ * const obj2 = { a: [1, 2], b: { c: 3 } }
48
+ *
49
+ * console.log(deepEquals(obj1, obj2)) // true
50
+ *
51
+ * // Strict mode for +0 / -0 and NaN
52
+ * console.log(deepEquals(NaN, NaN)) // true (lenient)
53
+ * console.log(deepEquals(NaN, NaN, { strict: true })) // false
54
+ * ```
55
+ */
56
+ export declare function getDeepEquals(): DeepEqualsFn;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Runtime detection utilities.
3
+ *
4
+ * @module runtime/detection
5
+ * @since 3.2.0
6
+ */
7
+ import type { RuntimeKind } from './types';
8
+ /**
9
+ * Detect the current JavaScript runtime environment.
10
+ * @internal
11
+ */
12
+ export declare function getRuntimeKind(): RuntimeKind;
13
+ /**
14
+ * Get environment variables from the current runtime.
15
+ * @public
16
+ */
17
+ export declare function getRuntimeEnv(): Record<string, string | undefined>;
18
+ /**
19
+ * Convert various data types to Uint8Array.
20
+ * @internal
21
+ */
22
+ export declare function toUint8Array(data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Runtime HTML escape abstraction.
3
+ *
4
+ * Provides unified HTML escaping across Bun, Node.js, and Deno runtimes.
5
+ * Bun uses the native C++ `Bun.escapeHTML()` for 10-100x better performance.
6
+ * Node.js/Deno fall back to manual entity replacement.
7
+ *
8
+ * @module runtime/escape
9
+ * @since 3.4.0
10
+ */
11
+ /**
12
+ * HTML escape function type.
13
+ * @public
14
+ */
15
+ export type EscapeHtmlFn = (value: string) => string;
16
+ /**
17
+ * Get the HTML escape function (auto-selects best implementation based on runtime).
18
+ *
19
+ * - Bun: Uses native C++ `Bun.escapeHTML()` (10-100x faster, SIMD accelerated)
20
+ * - Node.js/Deno/Unknown: Uses .replace() chain fallback with same behavior
21
+ *
22
+ * @returns HTML escape function
23
+ * @public
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { getEscapeHtml } from '@gravito/core'
28
+ *
29
+ * const escapeHtml = getEscapeHtml()
30
+ * const safe = escapeHtml('<script>alert("xss")</script>')
31
+ * // '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;'
32
+ * ```
33
+ */
34
+ export declare function getEscapeHtml(): EscapeHtmlFn;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Runtime abstraction module.
3
+ *
4
+ * Provides unified APIs for filesystem, process, archive, and compression
5
+ * operations across Bun, Node.js, and Deno runtimes.
6
+ *
7
+ * @module runtime
8
+ * @since 3.2.0
9
+ */
10
+ import type { RuntimeAdapter, RuntimePasswordAdapter, RuntimeSqliteDatabase } from './types';
11
+ export type { ArchiveCreateOptions, ArchiveEntry, ArchiveExtractOptions, ArchiveFileInfo, ArchiveFromDirectoryOptions, CompressionOptions, MarkdownRenderCallbacks, MarkdownRenderOptions, OptionalRuntimeResourceUsage, RuntimeAdapter, RuntimeArchiveAdapter, RuntimeCompressionAdapter, RuntimeFileSink, RuntimeFileStat, RuntimeKind, RuntimeMarkdownAdapter, RuntimePasswordAdapter, RuntimeProcess, RuntimeProcessOutput, RuntimeResourceUsage, RuntimeServeConfig, RuntimeServer, RuntimeSpawnOptions, RuntimeSpawnSyncResult, RuntimeSqliteDatabase, RuntimeSqliteStatement, } from './types';
12
+ export { getRuntimeEnv, getRuntimeKind } from './detection';
13
+ export { archiveFromDirectory, getArchiveAdapter, } from './archive';
14
+ export { getCompressionAdapter } from './compression';
15
+ export { createHtmlRenderCallbacks, getMarkdownAdapter } from './markdown';
16
+ export type { DeepEqualsFn, DeepEqualsOptions } from './deep-equals';
17
+ export { getDeepEquals } from './deep-equals';
18
+ export type { EscapeHtmlFn } from './escape';
19
+ export { getEscapeHtml } from './escape';
20
+ /**
21
+ * Get the runtime abstraction adapter (Bun/Node/Deno).
22
+ * @public
23
+ */
24
+ export declare function getRuntimeAdapter(): RuntimeAdapter;
25
+ /**
26
+ * Reset the runtime adapter (mainly for testing).
27
+ * @internal
28
+ */
29
+ export declare function resetRuntimeAdapter(): void;
30
+ /**
31
+ * Get the password hashing adapter using native optimized implementations if available.
32
+ * @public
33
+ */
34
+ export declare function getPasswordAdapter(): RuntimePasswordAdapter;
35
+ /**
36
+ * Create a SQLite database connection using runtime-native drivers.
37
+ * @public
38
+ */
39
+ export declare function createSqliteDatabase(path: string): Promise<RuntimeSqliteDatabase>;
40
+ /**
41
+ * Convert various data types to Uint8Array.
42
+ * @internal
43
+ */
44
+ export declare function toUint8Array(data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Runtime markdown adapter implementations.
3
+ *
4
+ * Provides unified Markdown -> HTML rendering across Bun and Node.js runtimes.
5
+ * Bun uses the native C++ Markdown parser (Bun.markdown) for 10-100x better performance.
6
+ * Node.js falls back to the `marked` library (lazy-loaded optional dependency).
7
+ *
8
+ * @module runtime/markdown
9
+ * @since 3.3.0
10
+ */
11
+ import type { MarkdownRenderCallbacks, RuntimeMarkdownAdapter } from './types';
12
+ /**
13
+ * 建立預設的 HTML 渲染回調集合。
14
+ *
15
+ * 提供完整的 HTML 元素生成回調,產生與 `html()` 相同的 HTML 輸出。
16
+ * 使用者可透過覆寫個別回調來自訂特定元素的渲染行為(例如 XSS 防護、
17
+ * 自訂 CSS class 等),同時保留其他元素的預設 HTML 渲染。
18
+ *
19
+ * @param overrides - 要覆寫的回調。未指定的回調使用預設 HTML 渲染。
20
+ * @returns 完整的 MarkdownRenderCallbacks 物件
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // 自訂 link 和 html 渲染(XSS 防護)
25
+ * const callbacks = createHtmlRenderCallbacks({
26
+ * html: (raw) => escapeHtml(raw),
27
+ * link: (content, { href }) => `<a href="${href}" rel="noopener">${content}</a>`,
28
+ * })
29
+ * const result = adapter.render(markdown, callbacks)
30
+ * ```
31
+ *
32
+ * @public
33
+ */
34
+ export declare function createHtmlRenderCallbacks(overrides?: Partial<MarkdownRenderCallbacks>): MarkdownRenderCallbacks;
35
+ /**
36
+ * 取得 Markdown 操作 adapter(依運行時自動選擇最佳實作)
37
+ *
38
+ * - Bun: 使用原生 C++ Markdown 解析器(10-100x 更快)
39
+ * - Node.js: 使用 marked 函式庫(延遲載入 optional dependency)
40
+ * - Deno/Unknown: 拋出錯誤
41
+ *
42
+ * @public
43
+ */
44
+ export declare function getMarkdownAdapter(): RuntimeMarkdownAdapter;