@flight-framework/core 0.2.3 → 0.2.5
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/dist/chunk-FSJNOPYE.js +197 -0
- package/dist/chunk-FSJNOPYE.js.map +1 -0
- package/dist/{chunk-VOBQDQKX.js → chunk-LBYDTULN.js} +3 -3
- package/dist/{chunk-VOBQDQKX.js.map → chunk-LBYDTULN.js.map} +1 -1
- package/dist/chunk-PL37KFRJ.js +3 -0
- package/dist/chunk-PL37KFRJ.js.map +1 -0
- package/dist/chunk-YHEVHRLH.js +46 -0
- package/dist/chunk-YHEVHRLH.js.map +1 -0
- package/dist/errors/index.d.ts +267 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -11
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +73 -0
- package/dist/react/index.js +52 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rsc/adapters/index.js +1 -1
- package/dist/rsc/index.js +4 -4
- package/dist/server/index.js +2 -2
- package/dist/utils/index.d.ts +42 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +18 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flight-framework/core - Error Handling
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive error handling utilities for Flight applications.
|
|
5
|
+
* All utilities are OPTIONAL - developers can use their own error handling.
|
|
6
|
+
*
|
|
7
|
+
* Philosophy: Flight OFFERS these utilities, but never IMPOSES them.
|
|
8
|
+
* Using throw new Error() works perfectly fine - this is your choice.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Options for creating a Flight error
|
|
12
|
+
*/
|
|
13
|
+
interface FlightErrorOptions {
|
|
14
|
+
/** HTTP status code */
|
|
15
|
+
statusCode: number;
|
|
16
|
+
/** Short status message (e.g., "Not Found") */
|
|
17
|
+
statusMessage?: string;
|
|
18
|
+
/** Detailed error message */
|
|
19
|
+
message?: string;
|
|
20
|
+
/** Additional data to include with the error */
|
|
21
|
+
data?: Record<string, unknown>;
|
|
22
|
+
/** If true, shows full-screen error page instead of error boundary */
|
|
23
|
+
fatal?: boolean;
|
|
24
|
+
/** Original error that caused this error */
|
|
25
|
+
cause?: Error;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extended error props with digest for production error correlation
|
|
29
|
+
*/
|
|
30
|
+
interface FlightErrorProps {
|
|
31
|
+
/** The error object */
|
|
32
|
+
error: Error & {
|
|
33
|
+
digest?: string;
|
|
34
|
+
};
|
|
35
|
+
/** Function to attempt recovery by re-rendering */
|
|
36
|
+
reset: () => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reset details provided to onReset callback
|
|
40
|
+
*/
|
|
41
|
+
interface ResetDetails {
|
|
42
|
+
/** Reason for the reset */
|
|
43
|
+
reason: 'imperative-api' | 'keys';
|
|
44
|
+
/** Arguments passed to resetErrorBoundary (if imperative) */
|
|
45
|
+
args?: unknown[];
|
|
46
|
+
/** Previous resetKeys values (if keys changed) */
|
|
47
|
+
prev?: unknown[];
|
|
48
|
+
/** New resetKeys values (if keys changed) */
|
|
49
|
+
next?: unknown[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Options for error boundary behavior
|
|
53
|
+
*/
|
|
54
|
+
interface ErrorBoundaryOptions {
|
|
55
|
+
/** Keys that trigger automatic reset when changed */
|
|
56
|
+
resetKeys?: unknown[];
|
|
57
|
+
/** Callback when error boundary resets */
|
|
58
|
+
onReset?: (details: ResetDetails) => void;
|
|
59
|
+
/** Callback when error is caught */
|
|
60
|
+
onError?: (error: Error, info: {
|
|
61
|
+
componentStack?: string;
|
|
62
|
+
}) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Custom error class with status code and metadata support.
|
|
66
|
+
*
|
|
67
|
+
* You can use this class or regular Error - Flight handles both.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* throw new FlightError({
|
|
72
|
+
* statusCode: 404,
|
|
73
|
+
* message: 'User not found',
|
|
74
|
+
* data: { userId: '123' }
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare class FlightError extends Error {
|
|
79
|
+
/** HTTP status code */
|
|
80
|
+
readonly statusCode: number;
|
|
81
|
+
/** Short status message */
|
|
82
|
+
readonly statusMessage: string;
|
|
83
|
+
/** Additional error data */
|
|
84
|
+
readonly data?: Record<string, unknown>;
|
|
85
|
+
/** Whether this is a fatal error (shows full-screen) */
|
|
86
|
+
readonly fatal: boolean;
|
|
87
|
+
/** Unique digest for production error correlation */
|
|
88
|
+
readonly digest?: string;
|
|
89
|
+
constructor(options: FlightErrorOptions);
|
|
90
|
+
/**
|
|
91
|
+
* Convert to plain object for serialization
|
|
92
|
+
*/
|
|
93
|
+
toJSON(): Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 400 Bad Request error
|
|
97
|
+
*/
|
|
98
|
+
declare class BadRequestError extends FlightError {
|
|
99
|
+
constructor(message?: string, data?: Record<string, unknown>);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 401 Unauthorized error
|
|
103
|
+
*/
|
|
104
|
+
declare class UnauthorizedError extends FlightError {
|
|
105
|
+
constructor(message?: string, data?: Record<string, unknown>);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 403 Forbidden error
|
|
109
|
+
*/
|
|
110
|
+
declare class ForbiddenError extends FlightError {
|
|
111
|
+
constructor(message?: string, data?: Record<string, unknown>);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 404 Not Found error
|
|
115
|
+
*/
|
|
116
|
+
declare class NotFoundError extends FlightError {
|
|
117
|
+
constructor(message?: string, data?: Record<string, unknown>);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 500 Internal Server Error
|
|
121
|
+
*/
|
|
122
|
+
declare class InternalError extends FlightError {
|
|
123
|
+
constructor(message?: string, data?: Record<string, unknown>);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Create a FlightError with the specified options.
|
|
127
|
+
*
|
|
128
|
+
* This is a convenience function - you can also use `new FlightError()` directly
|
|
129
|
+
* or just `throw new Error()` - Flight handles all cases.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // With full options
|
|
134
|
+
* throw createError({
|
|
135
|
+
* statusCode: 404,
|
|
136
|
+
* message: 'Product not found',
|
|
137
|
+
* data: { productId: 'abc123' }
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* // Simple string shorthand (becomes 500 error)
|
|
141
|
+
* throw createError('Something went wrong');
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function createError(options: FlightErrorOptions | string): FlightError;
|
|
145
|
+
/**
|
|
146
|
+
* Create a 404 Not Found error.
|
|
147
|
+
* Convenience function equivalent to `createError({ statusCode: 404, ... })`.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* if (!user) {
|
|
152
|
+
* throw notFound('User not found');
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function notFound(message?: string, data?: Record<string, unknown>): never;
|
|
157
|
+
/**
|
|
158
|
+
* Create a 403 Forbidden error.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* if (!user.isAdmin) {
|
|
163
|
+
* throw forbidden('Admin access required');
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
declare function forbidden(message?: string, data?: Record<string, unknown>): never;
|
|
168
|
+
/**
|
|
169
|
+
* Create a 401 Unauthorized error.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* if (!session) {
|
|
174
|
+
* throw unauthorized('Please log in to continue');
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function unauthorized(message?: string, data?: Record<string, unknown>): never;
|
|
179
|
+
declare global {
|
|
180
|
+
interface Window {
|
|
181
|
+
__FLIGHT_ERROR__?: FlightError | null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Programmatically show an error page.
|
|
186
|
+
*
|
|
187
|
+
* This triggers the nearest error boundary or navigates to the error page.
|
|
188
|
+
* Only works on the client side.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Show error with full options
|
|
193
|
+
* showError({
|
|
194
|
+
* statusCode: 500,
|
|
195
|
+
* message: 'Connection lost'
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* // Simple string shorthand
|
|
199
|
+
* showError('Something went wrong');
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare function showError(error: FlightErrorOptions | FlightError | string): void;
|
|
203
|
+
/**
|
|
204
|
+
* Clear the current error state and optionally redirect.
|
|
205
|
+
*
|
|
206
|
+
* Use this to dismiss an error and return to normal state.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // Just clear the error
|
|
211
|
+
* clearError();
|
|
212
|
+
*
|
|
213
|
+
* // Clear and redirect to home
|
|
214
|
+
* clearError({ redirect: '/' });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
declare function clearError(options?: {
|
|
218
|
+
redirect?: string;
|
|
219
|
+
}): void;
|
|
220
|
+
/**
|
|
221
|
+
* Get the current error from global state.
|
|
222
|
+
* Returns null if no error is active.
|
|
223
|
+
*/
|
|
224
|
+
declare function getError(): FlightError | null;
|
|
225
|
+
/**
|
|
226
|
+
* Check if an error is a FlightError
|
|
227
|
+
*/
|
|
228
|
+
declare function isFlightError(error: unknown): error is FlightError;
|
|
229
|
+
/**
|
|
230
|
+
* Check if an error is a NotFoundError (404)
|
|
231
|
+
*/
|
|
232
|
+
declare function isNotFoundError(error: unknown): error is NotFoundError;
|
|
233
|
+
/**
|
|
234
|
+
* Check if an error is a ForbiddenError (403)
|
|
235
|
+
*/
|
|
236
|
+
declare function isForbiddenError(error: unknown): error is ForbiddenError;
|
|
237
|
+
/**
|
|
238
|
+
* Check if an error is an UnauthorizedError (401)
|
|
239
|
+
*/
|
|
240
|
+
declare function isUnauthorizedError(error: unknown): error is UnauthorizedError;
|
|
241
|
+
/**
|
|
242
|
+
* Get the status code from any error.
|
|
243
|
+
* Returns 500 for non-FlightError errors.
|
|
244
|
+
*/
|
|
245
|
+
declare function getErrorStatusCode(error: unknown): number;
|
|
246
|
+
/**
|
|
247
|
+
* Create an error Response from a FlightError.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* try {
|
|
252
|
+
* // ... some operation
|
|
253
|
+
* } catch (error) {
|
|
254
|
+
* return createErrorResponse(error);
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare function createErrorResponse(error: unknown): Response;
|
|
259
|
+
/**
|
|
260
|
+
* Wrap an error with a digest if it doesn't have one.
|
|
261
|
+
* Useful for adding correlation IDs to third-party errors.
|
|
262
|
+
*/
|
|
263
|
+
declare function wrapWithDigest<T extends Error>(error: T): T & {
|
|
264
|
+
digest: string;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export { BadRequestError, type ErrorBoundaryOptions, FlightError, type FlightErrorOptions, type FlightErrorProps, ForbiddenError, InternalError, NotFoundError, type ResetDetails, UnauthorizedError, clearError, createError, createErrorResponse, forbidden, getError, getErrorStatusCode, isFlightError, isForbiddenError, isNotFoundError, isUnauthorizedError, notFound, showError, unauthorized, wrapWithDigest };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BadRequestError, FlightError, ForbiddenError, InternalError, NotFoundError, UnauthorizedError, clearError, createError, createErrorResponse, forbidden, getError, getErrorStatusCode, isFlightError, isForbiddenError, isNotFoundError, isUnauthorizedError, notFound, showError, unauthorized, wrapWithDigest } from '../chunk-FSJNOPYE.js';
|
|
2
|
+
import '../chunk-YHEVHRLH.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export { DEFAULT_STREAMING_HINTS, GetStreamingConfig, ResolvedStreamingConfig, S
|
|
|
19
19
|
export { ServerContext as RSCServerContext, createServerContext, isNotFoundError, isRedirectError as isRscRedirectError, notFound, redirect as rscRedirect } from './rsc/context.js';
|
|
20
20
|
export { BoundaryType as RSCBoundaryType, detectBoundaryType, hasUseClientDirective, hasUseServerDirective } from './rsc/boundaries.js';
|
|
21
21
|
export { ClientComponent, ComponentType as RSCComponentType, RenderContext as RSCRenderContext, ServerComponent, composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, revalidatePath as rscRevalidatePath, revalidateTag as rscRevalidateTag, serializeProps, serverFetch, withErrorBoundary } from './rsc/legacy.js';
|
|
22
|
+
export { BadRequestError, ErrorBoundaryOptions, FlightError, FlightErrorOptions, FlightErrorProps, ForbiddenError, InternalError, NotFoundError, ResetDetails, UnauthorizedError, clearError, createError, createErrorResponse, forbidden as createForbidden, notFound as createNotFound, unauthorized as createUnauthorized, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError, wrapWithDigest } from './errors/index.js';
|
|
23
|
+
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './utils/index.js';
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* @flight-framework/core - Route Rules Configuration
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
export { createIslandRegistry, createPreactIslandAdapter, createReactIslandAdapter, createSolidIslandAdapter, createVueIslandAdapter, defineIsland, hydrateIslands, registerFlightIslandElement, registerIsland, renderIsland, renderIslands, setIslandAdapter } from './chunk-WFAWAHJH.js';
|
|
2
|
-
export { DEFAULT_STREAMING_HINTS, createStreamingController, generateCacheKey, getStreamingCacheHeaders, hasStreamingConfig, isValidStreamingHints, loadRouteWithStreaming, resolveStreamingConfig, shouldStream } from './chunk-XSY5AAXT.js';
|
|
3
|
-
export { streamWithPriority, validateDependencies } from './chunk-WOEIJWGJ.js';
|
|
4
1
|
export { MetricsAggregator, createHttpObserver, createInstrumentedStream, createLoggerObserver } from './chunk-6BDCTUQY.js';
|
|
5
2
|
export { DEFAULT_BOT_PATTERNS, addStreamingHeaders, createConditionalStreamer, createStreamingResponse as createConditionalStreamingResponse, createStaticResponse, isBot, isSlowConnection, prefersNoStream, streamIf, supportsStreaming } from './chunk-XOIYNY4I.js';
|
|
6
3
|
export { createHTMXStreamAdapter, createReactStreamAdapter, createSolidStreamAdapter, createStreamAdapter, createSvelteStreamAdapter, createVueStreamAdapter } from './chunk-MQQLYWZZ.js';
|
|
4
|
+
export { createIslandRegistry, createPreactIslandAdapter, createReactIslandAdapter, createSolidIslandAdapter, createVueIslandAdapter, defineIsland, hydrateIslands, registerFlightIslandElement, registerIsland, renderIsland, renderIslands, setIslandAdapter } from './chunk-WFAWAHJH.js';
|
|
5
|
+
export { DEFAULT_STREAMING_HINTS, createStreamingController, generateCacheKey, getStreamingCacheHeaders, hasStreamingConfig, isValidStreamingHints, loadRouteWithStreaming, resolveStreamingConfig, shouldStream } from './chunk-XSY5AAXT.js';
|
|
6
|
+
export { streamWithPriority, validateDependencies } from './chunk-WOEIJWGJ.js';
|
|
7
|
+
import './chunk-SUILH4ID.js';
|
|
8
|
+
export { createServer } from './chunk-LBYDTULN.js';
|
|
9
|
+
export { defineConfig } from './chunk-IXMD5QH2.js';
|
|
7
10
|
export { createFileRouter, loadRoutes, scanRoutes } from './chunk-54HPVE7N.js';
|
|
8
11
|
export { RedirectError, redirect as actionRedirect, cookies, executeAction, executeFormAction, getAction, handleActionRequest, isRedirectError, parseFormData, registerAction } from './chunk-3QP3E7HS.js';
|
|
9
12
|
export { createRouteContext, error, json, parseBody, redirect } from './chunk-W6D62JCI.js';
|
|
10
13
|
export { createLazyContent, createStreamingResponse, createStreamingSSR, renderWithStreaming, streamParallel, streamSequential } from './chunk-RSVA2EYO.js';
|
|
11
14
|
import './chunk-63SCEXD7.js';
|
|
15
|
+
export { createServerContext, isNotFoundError, isRedirectError as isRscRedirectError, notFound, redirect as rscRedirect } from './chunk-62C7LX2E.js';
|
|
12
16
|
import './chunk-PVUMB632.js';
|
|
13
17
|
import './chunk-P6WSBVDT.js';
|
|
18
|
+
import './chunk-K2CQZPCG.js';
|
|
14
19
|
export { composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, revalidatePath as rscRevalidatePath, revalidateTag as rscRevalidateTag, serializeProps, serverFetch, withErrorBoundary } from './chunk-3ZSSRE6M.js';
|
|
15
20
|
import './chunk-ZIE56LCA.js';
|
|
21
|
+
export { detectBoundaryType, hasUseClientDirective, hasUseServerDirective } from './chunk-PDW5WCMW.js';
|
|
16
22
|
import './chunk-Y22AMGTM.js';
|
|
17
|
-
import './chunk-MDQNNIHH.js';
|
|
18
23
|
import './chunk-TASAT7KB.js';
|
|
19
24
|
import './chunk-2F2QU6RC.js';
|
|
20
25
|
import './chunk-VPFMHGEV.js';
|
|
21
|
-
import './chunk-
|
|
22
|
-
export {
|
|
23
|
-
|
|
26
|
+
import './chunk-MDQNNIHH.js';
|
|
27
|
+
export { BadRequestError, FlightError, ForbiddenError, InternalError, NotFoundError, UnauthorizedError, clearError, createError, createErrorResponse, forbidden as createForbidden, notFound as createNotFound, unauthorized as createUnauthorized, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError, wrapWithDigest } from './chunk-FSJNOPYE.js';
|
|
28
|
+
import './chunk-PL37KFRJ.js';
|
|
29
|
+
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './chunk-YHEVHRLH.js';
|
|
30
|
+
export { createRouter } from './chunk-GCQZ4FHI.js';
|
|
24
31
|
import './chunk-ZVC3ZWLM.js';
|
|
25
32
|
export { cacheKey, cached, createCache, dedupe, jsonSerializer, memory } from './chunk-R7SQAREQ.js';
|
|
26
|
-
import './chunk-SUILH4ID.js';
|
|
27
|
-
export { createServer } from './chunk-VOBQDQKX.js';
|
|
28
|
-
export { createRouter } from './chunk-GCQZ4FHI.js';
|
|
29
33
|
export { createMiddlewareChain } from './chunk-KWFX6WHG.js';
|
|
30
|
-
export { defineConfig } from './chunk-IXMD5QH2.js';
|
|
31
34
|
import { promises } from 'fs';
|
|
32
35
|
import { dirname, join } from 'path';
|
|
33
36
|
|