@flightdev/core 0.6.7
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/LICENSE +21 -0
- package/README.md +541 -0
- package/dist/actions/index.d.ts +743 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/adapters/index.d.ts +502 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/cache/index.d.ts +191 -0
- package/dist/cache/index.js +3 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/chunk-62HISNA3.js +354 -0
- package/dist/chunk-62HISNA3.js.map +1 -0
- package/dist/chunk-63LWTEDQ.js +341 -0
- package/dist/chunk-63LWTEDQ.js.map +1 -0
- package/dist/chunk-63SCEXD7.js +3 -0
- package/dist/chunk-63SCEXD7.js.map +1 -0
- package/dist/chunk-72MYOTUB.js +667 -0
- package/dist/chunk-72MYOTUB.js.map +1 -0
- package/dist/chunk-7CNW24MQ.js +257 -0
- package/dist/chunk-7CNW24MQ.js.map +1 -0
- package/dist/chunk-7WIEAUJT.js +300 -0
- package/dist/chunk-7WIEAUJT.js.map +1 -0
- package/dist/chunk-7ZZF4ULK.js +259 -0
- package/dist/chunk-7ZZF4ULK.js.map +1 -0
- package/dist/chunk-AE3JTS73.js +222 -0
- package/dist/chunk-AE3JTS73.js.map +1 -0
- package/dist/chunk-AP5NLUSB.js +258 -0
- package/dist/chunk-AP5NLUSB.js.map +1 -0
- package/dist/chunk-C37YQQI7.js +221 -0
- package/dist/chunk-C37YQQI7.js.map +1 -0
- package/dist/chunk-DCLVXFVH.js +225 -0
- package/dist/chunk-DCLVXFVH.js.map +1 -0
- package/dist/chunk-DZMWWDFD.js +223 -0
- package/dist/chunk-DZMWWDFD.js.map +1 -0
- package/dist/chunk-GCQZ4FHI.js +245 -0
- package/dist/chunk-GCQZ4FHI.js.map +1 -0
- package/dist/chunk-IPP44XY6.js +47 -0
- package/dist/chunk-IPP44XY6.js.map +1 -0
- package/dist/chunk-IW7FTQQX.js +267 -0
- package/dist/chunk-IW7FTQQX.js.map +1 -0
- package/dist/chunk-JX4YSCBH.js +428 -0
- package/dist/chunk-JX4YSCBH.js.map +1 -0
- package/dist/chunk-KX6UYWWR.js +229 -0
- package/dist/chunk-KX6UYWWR.js.map +1 -0
- package/dist/chunk-LWVETFJV.js +46 -0
- package/dist/chunk-LWVETFJV.js.map +1 -0
- package/dist/chunk-MCL2MCA2.js +285 -0
- package/dist/chunk-MCL2MCA2.js.map +1 -0
- package/dist/chunk-MZXCF35B.js +205 -0
- package/dist/chunk-MZXCF35B.js.map +1 -0
- package/dist/chunk-NCGPUFWV.js +96 -0
- package/dist/chunk-NCGPUFWV.js.map +1 -0
- package/dist/chunk-OEJMIE2Q.js +351 -0
- package/dist/chunk-OEJMIE2Q.js.map +1 -0
- package/dist/chunk-OYF2OAKS.js +394 -0
- package/dist/chunk-OYF2OAKS.js.map +1 -0
- package/dist/chunk-P6S43FYZ.js +316 -0
- package/dist/chunk-P6S43FYZ.js.map +1 -0
- package/dist/chunk-PL37KFRJ.js +3 -0
- package/dist/chunk-PL37KFRJ.js.map +1 -0
- package/dist/chunk-Q7BS5QC5.js +197 -0
- package/dist/chunk-Q7BS5QC5.js.map +1 -0
- package/dist/chunk-SDYPG3JD.js +288 -0
- package/dist/chunk-SDYPG3JD.js.map +1 -0
- package/dist/chunk-SUG56SZO.js +256 -0
- package/dist/chunk-SUG56SZO.js.map +1 -0
- package/dist/chunk-UVH5XJRP.js +164 -0
- package/dist/chunk-UVH5XJRP.js.map +1 -0
- package/dist/chunk-WZIJKCL3.js +282 -0
- package/dist/chunk-WZIJKCL3.js.map +1 -0
- package/dist/chunk-Y22AMGTM.js +3 -0
- package/dist/chunk-Y22AMGTM.js.map +1 -0
- package/dist/chunk-Z7G23XWU.js +200 -0
- package/dist/chunk-Z7G23XWU.js.map +1 -0
- package/dist/chunk-ZJU5M4IB.js +125 -0
- package/dist/chunk-ZJU5M4IB.js.map +1 -0
- package/dist/chunk-ZVC3ZWLM.js +52 -0
- package/dist/chunk-ZVC3ZWLM.js.map +1 -0
- package/dist/chunk-ZZZML7Y3.js +310 -0
- package/dist/chunk-ZZZML7Y3.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.js +16 -0
- package/dist/client.js.map +1 -0
- package/dist/config/index.d.ts +170 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.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/file-router/index.d.ts +184 -0
- package/dist/file-router/index.js +3 -0
- package/dist/file-router/index.js.map +1 -0
- package/dist/file-router/streaming-hints.d.ts +129 -0
- package/dist/file-router/streaming-hints.js +3 -0
- package/dist/file-router/streaming-hints.js.map +1 -0
- package/dist/handlers/index.d.ts +59 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +886 -0
- package/dist/index.js.map +1 -0
- package/dist/islands/index.d.ts +234 -0
- package/dist/islands/index.js +3 -0
- package/dist/islands/index.js.map +1 -0
- package/dist/middleware/index.d.ts +305 -0
- package/dist/middleware/index.js +3 -0
- package/dist/middleware/index.js.map +1 -0
- 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/render/index.d.ts +131 -0
- package/dist/render/index.js +3 -0
- package/dist/render/index.js.map +1 -0
- package/dist/router/index.d.ts +65 -0
- package/dist/router/index.js +3 -0
- package/dist/router/index.js.map +1 -0
- package/dist/rsc/adapters/index.d.ts +8 -0
- package/dist/rsc/adapters/index.js +7 -0
- package/dist/rsc/adapters/index.js.map +1 -0
- package/dist/rsc/adapters/preact.d.ts +97 -0
- package/dist/rsc/adapters/preact.js +3 -0
- package/dist/rsc/adapters/preact.js.map +1 -0
- package/dist/rsc/adapters/react.d.ts +82 -0
- package/dist/rsc/adapters/react.js +3 -0
- package/dist/rsc/adapters/react.js.map +1 -0
- package/dist/rsc/adapters/solid.d.ts +84 -0
- package/dist/rsc/adapters/solid.js +3 -0
- package/dist/rsc/adapters/solid.js.map +1 -0
- package/dist/rsc/adapters/vue.d.ts +80 -0
- package/dist/rsc/adapters/vue.js +3 -0
- package/dist/rsc/adapters/vue.js.map +1 -0
- package/dist/rsc/boundaries.d.ts +182 -0
- package/dist/rsc/boundaries.js +3 -0
- package/dist/rsc/boundaries.js.map +1 -0
- package/dist/rsc/context.d.ts +201 -0
- package/dist/rsc/context.js +3 -0
- package/dist/rsc/context.js.map +1 -0
- package/dist/rsc/index.d.ts +232 -0
- package/dist/rsc/index.js +15 -0
- package/dist/rsc/index.js.map +1 -0
- package/dist/rsc/legacy.d.ts +155 -0
- package/dist/rsc/legacy.js +3 -0
- package/dist/rsc/legacy.js.map +1 -0
- package/dist/rsc/payload.d.ts +262 -0
- package/dist/rsc/payload.js +3 -0
- package/dist/rsc/payload.js.map +1 -0
- package/dist/rsc/plugins/esbuild.d.ts +124 -0
- package/dist/rsc/plugins/esbuild.js +4 -0
- package/dist/rsc/plugins/esbuild.js.map +1 -0
- package/dist/rsc/plugins/index.d.ts +4 -0
- package/dist/rsc/plugins/index.js +6 -0
- package/dist/rsc/plugins/index.js.map +1 -0
- package/dist/rsc/plugins/rollup.d.ts +103 -0
- package/dist/rsc/plugins/rollup.js +4 -0
- package/dist/rsc/plugins/rollup.js.map +1 -0
- package/dist/rsc/renderer.d.ts +162 -0
- package/dist/rsc/renderer.js +5 -0
- package/dist/rsc/renderer.js.map +1 -0
- package/dist/rsc/stream.d.ts +129 -0
- package/dist/rsc/stream.js +3 -0
- package/dist/rsc/stream.js.map +1 -0
- package/dist/rsc/vite-plugin.d.ts +78 -0
- package/dist/rsc/vite-plugin.js +4 -0
- package/dist/rsc/vite-plugin.js.map +1 -0
- package/dist/server/index.d.ts +135 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/streaming/adapters/index.d.ts +223 -0
- package/dist/streaming/adapters/index.js +3 -0
- package/dist/streaming/adapters/index.js.map +1 -0
- package/dist/streaming/conditional.d.ts +130 -0
- package/dist/streaming/conditional.js +3 -0
- package/dist/streaming/conditional.js.map +1 -0
- package/dist/streaming/index.d.ts +177 -0
- package/dist/streaming/index.js +3 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/streaming/observability.d.ts +201 -0
- package/dist/streaming/observability.js +4 -0
- package/dist/streaming/observability.js.map +1 -0
- package/dist/streaming/priority.d.ts +103 -0
- package/dist/streaming/priority.js +3 -0
- package/dist/streaming/priority.js.map +1 -0
- 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 +228 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flightdev/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-Q7BS5QC5.js';
|
|
2
|
+
import '../chunk-LWVETFJV.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flightdev/core - File Router
|
|
3
|
+
*
|
|
4
|
+
* Auto-discovery of routes from file system.
|
|
5
|
+
* Similar to Next.js App Router and Nuxt server/api patterns.
|
|
6
|
+
*/
|
|
7
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
8
|
+
type Handler = (context: unknown) => Response | Promise<Response>;
|
|
9
|
+
type Middleware = (context: unknown, next: () => Promise<Response>) => Response | Promise<Response>;
|
|
10
|
+
interface FileRoute {
|
|
11
|
+
/** HTTP method (GET, POST, etc) or 'ALL' */
|
|
12
|
+
method: HttpMethod | 'ALL';
|
|
13
|
+
/** Route path with params (e.g., /users/:id) */
|
|
14
|
+
path: string;
|
|
15
|
+
/** Original file path */
|
|
16
|
+
filePath: string;
|
|
17
|
+
/** Handler function (for APIs) */
|
|
18
|
+
handler?: Handler;
|
|
19
|
+
/** Route-specific middleware */
|
|
20
|
+
middleware?: Middleware[];
|
|
21
|
+
/** Route type: 'page' for SSR pages, 'api' for API endpoints */
|
|
22
|
+
type: 'page' | 'api';
|
|
23
|
+
/** Component function (for pages) */
|
|
24
|
+
component?: () => unknown;
|
|
25
|
+
/** Page metadata (title, description, etc) */
|
|
26
|
+
meta?: Record<string, unknown>;
|
|
27
|
+
/** Parallel route slot name (for @folder convention) */
|
|
28
|
+
slot?: string;
|
|
29
|
+
/** Intercepting route info (for (.) (..) (...) convention) */
|
|
30
|
+
interceptInfo?: {
|
|
31
|
+
/** Number of levels to intercept: 1 = same, 2 = parent, 3+ = root */
|
|
32
|
+
level: number;
|
|
33
|
+
/** Target route segment to intercept */
|
|
34
|
+
target: string;
|
|
35
|
+
/** Original path that triggers interception */
|
|
36
|
+
interceptPath: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface FileRouterOptions {
|
|
40
|
+
/** Root directory to scan (default: src/routes) */
|
|
41
|
+
directory: string;
|
|
42
|
+
/** File extensions to consider (default: ['.ts', '.js']) */
|
|
43
|
+
extensions?: string[];
|
|
44
|
+
/** Whether to watch for changes (default: false in prod) */
|
|
45
|
+
watch?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Custom module loader for development with Vite.
|
|
48
|
+
* Pass vite.ssrLoadModule to load TSX files correctly.
|
|
49
|
+
* Falls back to native import() if not provided.
|
|
50
|
+
*/
|
|
51
|
+
moduleLoader?: (filePath: string) => Promise<any>;
|
|
52
|
+
}
|
|
53
|
+
interface ScanResult {
|
|
54
|
+
routes: FileRoute[];
|
|
55
|
+
errors: string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scan a directory for route files
|
|
59
|
+
*/
|
|
60
|
+
declare function scanRoutes(options: FileRouterOptions): Promise<ScanResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Load routes with their handlers or components
|
|
63
|
+
* @param scanResult - Result from scanRoutes
|
|
64
|
+
* @param moduleLoader - Optional custom loader (use vite.ssrLoadModule for dev)
|
|
65
|
+
*/
|
|
66
|
+
declare function loadRoutes(scanResult: ScanResult, moduleLoader?: (filePath: string) => Promise<any>): Promise<FileRoute[]>;
|
|
67
|
+
interface FileRouter {
|
|
68
|
+
routes: FileRoute[];
|
|
69
|
+
refresh: () => Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a file-based router
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { createFileRouter } from '@flightdev/core/file-router';
|
|
77
|
+
* import { createServer } from '@flightdev/http';
|
|
78
|
+
*
|
|
79
|
+
* const router = await createFileRouter({ directory: './src/routes' });
|
|
80
|
+
* const app = createServer();
|
|
81
|
+
*
|
|
82
|
+
* // Register all discovered routes
|
|
83
|
+
* for (const route of router.routes) {
|
|
84
|
+
* app[route.method.toLowerCase()](route.path, route.handler);
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function createFileRouter(options: FileRouterOptions): Promise<FileRouter>;
|
|
89
|
+
/**
|
|
90
|
+
* Resolved parallel route slots for a layout.
|
|
91
|
+
* Each slot name maps to its resolved component or null if not matched.
|
|
92
|
+
*/
|
|
93
|
+
interface ResolvedSlots {
|
|
94
|
+
[slotName: string]: {
|
|
95
|
+
/** The component to render */
|
|
96
|
+
component: () => unknown;
|
|
97
|
+
/** The full route information */
|
|
98
|
+
route: FileRoute;
|
|
99
|
+
} | null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolve parallel route slots for a given path.
|
|
103
|
+
*
|
|
104
|
+
* Parallel routes use the @folder convention to define named slots
|
|
105
|
+
* that can render alongside the main content in a layout.
|
|
106
|
+
*
|
|
107
|
+
* @param routes - All loaded routes from the file router
|
|
108
|
+
* @param currentPath - The current URL path to resolve slots for
|
|
109
|
+
* @returns Object mapping slot names to their resolved components
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Given routes from @modal/ and @sidebar/ directories
|
|
114
|
+
* const slots = resolveParallelSlots(router.routes, '/dashboard');
|
|
115
|
+
*
|
|
116
|
+
* // In layout:
|
|
117
|
+
* if (slots.modal) {
|
|
118
|
+
* renderModal(slots.modal.component);
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
declare function resolveParallelSlots(routes: FileRoute[], currentPath: string): ResolvedSlots;
|
|
123
|
+
/**
|
|
124
|
+
* Get the default page for an unmatched slot.
|
|
125
|
+
*
|
|
126
|
+
* When a parallel route slot doesn't have a matching route for the current path,
|
|
127
|
+
* it should render its default.page if one exists, or null.
|
|
128
|
+
*
|
|
129
|
+
* @param routes - All loaded routes
|
|
130
|
+
* @param slotName - Name of the slot (without @)
|
|
131
|
+
* @param basePath - Base path to search from
|
|
132
|
+
* @returns The default route for the slot, or null
|
|
133
|
+
*/
|
|
134
|
+
declare function getSlotDefault(routes: FileRoute[], slotName: string, basePath?: string): FileRoute | null;
|
|
135
|
+
/**
|
|
136
|
+
* Get all slot names used in the routes.
|
|
137
|
+
*
|
|
138
|
+
* @param routes - All loaded routes
|
|
139
|
+
* @returns Array of unique slot names
|
|
140
|
+
*/
|
|
141
|
+
declare function getSlotNames(routes: FileRoute[]): string[];
|
|
142
|
+
/**
|
|
143
|
+
* Check if a navigation should be intercepted by an intercepting route.
|
|
144
|
+
*
|
|
145
|
+
* Intercepting routes use the (.) (..) (...) convention:
|
|
146
|
+
* - (.)segment - intercepts from same level
|
|
147
|
+
* - (..)segment - intercepts from parent level
|
|
148
|
+
* - (...)segment - intercepts from root
|
|
149
|
+
*
|
|
150
|
+
* @param routes - All loaded routes
|
|
151
|
+
* @param fromPath - Current path where navigation originates
|
|
152
|
+
* @param toPath - Target path the user wants to navigate to
|
|
153
|
+
* @returns The intercepting route if found, null otherwise
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // User is on /feed and clicks link to /photo/123
|
|
158
|
+
* const intercepted = findInterceptingRoute(routes, '/feed', '/photo/123');
|
|
159
|
+
*
|
|
160
|
+
* if (intercepted) {
|
|
161
|
+
* // Render intercepted.component as modal instead of navigating
|
|
162
|
+
* showModal(intercepted);
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function findInterceptingRoute(routes: FileRoute[], fromPath: string, toPath: string): FileRoute | null;
|
|
167
|
+
/**
|
|
168
|
+
* Check if an intercepting route should be dismissed on this navigation.
|
|
169
|
+
*
|
|
170
|
+
* @param currentRoute - The currently active intercepting route
|
|
171
|
+
* @param toPath - The path being navigated to
|
|
172
|
+
* @returns true if the interception should be dismissed
|
|
173
|
+
*/
|
|
174
|
+
declare function shouldDismissIntercept(currentRoute: FileRoute | null, toPath: string): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Get route params from a path match.
|
|
177
|
+
*
|
|
178
|
+
* @param routePath - The route pattern with params (e.g., /photo/:id)
|
|
179
|
+
* @param actualPath - The actual URL path (e.g., /photo/123)
|
|
180
|
+
* @returns Object with matched params, or null if no match
|
|
181
|
+
*/
|
|
182
|
+
declare function extractRouteParams(routePath: string, actualPath: string): Record<string, string> | null;
|
|
183
|
+
|
|
184
|
+
export { type FileRoute, type FileRouter, type FileRouterOptions, type Handler, type HttpMethod, type Middleware, type ResolvedSlots, type ScanResult, createFileRouter, extractRouteParams, findInterceptingRoute, getSlotDefault, getSlotNames, loadRoutes, resolveParallelSlots, scanRoutes, shouldDismissIntercept };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flightdev/core - File Router Streaming Hints
|
|
3
|
+
*
|
|
4
|
+
* Per-route streaming configuration through exports.
|
|
5
|
+
* The user defines streaming behavior at the route level.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // src/routes/products/[id].page.tsx
|
|
10
|
+
*
|
|
11
|
+
* // Static export for streaming hints
|
|
12
|
+
* export const streaming = {
|
|
13
|
+
* enabled: true,
|
|
14
|
+
* timeout: 5000,
|
|
15
|
+
* priority: 'high',
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* // Or dynamic function based on params
|
|
19
|
+
* export function getStreamingConfig(params: { id: string }) {
|
|
20
|
+
* return {
|
|
21
|
+
* enabled: params.id !== 'preview',
|
|
22
|
+
* timeout: 3000,
|
|
23
|
+
* };
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* export default function ProductPage({ params }) {
|
|
27
|
+
* return <Product id={params.id} />;
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Static streaming configuration export
|
|
33
|
+
*/
|
|
34
|
+
interface StreamingHints {
|
|
35
|
+
/** Whether streaming is enabled for this route (default: true) */
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
/** Timeout before aborting streaming (ms) */
|
|
38
|
+
timeout?: number;
|
|
39
|
+
/** Priority hint for streaming scheduler */
|
|
40
|
+
priority?: 'high' | 'normal' | 'low';
|
|
41
|
+
/** Expected suspense boundary IDs */
|
|
42
|
+
boundaries?: string[];
|
|
43
|
+
/** Force static rendering (no streaming) */
|
|
44
|
+
forceStatic?: boolean;
|
|
45
|
+
/** Cache the static version */
|
|
46
|
+
cache?: {
|
|
47
|
+
/** Time to cache in seconds */
|
|
48
|
+
ttl?: number;
|
|
49
|
+
/** Stale-while-revalidate time in seconds */
|
|
50
|
+
swr?: number;
|
|
51
|
+
/** Cache tags for invalidation */
|
|
52
|
+
tags?: string[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Dynamic streaming configuration function
|
|
57
|
+
*/
|
|
58
|
+
type GetStreamingConfig<TParams = Record<string, string>> = (params: TParams, request?: Request) => StreamingHints | Promise<StreamingHints>;
|
|
59
|
+
/**
|
|
60
|
+
* Route module with streaming exports
|
|
61
|
+
*/
|
|
62
|
+
interface StreamingRouteModule {
|
|
63
|
+
/** Default component/handler */
|
|
64
|
+
default: unknown;
|
|
65
|
+
/** Static streaming configuration */
|
|
66
|
+
streaming?: StreamingHints;
|
|
67
|
+
/** Dynamic streaming configuration function */
|
|
68
|
+
getStreamingConfig?: GetStreamingConfig;
|
|
69
|
+
/** Other route exports (metadata, generateStaticParams, etc.) */
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolved streaming configuration for a request
|
|
74
|
+
*/
|
|
75
|
+
interface ResolvedStreamingConfig extends StreamingHints {
|
|
76
|
+
/** Source of the configuration */
|
|
77
|
+
source: 'static' | 'dynamic' | 'default';
|
|
78
|
+
/** Route path */
|
|
79
|
+
routePath: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Default streaming hints when none are specified
|
|
83
|
+
*/
|
|
84
|
+
declare const DEFAULT_STREAMING_HINTS: Required<StreamingHints>;
|
|
85
|
+
/**
|
|
86
|
+
* Resolve streaming configuration for a route request
|
|
87
|
+
*/
|
|
88
|
+
declare function resolveStreamingConfig(module: StreamingRouteModule, params: Record<string, string>, request?: Request, routePath?: string): Promise<ResolvedStreamingConfig>;
|
|
89
|
+
/**
|
|
90
|
+
* Load route module and extract streaming configuration
|
|
91
|
+
*/
|
|
92
|
+
declare function loadRouteWithStreaming(filePath: string, moduleLoader?: (path: string) => Promise<StreamingRouteModule>): Promise<{
|
|
93
|
+
module: StreamingRouteModule;
|
|
94
|
+
hasStreamingConfig: boolean;
|
|
95
|
+
hasGetStreamingConfig: boolean;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Determine if streaming should be used based on config and request
|
|
99
|
+
*/
|
|
100
|
+
declare function shouldStream(config: ResolvedStreamingConfig, request?: Request): {
|
|
101
|
+
stream: boolean;
|
|
102
|
+
reason: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Create an abort controller with timeout
|
|
106
|
+
*/
|
|
107
|
+
declare function createStreamingController(timeout: number): {
|
|
108
|
+
controller: AbortController;
|
|
109
|
+
signal: AbortSignal;
|
|
110
|
+
cleanup: () => void;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Generate cache key for a streaming route
|
|
114
|
+
*/
|
|
115
|
+
declare function generateCacheKey(routePath: string, params: Record<string, string>, _config: StreamingHints): string;
|
|
116
|
+
/**
|
|
117
|
+
* Cache headers for static streaming fallback
|
|
118
|
+
*/
|
|
119
|
+
declare function getStreamingCacheHeaders(config: StreamingHints): Record<string, string>;
|
|
120
|
+
/**
|
|
121
|
+
* Check if a module has streaming configuration
|
|
122
|
+
*/
|
|
123
|
+
declare function hasStreamingConfig(module: unknown): module is StreamingRouteModule;
|
|
124
|
+
/**
|
|
125
|
+
* Validate streaming hints object
|
|
126
|
+
*/
|
|
127
|
+
declare function isValidStreamingHints(obj: unknown): obj is StreamingHints;
|
|
128
|
+
|
|
129
|
+
export { DEFAULT_STREAMING_HINTS, type GetStreamingConfig, type ResolvedStreamingConfig, type StreamingHints, type StreamingRouteModule, createStreamingController, generateCacheKey, getStreamingCacheHeaders, hasStreamingConfig, isValidStreamingHints, loadRouteWithStreaming, resolveStreamingConfig, shouldStream };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { DEFAULT_STREAMING_HINTS, createStreamingController, generateCacheKey, getStreamingCacheHeaders, hasStreamingConfig, isValidStreamingHints, loadRouteWithStreaming, resolveStreamingConfig, shouldStream } from '../chunk-ZJU5M4IB.js';
|
|
2
|
+
//# sourceMappingURL=streaming-hints.js.map
|
|
3
|
+
//# sourceMappingURL=streaming-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"streaming-hints.js"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flightdev/core - Route Handlers
|
|
3
|
+
*
|
|
4
|
+
* Types and utilities for route handlers.
|
|
5
|
+
* Similar to Next.js Route Handlers pattern.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* HTTP methods supported by route handlers
|
|
9
|
+
*/
|
|
10
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
11
|
+
/**
|
|
12
|
+
* Context passed to route handlers
|
|
13
|
+
*/
|
|
14
|
+
interface RouteHandlerContext {
|
|
15
|
+
/** Route parameters (e.g., { id: '123' }) */
|
|
16
|
+
params: Record<string, string>;
|
|
17
|
+
/** Query string parameters */
|
|
18
|
+
searchParams: URLSearchParams;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Route handler function signature
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // src/routes/api/users/[id].ts
|
|
26
|
+
* export const GET: RouteHandler = async (request, context) => {
|
|
27
|
+
* const { id } = context.params;
|
|
28
|
+
* return Response.json({ userId: id });
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* export const PUT: RouteHandler = async (request, context) => {
|
|
32
|
+
* const body = await request.json();
|
|
33
|
+
* return Response.json({ updated: true, data: body });
|
|
34
|
+
* };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
type RouteHandler = (request: Request, context: RouteHandlerContext) => Response | Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a route handler context from request
|
|
40
|
+
*/
|
|
41
|
+
declare function createRouteContext(request: Request, params?: Record<string, string>): RouteHandlerContext;
|
|
42
|
+
/**
|
|
43
|
+
* Helper to create JSON response
|
|
44
|
+
*/
|
|
45
|
+
declare function json<T>(data: T, init?: ResponseInit): Response;
|
|
46
|
+
/**
|
|
47
|
+
* Helper to create redirect response
|
|
48
|
+
*/
|
|
49
|
+
declare function redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
50
|
+
/**
|
|
51
|
+
* Helper to create error response
|
|
52
|
+
*/
|
|
53
|
+
declare function error(message: string, status?: number): Response;
|
|
54
|
+
/**
|
|
55
|
+
* Helper to get request body as typed object
|
|
56
|
+
*/
|
|
57
|
+
declare function parseBody<T>(request: Request): Promise<T>;
|
|
58
|
+
|
|
59
|
+
export { type HttpMethod, type RouteHandler, type RouteHandlerContext, createRouteContext, error, json, parseBody, redirect };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|