@arponascension/express-inertia 0.1.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/LICENSE +21 -0
- package/README.md +478 -0
- package/dist/base.ejs +14 -0
- package/dist/engine.d.mts +24 -0
- package/dist/engine.d.ts +24 -0
- package/dist/engine.js +480 -0
- package/dist/engine.js.map +1 -0
- package/dist/engine.mjs +470 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/index.d.mts +175 -0
- package/dist/index.d.ts +175 -0
- package/dist/index.js +1268 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1218 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-Co2XESgs.d.mts +423 -0
- package/dist/types-Co2XESgs.d.ts +423 -0
- package/dist/vite.d.mts +116 -0
- package/dist/vite.d.ts +116 -0
- package/dist/vite.js +336 -0
- package/dist/vite.js.map +1 -0
- package/dist/vite.mjs +326 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +71 -0
- package/templates/base.ejs +14 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
|
|
3
|
+
type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
|
|
4
|
+
interface CircuitBreakerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Number of consecutive failures before opening the circuit.
|
|
7
|
+
* @default 5
|
|
8
|
+
*/
|
|
9
|
+
failureThreshold: number;
|
|
10
|
+
/**
|
|
11
|
+
* Time in milliseconds before transitioning from OPEN to HALF_OPEN.
|
|
12
|
+
* @default 30000
|
|
13
|
+
*/
|
|
14
|
+
cooldownMs: number;
|
|
15
|
+
/**
|
|
16
|
+
* Time in milliseconds to wait in HALF_OPEN before succeeding.
|
|
17
|
+
* @default 1000
|
|
18
|
+
*/
|
|
19
|
+
probeDelayMs: number;
|
|
20
|
+
}
|
|
21
|
+
interface RetryOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Maximum number of retry attempts.
|
|
24
|
+
* @default 2
|
|
25
|
+
*/
|
|
26
|
+
maxRetries: number;
|
|
27
|
+
/**
|
|
28
|
+
* Base delay in milliseconds for exponential backoff.
|
|
29
|
+
* @default 200
|
|
30
|
+
*/
|
|
31
|
+
baseDelayMs: number;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum delay in milliseconds between retries.
|
|
34
|
+
* @default 2000
|
|
35
|
+
*/
|
|
36
|
+
maxDelayMs: number;
|
|
37
|
+
/**
|
|
38
|
+
* HTTP status codes that should trigger a retry.
|
|
39
|
+
* @default [408, 429, 500, 502, 503, 504]
|
|
40
|
+
*/
|
|
41
|
+
retryableStatusCodes: number[];
|
|
42
|
+
}
|
|
43
|
+
interface SSRResilienceOptions {
|
|
44
|
+
circuitBreaker?: Partial<CircuitBreakerOptions>;
|
|
45
|
+
retry?: Partial<RetryOptions>;
|
|
46
|
+
}
|
|
47
|
+
declare class CircuitBreaker {
|
|
48
|
+
private options;
|
|
49
|
+
private state;
|
|
50
|
+
private failures;
|
|
51
|
+
private openedAt;
|
|
52
|
+
private probeTimer;
|
|
53
|
+
private pendingProbe;
|
|
54
|
+
constructor(options?: Required<CircuitBreakerOptions>);
|
|
55
|
+
getState(): CircuitState;
|
|
56
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
57
|
+
private onSuccess;
|
|
58
|
+
private onFailure;
|
|
59
|
+
allowProbe<T>(fn: () => Promise<T>): Promise<T>;
|
|
60
|
+
reset(): void;
|
|
61
|
+
}
|
|
62
|
+
declare function shouldRetry(error: any, statusCode: number | undefined, retryableStatusCodes: number[]): boolean;
|
|
63
|
+
declare function calculateBackoff(attempt: number, baseDelayMs: number, maxDelayMs: number): number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Standard Inertia Page Object sent to client-side adapters.
|
|
67
|
+
*/
|
|
68
|
+
interface Page<TProps extends PageProps = PageProps> {
|
|
69
|
+
component: string;
|
|
70
|
+
props: TProps;
|
|
71
|
+
url: string;
|
|
72
|
+
version: string | null;
|
|
73
|
+
encryptHistory?: boolean;
|
|
74
|
+
clearHistory?: boolean;
|
|
75
|
+
deferredProps?: Record<string, string[]>;
|
|
76
|
+
mergeProps?: string[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Inertia Page Props map.
|
|
80
|
+
*/
|
|
81
|
+
type PageProps = Record<string, any>;
|
|
82
|
+
/**
|
|
83
|
+
* Callback function or Promise returning a prop value.
|
|
84
|
+
*/
|
|
85
|
+
type PropCallback<T = any> = (req?: Request) => T | Promise<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Validation options for component names and view paths.
|
|
88
|
+
*/
|
|
89
|
+
interface SecurityOptions {
|
|
90
|
+
/**
|
|
91
|
+
* Whether to validate component names to prevent path traversal.
|
|
92
|
+
* @default true
|
|
93
|
+
*/
|
|
94
|
+
validateComponentNames?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Allowed characters for component names. Defaults to alphanumeric, slashes, hyphens, and underscores.
|
|
97
|
+
*/
|
|
98
|
+
componentNamePattern?: RegExp;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Special Prop Wrapper types
|
|
102
|
+
*/
|
|
103
|
+
interface LazyProp<T = any> {
|
|
104
|
+
__inertia_lazy: true;
|
|
105
|
+
callback: PropCallback<T>;
|
|
106
|
+
}
|
|
107
|
+
interface AlwaysProp<T = any> {
|
|
108
|
+
__inertia_always: true;
|
|
109
|
+
value: T | PropCallback<T>;
|
|
110
|
+
}
|
|
111
|
+
interface DeferredProp<T = any> {
|
|
112
|
+
__inertia_deferred: true;
|
|
113
|
+
callback: PropCallback<T>;
|
|
114
|
+
group?: string;
|
|
115
|
+
}
|
|
116
|
+
interface MergeProp<T = any> {
|
|
117
|
+
__inertia_merge: true;
|
|
118
|
+
value: T | PropCallback<T>;
|
|
119
|
+
}
|
|
120
|
+
interface OptionalProp<T = any> {
|
|
121
|
+
__inertia_optional: true;
|
|
122
|
+
callback: PropCallback<T>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Server-Side Rendering configuration.
|
|
126
|
+
*/
|
|
127
|
+
interface SSROptions {
|
|
128
|
+
/**
|
|
129
|
+
* Whether SSR is enabled.
|
|
130
|
+
* @default false
|
|
131
|
+
*/
|
|
132
|
+
enabled?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* SSR rendering endpoint URL.
|
|
135
|
+
* @default 'http://127.0.0.1:13714/render'
|
|
136
|
+
*/
|
|
137
|
+
url?: string;
|
|
138
|
+
/**
|
|
139
|
+
* Custom SSR render function (overrides HTTP endpoint).
|
|
140
|
+
*/
|
|
141
|
+
render?: (page: Page) => Promise<SSRResult> | SSRResult;
|
|
142
|
+
/**
|
|
143
|
+
* Timeout in milliseconds for SSR request.
|
|
144
|
+
* @default 2000
|
|
145
|
+
*/
|
|
146
|
+
timeout?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Fallback to client-side rendering if SSR fails.
|
|
149
|
+
* @default true
|
|
150
|
+
*/
|
|
151
|
+
fallback?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Circuit breaker configuration for SSR endpoint.
|
|
154
|
+
*/
|
|
155
|
+
circuitBreaker?: Partial<CircuitBreakerOptions>;
|
|
156
|
+
/**
|
|
157
|
+
* Retry configuration for SSR requests.
|
|
158
|
+
*/
|
|
159
|
+
retry?: Partial<RetryOptions>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Result returned by SSR server.
|
|
163
|
+
*/
|
|
164
|
+
interface SSRResult {
|
|
165
|
+
head: string[];
|
|
166
|
+
body: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Vite Helper configuration options.
|
|
170
|
+
*/
|
|
171
|
+
interface ViteConfig {
|
|
172
|
+
/**
|
|
173
|
+
* Path to the Vite manifest.json file in production.
|
|
174
|
+
* Auto-detected if omitted (checks public/build/.vite/manifest.json and public/build/manifest.json).
|
|
175
|
+
*/
|
|
176
|
+
manifestPath?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Public directory path containing compiled assets.
|
|
179
|
+
* @default 'public'
|
|
180
|
+
*/
|
|
181
|
+
publicDir?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Build subdirectory name inside publicDir.
|
|
184
|
+
* @default 'build'
|
|
185
|
+
*/
|
|
186
|
+
buildDir?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Development server URL.
|
|
189
|
+
* @default 'http://localhost:5173'
|
|
190
|
+
*/
|
|
191
|
+
devServerUrl?: string;
|
|
192
|
+
/**
|
|
193
|
+
* Path to the hot file created by Vite dev server.
|
|
194
|
+
* @default 'public/hot' or 'hot'
|
|
195
|
+
*/
|
|
196
|
+
hotFile?: string;
|
|
197
|
+
/**
|
|
198
|
+
* Custom base URL path for assets.
|
|
199
|
+
* @default '/build/'
|
|
200
|
+
*/
|
|
201
|
+
base?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Override for manifest data. Useful in edge runtimes where fs is unavailable.
|
|
204
|
+
* If provided, manifestPath and fs access are bypassed.
|
|
205
|
+
*/
|
|
206
|
+
manifest?: Record<string, any>;
|
|
207
|
+
/**
|
|
208
|
+
* Override for dev detection. Useful in edge runtimes where fs is unavailable.
|
|
209
|
+
* Return true if the Vite dev server should be considered active.
|
|
210
|
+
*/
|
|
211
|
+
isDev?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Override for dev server URL. Useful in edge runtimes where hot file is unavailable.
|
|
214
|
+
*/
|
|
215
|
+
devServerUrlOverride?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Configuration options for the Inertia Express middleware.
|
|
219
|
+
*/
|
|
220
|
+
interface InertiaOptions {
|
|
221
|
+
/**
|
|
222
|
+
* Name of the root view template (e.g. 'base.ejs', 'app.ejs', 'base').
|
|
223
|
+
* @default 'base.ejs'
|
|
224
|
+
*/
|
|
225
|
+
rootView?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Version of current assets. Can be a string, or a function/promise resolving to a string.
|
|
228
|
+
* If version mismatches client `X-Inertia-Version`, a 409 Conflict is returned for full reload.
|
|
229
|
+
*/
|
|
230
|
+
version?: string | (() => string | Promise<string>);
|
|
231
|
+
/**
|
|
232
|
+
* Server-Side Rendering configuration or boolean.
|
|
233
|
+
*/
|
|
234
|
+
ssr?: boolean | SSROptions;
|
|
235
|
+
/**
|
|
236
|
+
* Shared props available across all responses. Can be an object or function taking the Request.
|
|
237
|
+
*/
|
|
238
|
+
shared?: PageProps | ((req: Request) => PageProps | Promise<PageProps>);
|
|
239
|
+
/**
|
|
240
|
+
* Default history encryption setting.
|
|
241
|
+
*/
|
|
242
|
+
encryptHistory?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Vite helper configuration.
|
|
245
|
+
*/
|
|
246
|
+
vite?: ViteConfig;
|
|
247
|
+
/**
|
|
248
|
+
* Inertia protocol version for HTML initial page payload.
|
|
249
|
+
* - 2 (default): Outputs clean `<script data-page="app" type="application/json">`
|
|
250
|
+
* - 1: Outputs `<div id="app" data-page="..."></div>` attribute format
|
|
251
|
+
* @default 2
|
|
252
|
+
*/
|
|
253
|
+
inertiaVersion?: 1 | 2;
|
|
254
|
+
/**
|
|
255
|
+
* Whether @inertia should automatically render the root container `<div id="app"></div>`.
|
|
256
|
+
* Set to `false` if you write `<div id="app"></div>` manually in your root template.
|
|
257
|
+
* @default true
|
|
258
|
+
*/
|
|
259
|
+
rootElement?: boolean | string;
|
|
260
|
+
/**
|
|
261
|
+
* Custom view data passed to the root template view locals.
|
|
262
|
+
*/
|
|
263
|
+
viewData?: Record<string, any> | ((req: Request) => Record<string, any> | Promise<Record<string, any>>);
|
|
264
|
+
/**
|
|
265
|
+
* Security configuration options.
|
|
266
|
+
*/
|
|
267
|
+
security?: SecurityOptions;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Context and helper methods available on `res.inertia`.
|
|
271
|
+
*/
|
|
272
|
+
interface InertiaResponseHandler {
|
|
273
|
+
/**
|
|
274
|
+
* Render an Inertia response.
|
|
275
|
+
* @param component Name of the client-side component (e.g., 'Users/Index').
|
|
276
|
+
* @param props Page props passed to the component.
|
|
277
|
+
* @param viewData Extra data passed only to the root template (not to the frontend component).
|
|
278
|
+
*/
|
|
279
|
+
(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Explicit render method.
|
|
282
|
+
*/
|
|
283
|
+
render(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
284
|
+
/**
|
|
285
|
+
* Alias for the callable render method.
|
|
286
|
+
*/
|
|
287
|
+
inertia(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Share props for the current request.
|
|
290
|
+
*/
|
|
291
|
+
share(keyOrObject: string | PageProps, value?: any): InertiaResponseHandler;
|
|
292
|
+
/**
|
|
293
|
+
* Retrieve currently shared props.
|
|
294
|
+
*/
|
|
295
|
+
getShared(key?: string): any;
|
|
296
|
+
/**
|
|
297
|
+
* Perform an external redirect or full page reload.
|
|
298
|
+
* Returns a 409 Conflict with X-Inertia-Location header for Inertia requests,
|
|
299
|
+
* or a standard redirect for full requests.
|
|
300
|
+
*/
|
|
301
|
+
location(url: string): void;
|
|
302
|
+
/**
|
|
303
|
+
* Redirect back to the previous page with 303 status code.
|
|
304
|
+
*/
|
|
305
|
+
back(fallbackUrl?: string): void;
|
|
306
|
+
/**
|
|
307
|
+
* Set asset version for the current request.
|
|
308
|
+
*/
|
|
309
|
+
version(version: string | (() => string | Promise<string>)): InertiaResponseHandler;
|
|
310
|
+
/**
|
|
311
|
+
* Set custom root view for the current response.
|
|
312
|
+
*/
|
|
313
|
+
rootView(view: string): InertiaResponseHandler;
|
|
314
|
+
/**
|
|
315
|
+
* Enable/disable history encryption for this response (Inertia v2).
|
|
316
|
+
*/
|
|
317
|
+
encryptHistory(encrypt?: boolean): InertiaResponseHandler;
|
|
318
|
+
/**
|
|
319
|
+
* Clear history for this response (Inertia v2).
|
|
320
|
+
*/
|
|
321
|
+
clearHistory(clear?: boolean): InertiaResponseHandler;
|
|
322
|
+
/**
|
|
323
|
+
* Attach a flash message to the response.
|
|
324
|
+
*/
|
|
325
|
+
withFlash(key: string, value: any): InertiaResponseHandler;
|
|
326
|
+
/**
|
|
327
|
+
* Semantic POST form submission helper.
|
|
328
|
+
*/
|
|
329
|
+
postForm(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
330
|
+
/**
|
|
331
|
+
* Semantic PUT form submission helper.
|
|
332
|
+
*/
|
|
333
|
+
putForm(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Semantic PATCH form submission helper.
|
|
336
|
+
*/
|
|
337
|
+
patchForm(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
338
|
+
/**
|
|
339
|
+
* Semantic DELETE form submission helper.
|
|
340
|
+
*/
|
|
341
|
+
deleteForm(component: string, props?: PageProps, viewData?: Record<string, any>): Promise<void>;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Context available on `req.inertia`.
|
|
345
|
+
*/
|
|
346
|
+
interface InertiaRequestHelper {
|
|
347
|
+
/**
|
|
348
|
+
* True if the current request is an Inertia AJAX request.
|
|
349
|
+
*/
|
|
350
|
+
isInertia: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Target component if partial reload is requested.
|
|
353
|
+
*/
|
|
354
|
+
partialComponent: string | null;
|
|
355
|
+
/**
|
|
356
|
+
* Array of prop keys requested for partial reload.
|
|
357
|
+
*/
|
|
358
|
+
partialData: string[];
|
|
359
|
+
/**
|
|
360
|
+
* Array of prop keys to reset during partial reload.
|
|
361
|
+
*/
|
|
362
|
+
resetData: string[];
|
|
363
|
+
/**
|
|
364
|
+
* Client-supplied asset version.
|
|
365
|
+
*/
|
|
366
|
+
version: string | null;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Custom Blade Directive Handler.
|
|
370
|
+
*/
|
|
371
|
+
type DirectiveHandler = (args: string, locals: Record<string, any>) => string;
|
|
372
|
+
/**
|
|
373
|
+
* Custom View Engine Options for Blade EJS.
|
|
374
|
+
*/
|
|
375
|
+
interface BladeEngineOptions {
|
|
376
|
+
/**
|
|
377
|
+
* Enable template caching.
|
|
378
|
+
* Defaults to true when the Vite dev server is not running (i.e. build mode),
|
|
379
|
+
* matching the same auto-detection as the `@vite` directive.
|
|
380
|
+
*/
|
|
381
|
+
cache?: boolean;
|
|
382
|
+
/**
|
|
383
|
+
* Vite helper configuration.
|
|
384
|
+
*/
|
|
385
|
+
vite?: ViteConfig;
|
|
386
|
+
/**
|
|
387
|
+
* Custom Blade directives.
|
|
388
|
+
*/
|
|
389
|
+
directives?: Record<string, DirectiveHandler>;
|
|
390
|
+
/**
|
|
391
|
+
* Inertia protocol version for initial HTML payload (1 or 2).
|
|
392
|
+
* @default 2
|
|
393
|
+
*/
|
|
394
|
+
inertiaVersion?: 1 | 2;
|
|
395
|
+
/**
|
|
396
|
+
* Whether to render the root container `<div id="app"></div>` automatically.
|
|
397
|
+
* Set to `false` if writing `<div id="app"></div>` manually in your HTML.
|
|
398
|
+
* @default true
|
|
399
|
+
*/
|
|
400
|
+
rootElement?: boolean | string;
|
|
401
|
+
/**
|
|
402
|
+
* Pre-compiled template string. Useful in edge runtimes where fs is unavailable.
|
|
403
|
+
* When provided, the engine will not read from the filesystem.
|
|
404
|
+
*/
|
|
405
|
+
templateSource?: string;
|
|
406
|
+
/**
|
|
407
|
+
* Custom template compiler. Receives the raw template source and returns a compiled EJS string.
|
|
408
|
+
* Useful for custom preprocessing before Blade directive compilation.
|
|
409
|
+
*/
|
|
410
|
+
compileTemplate?: (source: string) => string;
|
|
411
|
+
}
|
|
412
|
+
declare global {
|
|
413
|
+
namespace Express {
|
|
414
|
+
interface Request {
|
|
415
|
+
inertia: InertiaRequestHelper;
|
|
416
|
+
}
|
|
417
|
+
interface Response {
|
|
418
|
+
inertia: InertiaResponseHandler;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export { type AlwaysProp as A, type BladeEngineOptions as B, CircuitBreaker as C, type DirectiveHandler as D, type InertiaOptions as I, type LazyProp as L, type MergeProp as M, type OptionalProp as O, type PropCallback as P, type RetryOptions as R, type SSROptions as S, type ViteConfig as V, type DeferredProp as a, type PageProps as b, type Page as c, type SSRResult as d, type CircuitBreakerOptions as e, type InertiaRequestHelper as f, type InertiaResponseHandler as g, type SSRResilienceOptions as h, type SecurityOptions as i, calculateBackoff as j, shouldRetry as s };
|