@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.
- package/README.md +100 -6
- package/README.zh-TW.md +101 -6
- package/dist/Application.d.ts +256 -0
- package/dist/CommandKernel.d.ts +33 -0
- package/dist/ConfigManager.d.ts +65 -0
- package/dist/Container/RequestScopeManager.d.ts +62 -0
- package/dist/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/Container.d.ts +153 -0
- package/dist/ErrorHandler.d.ts +66 -0
- package/dist/Event.d.ts +5 -0
- package/dist/EventManager.d.ts +123 -0
- package/dist/GlobalErrorHandlers.d.ts +47 -0
- package/dist/GravitoServer.d.ts +28 -0
- package/dist/HookManager.d.ts +435 -0
- package/dist/Listener.d.ts +4 -0
- package/dist/Logger.d.ts +20 -0
- package/dist/PlanetCore.d.ts +402 -0
- package/dist/RequestContext.d.ts +97 -0
- package/dist/Route.d.ts +36 -0
- package/dist/Router.d.ts +270 -0
- package/dist/ServiceProvider.d.ts +178 -0
- package/dist/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/adapters/bun/AdaptiveAdapter.d.ts +99 -0
- package/dist/adapters/bun/BunContext.d.ts +54 -0
- package/dist/adapters/bun/BunNativeAdapter.d.ts +66 -0
- package/dist/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/adapters/bun/BunWebSocketHandler.d.ts +48 -0
- package/dist/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/adapters/bun/RadixRouter.d.ts +32 -0
- package/dist/adapters/bun/index.d.ts +7 -0
- package/dist/adapters/bun/types.d.ts +20 -0
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/types.d.ts +235 -0
- package/dist/binary/BinaryUtils.d.ts +105 -0
- package/dist/binary/index.d.ts +5 -0
- package/dist/cli/queue-commands.d.ts +6 -0
- package/dist/compat/async-local-storage.browser.d.ts +9 -0
- package/dist/compat/async-local-storage.d.ts +7 -0
- package/dist/compat/crypto.browser.d.ts +5 -0
- package/dist/compat/crypto.d.ts +6 -0
- package/dist/compat.cjs +42 -11
- package/dist/compat.cjs.map +9 -0
- package/dist/compat.d.ts +23 -1
- package/dist/compat.js +3 -0
- package/dist/compat.js.map +9 -0
- package/dist/engine/AOTRouter.d.ts +139 -0
- package/dist/engine/FastContext.d.ts +141 -0
- package/dist/engine/Gravito.d.ts +131 -0
- package/dist/engine/MinimalContext.d.ts +102 -0
- package/dist/engine/analyzer.d.ts +113 -0
- package/dist/engine/constants.d.ts +23 -0
- package/dist/engine/index.cjs +576 -647
- package/dist/engine/index.cjs.map +22 -0
- package/dist/engine/index.d.ts +14 -910
- package/dist/engine/index.js +576 -623
- package/dist/engine/index.js.map +22 -0
- package/dist/engine/path.d.ts +26 -0
- package/dist/engine/pool.d.ts +83 -0
- package/dist/engine/types.d.ts +149 -0
- package/dist/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/events/BackpressureManager.d.ts +215 -0
- package/dist/events/CircuitBreaker.d.ts +229 -0
- package/dist/events/DeadLetterQueue.d.ts +219 -0
- package/dist/events/EventBackend.d.ts +12 -0
- package/dist/events/EventOptions.d.ts +204 -0
- package/dist/events/EventPriorityQueue.d.ts +63 -0
- package/dist/events/FlowControlStrategy.d.ts +109 -0
- package/dist/events/IdempotencyCache.d.ts +60 -0
- package/dist/events/MessageQueueBridge.d.ts +184 -0
- package/dist/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/events/RetryScheduler.d.ts +104 -0
- package/dist/events/WorkerPool.d.ts +98 -0
- package/dist/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/events/aggregation/index.d.ts +10 -0
- package/dist/events/aggregation/types.d.ts +117 -0
- package/dist/events/index.d.ts +26 -0
- package/dist/events/observability/EventMetrics.d.ts +132 -0
- package/dist/events/observability/EventTracer.d.ts +68 -0
- package/dist/events/observability/EventTracing.d.ts +161 -0
- package/dist/events/observability/OTelEventMetrics.d.ts +332 -0
- package/dist/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/events/observability/index.d.ts +24 -0
- package/dist/events/observability/metrics-types.d.ts +16 -0
- package/dist/events/queue-core.d.ts +77 -0
- package/dist/events/task-executor.d.ts +51 -0
- package/dist/events/types.d.ts +134 -0
- package/dist/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/exceptions/GravitoException.d.ts +23 -0
- package/dist/exceptions/HttpException.d.ts +9 -0
- package/dist/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/exceptions/ValidationException.d.ts +22 -0
- package/dist/exceptions/index.d.ts +7 -0
- package/dist/ffi/NativeAccelerator.d.ts +69 -0
- package/dist/ffi/NativeHasher.d.ts +139 -0
- package/dist/ffi/cbor-fallback.d.ts +96 -0
- package/dist/ffi/hash-fallback.d.ts +33 -0
- package/dist/ffi/index.cjs +621 -0
- package/dist/ffi/index.cjs.map +14 -0
- package/dist/ffi/index.d.ts +10 -0
- package/dist/ffi/index.js +602 -0
- package/dist/ffi/index.js.map +14 -0
- package/dist/ffi/types.d.ts +135 -0
- package/dist/health/HealthProvider.d.ts +67 -0
- package/dist/helpers/Arr.d.ts +19 -0
- package/dist/helpers/Str.d.ts +38 -0
- package/dist/helpers/data.d.ts +25 -0
- package/dist/helpers/errors.d.ts +34 -0
- package/dist/helpers/response.d.ts +41 -0
- package/dist/helpers.d.ts +338 -0
- package/dist/hooks/ActionManager.d.ts +132 -0
- package/dist/hooks/AsyncDetector.d.ts +84 -0
- package/dist/hooks/FilterManager.d.ts +71 -0
- package/dist/hooks/MigrationWarner.d.ts +24 -0
- package/dist/hooks/dlq-operations.d.ts +60 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/types.d.ts +107 -0
- package/dist/http/CookieJar.d.ts +51 -0
- package/dist/http/cookie.d.ts +29 -0
- package/dist/http/index.d.ts +12 -0
- package/dist/{compat-CI8hiulX.d.cts → http/types.d.ts} +29 -16
- package/dist/index.browser.d.ts +34 -0
- package/dist/index.cjs +10525 -11171
- package/dist/index.cjs.map +168 -0
- package/dist/index.d.ts +58 -10981
- package/dist/index.js +10861 -10997
- package/dist/index.js.map +168 -0
- package/dist/observability/QueueDashboard.d.ts +136 -0
- package/dist/observability/contracts.d.ts +137 -0
- package/dist/observability/index.d.ts +13 -0
- package/dist/reliability/DeadLetterQueueManager.d.ts +349 -0
- package/dist/reliability/RetryPolicy.d.ts +217 -0
- package/dist/reliability/index.d.ts +6 -0
- package/dist/router/ControllerDispatcher.d.ts +12 -0
- package/dist/router/RequestValidator.d.ts +20 -0
- package/dist/runtime/adapter-bun.d.ts +12 -0
- package/dist/runtime/adapter-deno.d.ts +12 -0
- package/dist/runtime/adapter-node.d.ts +12 -0
- package/dist/runtime/adapter-unknown.d.ts +13 -0
- package/dist/runtime/archive.d.ts +17 -0
- package/dist/runtime/compression.d.ts +21 -0
- package/dist/runtime/deep-equals.d.ts +56 -0
- package/dist/runtime/detection.d.ts +22 -0
- package/dist/runtime/escape.d.ts +34 -0
- package/dist/runtime/index.browser.d.ts +20 -0
- package/dist/runtime/index.d.ts +44 -0
- package/dist/runtime/markdown.d.ts +44 -0
- package/dist/runtime/types.d.ts +436 -0
- package/dist/runtime-helpers.d.ts +67 -0
- package/dist/runtime.d.ts +11 -0
- package/dist/security/Encrypter.d.ts +33 -0
- package/dist/security/Hasher.d.ts +29 -0
- package/dist/testing/HttpTester.d.ts +39 -0
- package/dist/testing/TestResponse.d.ts +78 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/transpiler-utils.d.ts +170 -0
- package/dist/types/events.d.ts +94 -0
- package/dist/types.d.ts +13 -0
- package/package.json +21 -52
- package/src/ffi/native/cbor.c +1148 -0
- package/dist/Metrics-VOWWRNNR.js +0 -219
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/compat-CI8hiulX.d.ts +0 -376
- package/dist/compat.d.cts +0 -1
- package/dist/engine/index.d.cts +0 -922
- 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
|
+
}
|