@gravito/core 1.6.1 → 2.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 (173) hide show
  1. package/README.md +100 -6
  2. package/README.zh-TW.md +101 -6
  3. package/dist/Application.d.ts +256 -0
  4. package/dist/CommandKernel.d.ts +33 -0
  5. package/dist/ConfigManager.d.ts +65 -0
  6. package/dist/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/Container.d.ts +153 -0
  9. package/dist/ErrorHandler.d.ts +66 -0
  10. package/dist/Event.d.ts +5 -0
  11. package/dist/EventManager.d.ts +123 -0
  12. package/dist/GlobalErrorHandlers.d.ts +47 -0
  13. package/dist/GravitoServer.d.ts +28 -0
  14. package/dist/HookManager.d.ts +435 -0
  15. package/dist/Listener.d.ts +4 -0
  16. package/dist/Logger.d.ts +20 -0
  17. package/dist/PlanetCore.d.ts +402 -0
  18. package/dist/RequestContext.d.ts +97 -0
  19. package/dist/Route.d.ts +36 -0
  20. package/dist/Router.d.ts +270 -0
  21. package/dist/ServiceProvider.d.ts +178 -0
  22. package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
  23. package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
  24. package/dist/adapters/bun/BunContext.d.ts +54 -0
  25. package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
  26. package/dist/adapters/bun/BunRequest.d.ts +31 -0
  27. package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  28. package/dist/adapters/bun/RadixNode.d.ts +19 -0
  29. package/dist/adapters/bun/RadixRouter.d.ts +32 -0
  30. package/dist/adapters/bun/index.d.ts +7 -0
  31. package/dist/adapters/bun/types.d.ts +20 -0
  32. package/dist/adapters/index.d.ts +12 -0
  33. package/dist/adapters/types.d.ts +235 -0
  34. package/dist/binary/BinaryUtils.d.ts +105 -0
  35. package/dist/binary/index.d.ts +5 -0
  36. package/dist/cli/queue-commands.d.ts +6 -0
  37. package/dist/compat/async-local-storage.browser.d.ts +9 -0
  38. package/dist/compat/async-local-storage.d.ts +7 -0
  39. package/dist/compat/crypto.browser.d.ts +5 -0
  40. package/dist/compat/crypto.d.ts +6 -0
  41. package/dist/compat.cjs +42 -11
  42. package/dist/compat.cjs.map +9 -0
  43. package/dist/compat.d.ts +23 -1
  44. package/dist/compat.js +3 -0
  45. package/dist/compat.js.map +9 -0
  46. package/dist/engine/AOTRouter.d.ts +139 -0
  47. package/dist/engine/FastContext.d.ts +141 -0
  48. package/dist/engine/Gravito.d.ts +131 -0
  49. package/dist/engine/MinimalContext.d.ts +102 -0
  50. package/dist/engine/analyzer.d.ts +113 -0
  51. package/dist/engine/constants.d.ts +23 -0
  52. package/dist/engine/index.cjs +576 -647
  53. package/dist/engine/index.cjs.map +22 -0
  54. package/dist/engine/index.d.ts +14 -910
  55. package/dist/engine/index.js +576 -623
  56. package/dist/engine/index.js.map +22 -0
  57. package/dist/engine/path.d.ts +26 -0
  58. package/dist/engine/pool.d.ts +83 -0
  59. package/dist/engine/types.d.ts +149 -0
  60. package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
  61. package/dist/events/BackpressureManager.d.ts +215 -0
  62. package/dist/events/CircuitBreaker.d.ts +229 -0
  63. package/dist/events/DeadLetterQueue.d.ts +219 -0
  64. package/dist/events/EventBackend.d.ts +12 -0
  65. package/dist/events/EventOptions.d.ts +204 -0
  66. package/dist/events/EventPriorityQueue.d.ts +63 -0
  67. package/dist/events/FlowControlStrategy.d.ts +109 -0
  68. package/dist/events/IdempotencyCache.d.ts +60 -0
  69. package/dist/events/MessageQueueBridge.d.ts +184 -0
  70. package/dist/events/PriorityEscalationManager.d.ts +82 -0
  71. package/dist/events/RetryScheduler.d.ts +104 -0
  72. package/dist/events/WorkerPool.d.ts +98 -0
  73. package/dist/events/WorkerPoolConfig.d.ts +153 -0
  74. package/dist/events/WorkerPoolMetrics.d.ts +65 -0
  75. package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
  76. package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
  77. package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
  78. package/dist/events/aggregation/EventBatcher.d.ts +99 -0
  79. package/dist/events/aggregation/index.d.ts +10 -0
  80. package/dist/events/aggregation/types.d.ts +117 -0
  81. package/dist/events/index.d.ts +26 -0
  82. package/dist/events/observability/EventMetrics.d.ts +132 -0
  83. package/dist/events/observability/EventTracer.d.ts +68 -0
  84. package/dist/events/observability/EventTracing.d.ts +161 -0
  85. package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
  86. package/dist/events/observability/ObservableHookManager.d.ts +108 -0
  87. package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
  88. package/dist/events/observability/index.d.ts +24 -0
  89. package/dist/events/observability/metrics-types.d.ts +16 -0
  90. package/dist/events/queue-core.d.ts +77 -0
  91. package/dist/events/task-executor.d.ts +51 -0
  92. package/dist/events/types.d.ts +134 -0
  93. package/dist/exceptions/AuthenticationException.d.ts +8 -0
  94. package/dist/exceptions/AuthorizationException.d.ts +8 -0
  95. package/dist/exceptions/CircularDependencyException.d.ts +9 -0
  96. package/dist/exceptions/GravitoException.d.ts +23 -0
  97. package/dist/exceptions/HttpException.d.ts +9 -0
  98. package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
  99. package/dist/exceptions/ValidationException.d.ts +22 -0
  100. package/dist/exceptions/index.d.ts +7 -0
  101. package/dist/ffi/NativeAccelerator.d.ts +69 -0
  102. package/dist/ffi/NativeHasher.d.ts +139 -0
  103. package/dist/ffi/cbor-fallback.d.ts +96 -0
  104. package/dist/ffi/hash-fallback.d.ts +33 -0
  105. package/dist/ffi/index.cjs +621 -0
  106. package/dist/ffi/index.cjs.map +14 -0
  107. package/dist/ffi/index.d.ts +10 -0
  108. package/dist/ffi/index.js +602 -0
  109. package/dist/ffi/index.js.map +14 -0
  110. package/dist/ffi/types.d.ts +135 -0
  111. package/dist/health/HealthProvider.d.ts +67 -0
  112. package/dist/helpers/Arr.d.ts +19 -0
  113. package/dist/helpers/Str.d.ts +38 -0
  114. package/dist/helpers/data.d.ts +25 -0
  115. package/dist/helpers/errors.d.ts +34 -0
  116. package/dist/helpers/response.d.ts +41 -0
  117. package/dist/helpers.d.ts +338 -0
  118. package/dist/hooks/ActionManager.d.ts +132 -0
  119. package/dist/hooks/AsyncDetector.d.ts +84 -0
  120. package/dist/hooks/FilterManager.d.ts +71 -0
  121. package/dist/hooks/MigrationWarner.d.ts +24 -0
  122. package/dist/hooks/dlq-operations.d.ts +60 -0
  123. package/dist/hooks/index.d.ts +11 -0
  124. package/dist/hooks/types.d.ts +107 -0
  125. package/dist/http/CookieJar.d.ts +51 -0
  126. package/dist/http/cookie.d.ts +29 -0
  127. package/dist/http/index.d.ts +12 -0
  128. package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +29 -16
  129. package/dist/index.browser.d.ts +34 -0
  130. package/dist/index.cjs +10525 -11171
  131. package/dist/index.cjs.map +168 -0
  132. package/dist/index.d.ts +58 -10981
  133. package/dist/index.js +10861 -10997
  134. package/dist/index.js.map +168 -0
  135. package/dist/observability/QueueDashboard.d.ts +136 -0
  136. package/dist/observability/contracts.d.ts +137 -0
  137. package/dist/observability/index.d.ts +13 -0
  138. package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
  139. package/dist/reliability/RetryPolicy.d.ts +217 -0
  140. package/dist/reliability/index.d.ts +6 -0
  141. package/dist/router/ControllerDispatcher.d.ts +12 -0
  142. package/dist/router/RequestValidator.d.ts +20 -0
  143. package/dist/runtime/adapter-bun.d.ts +12 -0
  144. package/dist/runtime/adapter-deno.d.ts +12 -0
  145. package/dist/runtime/adapter-node.d.ts +12 -0
  146. package/dist/runtime/adapter-unknown.d.ts +13 -0
  147. package/dist/runtime/archive.d.ts +17 -0
  148. package/dist/runtime/compression.d.ts +21 -0
  149. package/dist/runtime/deep-equals.d.ts +56 -0
  150. package/dist/runtime/detection.d.ts +22 -0
  151. package/dist/runtime/escape.d.ts +34 -0
  152. package/dist/runtime/index.browser.d.ts +20 -0
  153. package/dist/runtime/index.d.ts +44 -0
  154. package/dist/runtime/markdown.d.ts +44 -0
  155. package/dist/runtime/types.d.ts +436 -0
  156. package/dist/runtime-helpers.d.ts +67 -0
  157. package/dist/runtime.d.ts +11 -0
  158. package/dist/security/Encrypter.d.ts +33 -0
  159. package/dist/security/Hasher.d.ts +29 -0
  160. package/dist/testing/HttpTester.d.ts +39 -0
  161. package/dist/testing/TestResponse.d.ts +78 -0
  162. package/dist/testing/index.d.ts +2 -0
  163. package/dist/transpiler-utils.d.ts +170 -0
  164. package/dist/types/events.d.ts +94 -0
  165. package/dist/types.d.ts +13 -0
  166. package/package.json +21 -52
  167. package/src/ffi/native/cbor.c +1148 -0
  168. package/dist/Metrics-VOWWRNNR.js +0 -219
  169. package/dist/chunk-R5U7XKVJ.js +0 -16
  170. package/dist/compat-CI8hiulX.d.ts +0 -376
  171. package/dist/compat.d.cts +0 -1
  172. package/dist/engine/index.d.cts +0 -922
  173. package/dist/index.d.cts +0 -11008
@@ -0,0 +1,338 @@
1
+ import type { ContentfulStatusCode } from './http/types';
2
+ import type { PlanetCore } from './PlanetCore';
3
+ import type { Router } from './Router';
4
+ export { Arr } from './helpers/Arr';
5
+ export * from './helpers/data';
6
+ export * from './helpers/errors';
7
+ export * from './helpers/response';
8
+ export { Str } from './helpers/Str';
9
+ /**
10
+ * Error subclass used for dump and die functionality.
11
+ * @internal
12
+ */
13
+ export declare class DumpDieError extends Error {
14
+ readonly values: unknown[];
15
+ name: string;
16
+ constructor(values: unknown[]);
17
+ }
18
+ /**
19
+ * Options for dump output
20
+ * @public
21
+ */
22
+ export type DumpOptions = {
23
+ depth?: number | null;
24
+ colors?: boolean;
25
+ };
26
+ /**
27
+ * Dump data to console for debugging.
28
+ *
29
+ * Uses `console.dir` with configurable depth and colors to provide a
30
+ * readable representation of any value.
31
+ *
32
+ * @param values - One or more values to dump to the console.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * dump(user, { meta: 'data' });
37
+ * ```
38
+ *
39
+ * @public
40
+ * @since 3.0.0
41
+ */
42
+ export declare function dump(...values: unknown[]): void;
43
+ /**
44
+ * Dump data to console and exit process (or throw in HTTP context).
45
+ *
46
+ * Short for "Dump and Die". In a CLI environment, it exits the process.
47
+ * In an HTTP context (like a web request), it throws a `DumpDieError`
48
+ * which is caught by the exception handler to display the debug output.
49
+ *
50
+ * @param values - One or more values to dump and then die.
51
+ * @throws {DumpDieError} Always throws this error to halt execution.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * dd(user.permissions);
56
+ * ```
57
+ *
58
+ * @public
59
+ * @since 3.0.0
60
+ */
61
+ export declare function dd(...values: unknown[]): never;
62
+ /**
63
+ * Tap into a value, execute a callback, and return the value.
64
+ *
65
+ * This allows you to perform "side effects" on a value without breaking
66
+ * the chain of operations.
67
+ *
68
+ * @param value - The value to tap into.
69
+ * @param callback - A callback that receives the value.
70
+ * @returns The original value.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const user = tap(new User(), (u) => {
75
+ * u.name = 'Alice';
76
+ * u.save();
77
+ * });
78
+ * ```
79
+ *
80
+ * @public
81
+ * @since 3.0.0
82
+ */
83
+ export declare function tap<T>(value: T, callback: (value: T) => unknown): T;
84
+ /**
85
+ * Return the default value of the given value.
86
+ *
87
+ * If the value is a function, it will be executed with the provided arguments
88
+ * and its result will be returned. Otherwise, the value itself is returned.
89
+ * This is useful for handling optional lazy-loaded values.
90
+ *
91
+ * @param valueOrFactory - The value or a factory function.
92
+ * @param args - Arguments to pass to the factory function if it is a function.
93
+ * @returns The resolved value.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * value(10); // 10
98
+ * value(() => 10); // 10
99
+ * value((name) => `Hello ${name}`, 'World'); // "Hello World"
100
+ * ```
101
+ *
102
+ * @public
103
+ * @since 3.0.0
104
+ */
105
+ export declare function value<TArgs extends readonly unknown[], TResult>(valueOrFactory: TResult | ((...args: TArgs) => TResult), ...args: TArgs): TResult;
106
+ /**
107
+ * Determine if the given value is "blank".
108
+ *
109
+ * A value is considered blank if it is:
110
+ * - `null` or `undefined`
111
+ * - An empty string or a string containing only whitespace
112
+ * - An empty array
113
+ * - An empty object
114
+ * - An empty Map or Set
115
+ *
116
+ * @param value - The value to check.
117
+ * @returns `true` if the value is blank, `false` otherwise.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * blank(''); // true
122
+ * blank(' '); // true
123
+ * blank([]); // true
124
+ * blank({}); // true
125
+ * blank(0); // false
126
+ * ```
127
+ *
128
+ * @public
129
+ * @since 3.0.0
130
+ */
131
+ export declare function blank(value: unknown): boolean;
132
+ /**
133
+ * Determine if the given value is "filled" (not blank).
134
+ *
135
+ * This is the inverse of `blank()`.
136
+ *
137
+ * @param value - The value to check.
138
+ * @returns `true` if the value is not blank, `false` otherwise.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * filled('hello'); // true
143
+ * filled([1, 2, 3]); // true
144
+ * filled(''); // false
145
+ * ```
146
+ *
147
+ * @public
148
+ * @since 3.0.0
149
+ */
150
+ export declare function filled(value: unknown): boolean;
151
+ /**
152
+ * Throw an exception if the given condition is true.
153
+ *
154
+ * @param condition - The condition to evaluate.
155
+ * @param error - The exception to throw, a factory function, or an error message string.
156
+ * @throws {Error} If the condition evaluates to true.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * throwIf(user.isBanned, 'User is banned from the system');
161
+ * throwIf(count > 100, () => new ValidationError('Too many items'));
162
+ * ```
163
+ *
164
+ * @public
165
+ * @since 3.0.0
166
+ */
167
+ export declare function throwIf(condition: unknown, error?: Error | string | (() => Error)): void;
168
+ /**
169
+ * Throw an exception unless the given condition is true.
170
+ *
171
+ * @param condition - The condition to evaluate.
172
+ * @param error - The exception to throw, a factory function, or an error message string.
173
+ * @throws {Error} If the condition evaluates to false.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * throwUnless(user.isAdmin, 'Unauthorized access');
178
+ * ```
179
+ *
180
+ * @public
181
+ * @since 3.0.0
182
+ */
183
+ export declare function throwUnless(condition: unknown, error?: Error | string | (() => Error)): void;
184
+ /**
185
+ * Get the value of an environment variable.
186
+ *
187
+ * Automatically detects the runtime environment (Bun or Node.js) to retrieve
188
+ * the variable.
189
+ *
190
+ * @param key - The environment variable name.
191
+ * @param defaultValue - An optional default value to return if the variable is not defined.
192
+ * @returns The environment variable value or the default value.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const debug = env('DEBUG', 'false');
197
+ * const apiKey = env('API_KEY');
198
+ * ```
199
+ *
200
+ * @public
201
+ * @since 3.0.0
202
+ */
203
+ export declare function env<TDefault = string | undefined>(key: string, defaultValue?: TDefault): string | TDefault;
204
+ /**
205
+ * Set the global application instance.
206
+ *
207
+ * This is used internally during the bootstrap process to provide global
208
+ * access to the application instance via the `app()` helper.
209
+ *
210
+ * @param core - The PlanetCore instance to set as global.
211
+ * @internal
212
+ */
213
+ export declare function setApp(core: PlanetCore | null): void;
214
+ /**
215
+ * Check if the global application instance has been initialized and set.
216
+ *
217
+ * @returns `true` if the application instance is set, `false` otherwise.
218
+ *
219
+ * @public
220
+ * @since 3.0.0
221
+ */
222
+ export declare function hasApp(): boolean;
223
+ /**
224
+ * Get the global application instance.
225
+ *
226
+ * Provides access to the core application container, configuration, and services.
227
+ *
228
+ * @returns The initialized PlanetCore instance.
229
+ * @throws {Error} If the application has not been initialized.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const core = app();
234
+ * console.log(core.version);
235
+ * ```
236
+ *
237
+ * @public
238
+ * @since 3.0.0
239
+ */
240
+ export declare function app(): PlanetCore;
241
+ /**
242
+ * Get a configuration value from the application.
243
+ *
244
+ * Supports dot notation for accessing nested configuration properties.
245
+ *
246
+ * @param key - The configuration key in dot notation (e.g., 'app.name').
247
+ * @param defaultValue - An optional default value to return if the key is not found.
248
+ * @returns The configuration value or the default value.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const appName = config('app.name');
253
+ * const port = config('app.port', 3000);
254
+ * ```
255
+ *
256
+ * @public
257
+ * @since 3.0.0
258
+ */
259
+ export declare function config<T = unknown>(key: string, defaultValue?: T): T;
260
+ /**
261
+ * Get the global logger instance.
262
+ *
263
+ * Shortcut for `app().logger`.
264
+ *
265
+ * @returns The application's logger instance.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * logger().info('Operation completed successfully');
270
+ * ```
271
+ *
272
+ * @public
273
+ * @since 3.0.0
274
+ */
275
+ export declare function logger(): import("./Logger").Logger;
276
+ /**
277
+ * Get the application's primary router instance.
278
+ *
279
+ * Shortcut for `app().router`.
280
+ *
281
+ * @returns The router instance.
282
+ *
283
+ * @public
284
+ * @since 3.0.0
285
+ */
286
+ export declare function router(): Router;
287
+ /**
288
+ * Abort the current request with an HTTP exception.
289
+ *
290
+ * Throws an `HttpException` with the specified status code and optional message.
291
+ *
292
+ * @param status - The HTTP status code to return.
293
+ * @param message - An optional custom error message.
294
+ * @throws {HttpException} Always throws this exception.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * abort(403, 'You do not have permission to access this resource');
299
+ * ```
300
+ *
301
+ * @public
302
+ * @since 3.0.0
303
+ */
304
+ export declare function abort(status: ContentfulStatusCode, message?: string): never;
305
+ /**
306
+ * Abort the request if the given condition is true.
307
+ *
308
+ * @param condition - The condition to evaluate.
309
+ * @param status - The HTTP status code to return.
310
+ * @param message - An optional custom error message.
311
+ * @throws {HttpException} If the condition is true.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * abortIf(!user.isActive, 403, 'Account is deactivated');
316
+ * ```
317
+ *
318
+ * @public
319
+ * @since 3.0.0
320
+ */
321
+ export declare function abortIf(condition: unknown, status: ContentfulStatusCode, message?: string): void;
322
+ /**
323
+ * Abort the request unless the given condition is true.
324
+ *
325
+ * @param condition - The condition to evaluate.
326
+ * @param status - The HTTP status code to return.
327
+ * @param message - An optional custom error message.
328
+ * @throws {HttpException} If the condition is false.
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * abortUnless(request.hasValidToken(), 401, 'Invalid authentication token');
333
+ * ```
334
+ *
335
+ * @public
336
+ * @since 3.0.0
337
+ */
338
+ export declare function abortUnless(condition: unknown, status: ContentfulStatusCode, message?: string): void;
@@ -0,0 +1,132 @@
1
+ import type { EventBackend } from '../events/EventBackend';
2
+ import type { EventOptions } from '../events/EventOptions';
3
+ import type { AsyncDetector } from './AsyncDetector';
4
+ import type { MigrationWarner } from './MigrationWarner';
5
+ import type { ActionCallback, HookManagerConfig, ListenerInfo, ListenerOptions } from './types';
6
+ /**
7
+ * 管理 action hook 的登記與執行。
8
+ *
9
+ * Action hook 用於觸發副作用(例如發送 email、記錄日誌)。
10
+ * 支援同步和非同步執行模式,以及透過 EventPriorityQueue 的優先級佇列處理。
11
+ *
12
+ * @internal
13
+ */
14
+ export declare class ActionManager {
15
+ /**
16
+ * 儲存所有已登記的 action callbacks。
17
+ */
18
+ private actions;
19
+ private backend;
20
+ private idempotencyCache;
21
+ private config;
22
+ private asyncDetector;
23
+ private migrationWarner;
24
+ private aggregationManager?;
25
+ constructor(backend: EventBackend, config: HookManagerConfig, asyncDetector: AsyncDetector, migrationWarner: MigrationWarner);
26
+ /**
27
+ * 更新設定。
28
+ */
29
+ updateConfig(config: HookManagerConfig): void;
30
+ /**
31
+ * 更新 backend。
32
+ */
33
+ setBackend(backend: EventBackend): void;
34
+ /**
35
+ * Register an action hook.
36
+ *
37
+ * Actions are used to trigger side effects (e.g., logging, sending emails)
38
+ * at specific points in the application lifecycle.
39
+ *
40
+ * @template TArgs - The type of arguments passed to the action.
41
+ * @param hook - The unique name of the hook.
42
+ * @param callback - The callback function to execute.
43
+ * @param options - Optional listener options (type override, circuit breaker).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * actionManager.addAction('user_registered', async (user: User) => {
48
+ * await sendWelcomeEmail(user)
49
+ * })
50
+ * ```
51
+ */
52
+ addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>, options?: ListenerOptions): void;
53
+ /**
54
+ * 判斷是否需要使用非同步 dispatch,並在需要時發出遷移警告。
55
+ *
56
+ * 此方法僅判斷 dispatch 模式和發出警告,不執行實際的 dispatch。
57
+ * 實際執行由 HookManager.doAction 負責,以確保 ObservableHookManager 等子類別
58
+ * 的多型覆寫(override)能正確攔截 doActionSync / doActionAsync 呼叫。
59
+ *
60
+ * @param hook - Hook name
61
+ * @param args - Event args (unused here, kept for API consistency)
62
+ * @param options - Event options
63
+ * @returns 'async' if async dispatch should be used, 'sync' otherwise
64
+ */
65
+ resolveDispatchMode<TArgs = unknown>(hook: string, _args: TArgs, options?: EventOptions): 'async' | 'sync';
66
+ /**
67
+ * Run all registered actions synchronously (legacy mode).
68
+ *
69
+ * @template TArgs - The type of arguments passed to the action.
70
+ * @param hook - The name of the hook.
71
+ * @param args - The arguments to pass to the callbacks.
72
+ */
73
+ doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
74
+ /**
75
+ * Run all registered actions asynchronously via priority queue.
76
+ *
77
+ * 透過 EventPriorityQueue 進行非同步 dispatch,支援:
78
+ * - 優先級處理(high > normal > low)
79
+ * - 超時處理
80
+ * - 順序保證(strict、partition、none)
81
+ * - 冪等性
82
+ *
83
+ * @template TArgs - The type of arguments passed to the action.
84
+ * @param hook - The name of the hook.
85
+ * @param args - The arguments to pass to the callbacks.
86
+ * @param options - Event options for async dispatch.
87
+ */
88
+ doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
89
+ /**
90
+ * Determine if async dispatch should be used.
91
+ *
92
+ * @param callbacks - Callbacks to check
93
+ * @param options - Event options
94
+ * @returns True if async dispatch should be used
95
+ */
96
+ shouldUseAsyncDispatch(callbacks: ActionCallback[], options?: EventOptions): boolean;
97
+ /**
98
+ * Determine the dispatch mode for an event.
99
+ *
100
+ * @param hook - Hook name
101
+ * @param options - Optional event options
102
+ * @returns The dispatch mode: 'sync' or 'async'
103
+ */
104
+ detectMode(hook: string, options?: EventOptions): 'sync' | 'async';
105
+ /**
106
+ * Check if any listener for a hook is async (including type overrides).
107
+ *
108
+ * @param hook - Hook name
109
+ * @returns True if any listener is async
110
+ */
111
+ hasAsyncListeners(hook: string): boolean;
112
+ /**
113
+ * Get detailed information about all listeners for a hook.
114
+ *
115
+ * @param hook - Hook name
116
+ * @returns Array of listener info objects
117
+ */
118
+ getListenerInfo(hook: string): ListenerInfo[];
119
+ /**
120
+ * Get all registered listeners for a hook.
121
+ *
122
+ * @param hook - Hook name
123
+ * @returns Array of callbacks
124
+ */
125
+ getListeners(hook: string): ActionCallback[];
126
+ /**
127
+ * Remove all listeners for a specific action hook.
128
+ *
129
+ * @param hook - Hook name
130
+ */
131
+ removeAction(hook: string): void;
132
+ }
@@ -0,0 +1,84 @@
1
+ import type { ActionCallback } from './types';
2
+ /**
3
+ * 負責偵測 callback 函數是否為非同步(async)。
4
+ *
5
+ * 提供靜態偵測(透過函數簽名)和運行時偵測(透過執行函數)兩種方式,
6
+ * 並包含快取機制以提升重複偵測的性能。
7
+ *
8
+ * @internal
9
+ */
10
+ export declare class AsyncDetector {
11
+ /**
12
+ * 快取非同步偵測結果(WeakMap 以自動垃圾回收)。
13
+ */
14
+ private asyncDetectionCache;
15
+ /**
16
+ * 快取中的項目計數(供測試/偵錯使用)。
17
+ */
18
+ private asyncDetectionCacheCount;
19
+ /**
20
+ * 儲存 listener type override(callback -> type)。
21
+ */
22
+ private listenerTypeOverrides;
23
+ /**
24
+ * 設定 listener 的 type override。
25
+ *
26
+ * @param callback - 目標 callback
27
+ * @param type - Type override 值
28
+ */
29
+ setTypeOverride(callback: ActionCallback, type: 'sync' | 'async' | 'auto'): void;
30
+ /**
31
+ * 取得 listener 的 type override。
32
+ *
33
+ * @param callback - 目標 callback
34
+ * @returns Type override 或 undefined
35
+ */
36
+ getTypeOverride(callback: ActionCallback): 'sync' | 'async' | 'auto' | undefined;
37
+ /**
38
+ * Check if a callback is an async function (with caching).
39
+ *
40
+ * Detection methods:
41
+ * 1. Check cache first
42
+ * 2. Check type override
43
+ * 3. Check constructor.name === 'AsyncFunction'
44
+ * 4. Fallback: Check function string representation
45
+ *
46
+ * @param callback - The callback to check
47
+ * @returns True if the callback is async
48
+ * @public
49
+ */
50
+ isAsyncListener(callback: ActionCallback): boolean;
51
+ /**
52
+ * Check if a listener is effectively async (considering type override).
53
+ *
54
+ * @param callback - The callback to check
55
+ * @returns True if the listener should be treated as async
56
+ */
57
+ isEffectivelyAsync(callback: ActionCallback): boolean;
58
+ /**
59
+ * Runtime detection for functions that return Promises but aren't declared async.
60
+ *
61
+ * 此方法會實際執行 callback 來檢查是否回傳 Promise,請謹慎使用。
62
+ *
63
+ * @param callback - The callback to check
64
+ * @param testArgs - Arguments to pass to the callback for testing
65
+ * @returns True if the callback returns a Promise
66
+ * @public
67
+ */
68
+ isAsyncListenerRuntime<TArgs = unknown>(callback: ActionCallback<TArgs>, testArgs: TArgs): Promise<boolean>;
69
+ /**
70
+ * Get the size of the async detection cache (for testing/debugging).
71
+ *
72
+ * @returns Number of cached detection results
73
+ */
74
+ getCacheSize(): number;
75
+ /**
76
+ * Clear the async detection cache.
77
+ */
78
+ clearCache(): void;
79
+ /**
80
+ * 快取非同步偵測結果。
81
+ * @internal
82
+ */
83
+ private cacheResult;
84
+ }
@@ -0,0 +1,71 @@
1
+ import type { FilterCallback } from './types';
2
+ /**
3
+ * 管理 filter hook 的登記與執行。
4
+ *
5
+ * Filter hook 用於轉換數值:每個 callback 接收前一個 callback 的回傳值,
6
+ * 並返回新的轉換後數值。所有 callback 按登記順序依次執行。
7
+ *
8
+ * @internal
9
+ */
10
+ export declare class FilterManager {
11
+ /**
12
+ * 儲存所有已登記的 filter callbacks。
13
+ * Map key 為 hook 名稱,value 為 callback 陣列。
14
+ */
15
+ private filters;
16
+ /**
17
+ * Register a filter hook.
18
+ *
19
+ * Filters are used to transform a value (input/output) through a chain of
20
+ * callbacks. Each callback must return the modified value.
21
+ *
22
+ * @template T - The type of value being filtered.
23
+ * @param hook - The unique name of the hook.
24
+ * @param callback - The callback function to execute.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * filterManager.addFilter('content', async (content: string) => {
29
+ * return content.toUpperCase()
30
+ * })
31
+ * ```
32
+ */
33
+ addFilter<T = unknown>(hook: string, callback: FilterCallback<T>): void;
34
+ /**
35
+ * Apply all registered filters sequentially.
36
+ *
37
+ * Each callback receives the previous callback's return value.
38
+ *
39
+ * @template T - The type of value being filtered.
40
+ * @param hook - The name of the hook.
41
+ * @param initialValue - The initial value to filter.
42
+ * @param args - Additional arguments to pass to the callbacks.
43
+ * @returns The final filtered value.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const content = await filterManager.applyFilters('content', 'hello world')
48
+ * ```
49
+ */
50
+ applyFilters<T = unknown>(hook: string, initialValue: T, ...args: unknown[]): Promise<T>;
51
+ /**
52
+ * Check if any filters are registered for a hook.
53
+ *
54
+ * @param hook - Hook name
55
+ * @returns True if at least one filter is registered
56
+ */
57
+ hasFilters(hook: string): boolean;
58
+ /**
59
+ * Get count of registered filters for a hook.
60
+ *
61
+ * @param hook - Hook name
62
+ * @returns Number of registered filters
63
+ */
64
+ getFilterCount(hook: string): number;
65
+ /**
66
+ * Remove all filters for a specific hook.
67
+ *
68
+ * @param hook - Hook name
69
+ */
70
+ removeFilters(hook: string): void;
71
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Migration warning manager for deprecation warnings.
3
+ *
4
+ * 管理遷移警告訊息,支援透過環境變數抑制特定事件的警告。
5
+ *
6
+ * @internal
7
+ */
8
+ export declare class MigrationWarner {
9
+ private suppressedWarnings;
10
+ constructor();
11
+ /**
12
+ * 發出遷移警告訊息。
13
+ *
14
+ * @param eventName - 事件名稱
15
+ * @param message - 警告訊息
16
+ */
17
+ warn(eventName: string, message: string): void;
18
+ /**
19
+ * 抑制特定事件的遷移警告。
20
+ *
21
+ * @param eventName - 要抑制警告的事件名稱
22
+ */
23
+ suppress(eventName: string): void;
24
+ }