@orieljs/inertia 0.1.0-alpha.10
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 +202 -0
- package/NOTICE +16 -0
- package/README.md +34 -0
- package/TRADEMARKS.md +33 -0
- package/dist/index.d.ts +633 -0
- package/dist/index.js +1556 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import { PropCallback, InertiaScrollProp, InertiaOnceProp, HttpRequest, Session, Container, OrielError, InertiaResponse, InertiaPage, InertiaFactory, Application, RedirectResponse, Htmlable, Middleware, Next, InertiaSsrGateway, InertiaSsrResponse, Route, ConsoleKernel } from '@orieljs/contracts';
|
|
2
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
|
|
5
|
+
/** The Inertia protocol headers (inertia-laravel's Support\Header). */
|
|
6
|
+
declare const Header: {
|
|
7
|
+
readonly INERTIA: "X-Inertia";
|
|
8
|
+
readonly ERROR_BAG: "X-Inertia-Error-Bag";
|
|
9
|
+
readonly LOCATION: "X-Inertia-Location";
|
|
10
|
+
readonly REDIRECT: "X-Inertia-Redirect";
|
|
11
|
+
readonly VERSION: "X-Inertia-Version";
|
|
12
|
+
readonly PARTIAL_COMPONENT: "X-Inertia-Partial-Component";
|
|
13
|
+
readonly PARTIAL_ONLY: "X-Inertia-Partial-Data";
|
|
14
|
+
readonly PARTIAL_EXCEPT: "X-Inertia-Partial-Except";
|
|
15
|
+
readonly RESET: "X-Inertia-Reset";
|
|
16
|
+
readonly INFINITE_SCROLL_MERGE_INTENT: "X-Inertia-Infinite-Scroll-Merge-Intent";
|
|
17
|
+
readonly EXCEPT_ONCE_PROPS: "X-Inertia-Except-Once-Props";
|
|
18
|
+
};
|
|
19
|
+
/** 'a,b,,c' → ['a', 'b', 'c']; empty or missing → undefined ("not given"), like PropsResolver::parseHeader. */
|
|
20
|
+
declare function parseList(value: string | undefined): string[] | undefined;
|
|
21
|
+
|
|
22
|
+
/** A value or a (possibly async) callback that produces it. */
|
|
23
|
+
type PropValue<T> = T | PropCallback<T>;
|
|
24
|
+
/** Where a mergeable prop is merged on the client (Laravel's MergesProps). */
|
|
25
|
+
interface MergeState {
|
|
26
|
+
merge: boolean;
|
|
27
|
+
deep: boolean;
|
|
28
|
+
append: boolean;
|
|
29
|
+
appendPaths: string[];
|
|
30
|
+
prependPaths: string[];
|
|
31
|
+
matchOn: string[];
|
|
32
|
+
}
|
|
33
|
+
/** Once-prop settings (Laravel's ResolvesOnce). */
|
|
34
|
+
interface OnceState {
|
|
35
|
+
once: boolean;
|
|
36
|
+
fresh: boolean;
|
|
37
|
+
key: string | undefined;
|
|
38
|
+
ttlSeconds: number | undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The base of every Inertia prop type. `resolve()` produces the value; the flags say how the PropsResolver treats
|
|
42
|
+
* it. Subclasses switch the behaviours on, which is how Laravel's traits and marker interfaces work.
|
|
43
|
+
*/
|
|
44
|
+
declare abstract class Prop<T = unknown> {
|
|
45
|
+
protected readonly value: PropValue<T>;
|
|
46
|
+
/** A phantom field that carries the value type for the generated page props. Never set at runtime. */
|
|
47
|
+
readonly __value?: T;
|
|
48
|
+
/** Which prop type this is: the generated page props make deferred and optional props optional keys. */
|
|
49
|
+
abstract readonly kind: 'always' | 'optional' | 'defer' | 'merge' | 'once' | 'scroll';
|
|
50
|
+
protected readonly mergeState: MergeState;
|
|
51
|
+
protected readonly onceState: OnceState;
|
|
52
|
+
protected deferred: boolean;
|
|
53
|
+
protected deferGroup: string | undefined;
|
|
54
|
+
constructor(value: PropValue<T>);
|
|
55
|
+
/** Calls the callback, if the value is one. */
|
|
56
|
+
resolve(): Promise<unknown>;
|
|
57
|
+
/** Never sent on the first load (OptionalProp, DeferProp). */
|
|
58
|
+
ignoresFirstLoad(): boolean;
|
|
59
|
+
/** Sent even when a partial reload didn't ask for it (AlwaysProp). */
|
|
60
|
+
isAlways(): boolean;
|
|
61
|
+
/** Errors are reported and the prop is left out, instead of failing the page (defer(..., { rescue: true })). */
|
|
62
|
+
shouldRescue(): boolean;
|
|
63
|
+
/** once(), once(false), once(true, { as: 'key', until: 3600 }). */
|
|
64
|
+
once(value?: boolean, options?: {
|
|
65
|
+
as?: string;
|
|
66
|
+
until?: Date | number;
|
|
67
|
+
}): this;
|
|
68
|
+
/** A custom once key, so pages can share the prop under different names. */
|
|
69
|
+
as(key: string): this;
|
|
70
|
+
/** Send the prop again even though the client already has it. */
|
|
71
|
+
fresh(value?: boolean): this;
|
|
72
|
+
/** Expire after a number of seconds, or at a Date. */
|
|
73
|
+
until(delay: Date | number): this;
|
|
74
|
+
isMergeable(): boolean;
|
|
75
|
+
shouldMerge(): boolean;
|
|
76
|
+
shouldDeepMerge(): boolean;
|
|
77
|
+
matchesOn(): string[];
|
|
78
|
+
appendsAtRoot(): boolean;
|
|
79
|
+
prependsAtRoot(): boolean;
|
|
80
|
+
appendsAtPaths(): string[];
|
|
81
|
+
prependsAtPaths(): string[];
|
|
82
|
+
protected mergesAtRoot(): boolean;
|
|
83
|
+
isDeferrable(): boolean;
|
|
84
|
+
shouldDefer(): boolean;
|
|
85
|
+
group(): string;
|
|
86
|
+
isOnceable(): boolean;
|
|
87
|
+
shouldResolveOnce(): boolean;
|
|
88
|
+
shouldBeRefreshed(): boolean;
|
|
89
|
+
getKey(): string | undefined;
|
|
90
|
+
/** Epoch milliseconds, or null when the prop never expires. */
|
|
91
|
+
expiresAt(): number | null;
|
|
92
|
+
}
|
|
93
|
+
/** The fluent merge API shared by MergeProp, DeferProp and ScrollProp. */
|
|
94
|
+
declare abstract class MergeableProp<T = unknown> extends Prop<T> {
|
|
95
|
+
#private;
|
|
96
|
+
isMergeable(): boolean;
|
|
97
|
+
merge(): this;
|
|
98
|
+
deepMerge(): this;
|
|
99
|
+
/** Match array items on these keys instead of appending duplicates: matchOn('id'). */
|
|
100
|
+
matchOn(keys: string | string[]): this;
|
|
101
|
+
/** append() at the root, append('data') at a path, append('data', 'id') with a match key, or a map of both. */
|
|
102
|
+
append(path?: boolean | string | string[] | Record<string, string>, matchOn?: string): this;
|
|
103
|
+
prepend(path?: boolean | string | string[] | Record<string, string>, matchOn?: string): this;
|
|
104
|
+
}
|
|
105
|
+
/** Seconds from now until `delay` (a Date, or a number of seconds). */
|
|
106
|
+
declare function secondsUntil(delay: Date | number): number;
|
|
107
|
+
|
|
108
|
+
/** Sent on every response, even partial reloads that didn't ask for it (Inertia::always). */
|
|
109
|
+
declare class AlwaysProp<T = unknown> extends Prop<T> {
|
|
110
|
+
readonly kind: "always";
|
|
111
|
+
isAlways(): boolean;
|
|
112
|
+
}
|
|
113
|
+
/** Only evaluated on partial reloads that ask for it (Inertia::optional). */
|
|
114
|
+
declare class OptionalProp<T = unknown> extends Prop<T> {
|
|
115
|
+
readonly kind: "optional";
|
|
116
|
+
constructor(callback: PropCallback<T>);
|
|
117
|
+
ignoresFirstLoad(): boolean;
|
|
118
|
+
isOnceable(): boolean;
|
|
119
|
+
}
|
|
120
|
+
/** Loaded by the client in a follow-up request, grouped (Inertia::defer). */
|
|
121
|
+
declare class DeferProp<T = unknown> extends MergeableProp<T> {
|
|
122
|
+
#private;
|
|
123
|
+
readonly kind: "defer";
|
|
124
|
+
constructor(callback: PropCallback<T>, group?: string, options?: {
|
|
125
|
+
rescue?: boolean;
|
|
126
|
+
});
|
|
127
|
+
ignoresFirstLoad(): boolean;
|
|
128
|
+
isDeferrable(): boolean;
|
|
129
|
+
isOnceable(): boolean;
|
|
130
|
+
shouldRescue(): boolean;
|
|
131
|
+
}
|
|
132
|
+
/** Merged with the client's current value on partial reloads (Inertia::merge / Inertia::deepMerge). */
|
|
133
|
+
declare class MergeProp<T = unknown> extends MergeableProp<T> {
|
|
134
|
+
readonly kind: "merge";
|
|
135
|
+
constructor(value: PropValue<T>);
|
|
136
|
+
isOnceable(): boolean;
|
|
137
|
+
}
|
|
138
|
+
/** Resolved once, then kept by the client until it expires (Inertia::once). */
|
|
139
|
+
declare class OnceProp<T = unknown> extends Prop<T> {
|
|
140
|
+
readonly kind: "once";
|
|
141
|
+
constructor(callback: PropCallback<T>);
|
|
142
|
+
isOnceable(): boolean;
|
|
143
|
+
}
|
|
144
|
+
/** Page metadata for infinite scroll (Laravel's ProvidesScrollMetadata). */
|
|
145
|
+
interface ScrollMetadata {
|
|
146
|
+
pageName: string;
|
|
147
|
+
previousPage: string | number | null;
|
|
148
|
+
nextPage: string | number | null;
|
|
149
|
+
currentPage: string | number | null;
|
|
150
|
+
}
|
|
151
|
+
type MetadataResolver = (value: unknown) => ScrollMetadata;
|
|
152
|
+
/** Laravel's ScrollMetadata::fromPaginator for the Database paginators (matched by shape). */
|
|
153
|
+
declare function scrollMetadataFrom(value: unknown): ScrollMetadata;
|
|
154
|
+
/** A paginated prop the client merges page by page (Inertia::scroll). */
|
|
155
|
+
declare class ScrollProp<T = unknown> extends MergeableProp<T> {
|
|
156
|
+
#private;
|
|
157
|
+
readonly wrapper: string;
|
|
158
|
+
private readonly metadataResolver?;
|
|
159
|
+
readonly kind: "scroll";
|
|
160
|
+
constructor(value: PropValue<T>, wrapper?: string, metadataResolver?: MetadataResolver | undefined);
|
|
161
|
+
isDeferrable(): boolean;
|
|
162
|
+
/** Load the prop after the first render, like a deferred prop. */
|
|
163
|
+
defer(group?: string): this;
|
|
164
|
+
/** 'prepend' from the X-Inertia-Infinite-Scroll-Merge-Intent header prepends the wrapper; anything else appends. */
|
|
165
|
+
configureMergeIntent(intent: string | undefined): this;
|
|
166
|
+
/** Resolves once and caches, because both the value and its metadata need it. */
|
|
167
|
+
resolve(): Promise<unknown>;
|
|
168
|
+
metadata(): Promise<ScrollMetadata>;
|
|
169
|
+
}
|
|
170
|
+
declare const isProp: (value: unknown) => value is Prop;
|
|
171
|
+
|
|
172
|
+
type Obj$3 = Record<string, unknown>;
|
|
173
|
+
/** The page fields the resolver produces next to the props. Empty fields are left out. */
|
|
174
|
+
interface PropsMetadata {
|
|
175
|
+
sharedProps?: string[];
|
|
176
|
+
mergeProps?: string[];
|
|
177
|
+
prependProps?: string[];
|
|
178
|
+
deepMergeProps?: string[];
|
|
179
|
+
matchPropsOn?: string[];
|
|
180
|
+
deferredProps?: Record<string, string[]>;
|
|
181
|
+
rescuedProps?: string[];
|
|
182
|
+
scrollProps?: Record<string, InertiaScrollProp>;
|
|
183
|
+
onceProps?: Record<string, InertiaOnceProp>;
|
|
184
|
+
}
|
|
185
|
+
interface PropsResolverOptions {
|
|
186
|
+
/** config('inertia.expose_shared_prop_keys'), default true. */
|
|
187
|
+
exposeSharedPropKeys?: boolean;
|
|
188
|
+
/** Reports a rescued deferred prop's error (the exception handler). */
|
|
189
|
+
report?: (error: unknown) => void | Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* inertia-laravel's PropsResolver: walks the shared and page props, filters them for partial reloads, skips what
|
|
193
|
+
* the first load must not send (optional, deferred, already-loaded once props), resolves callbacks and toJSON()
|
|
194
|
+
* values, and collects the page metadata (merge, deferred, once, scroll, rescued, shared keys).
|
|
195
|
+
*/
|
|
196
|
+
declare class PropsResolver {
|
|
197
|
+
#private;
|
|
198
|
+
private readonly options;
|
|
199
|
+
constructor(request: HttpRequest, component: string, options?: PropsResolverOptions);
|
|
200
|
+
resolve(shared: Obj$3, props: Obj$3): Promise<{
|
|
201
|
+
props: Obj$3;
|
|
202
|
+
metadata: PropsMetadata;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The current container when it is a request scope (Http binds HttpRequest only there). */
|
|
207
|
+
declare function requestScope(): Container | undefined;
|
|
208
|
+
declare function currentRequest(): HttpRequest | undefined;
|
|
209
|
+
/** The request's session, or undefined outside a request or when no Session provider is registered. */
|
|
210
|
+
declare function optionalSession(): Session | undefined;
|
|
211
|
+
/** Is this an Inertia visit (X-Inertia header)? */
|
|
212
|
+
declare function isInertiaRequest(request: HttpRequest): boolean;
|
|
213
|
+
/** Laravel's Request::prefetch(): Purpose, Sec-Purpose or X-Moz is 'prefetch'. */
|
|
214
|
+
declare function isPrefetch(request: HttpRequest): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* A copy of `response` with another status and/or extra headers. Web Responses have a read-only status and may
|
|
217
|
+
* have immutable headers (Response.redirect()), so this always builds a new one around the same body.
|
|
218
|
+
*/
|
|
219
|
+
declare function rebuild(response: Response, changes: {
|
|
220
|
+
status?: number;
|
|
221
|
+
headers?: Record<string, string>;
|
|
222
|
+
}): Response;
|
|
223
|
+
declare function isRedirect(response: Response): boolean;
|
|
224
|
+
|
|
225
|
+
/** A page component that doesn't exist on disk (inertia.pages.ensure_pages_exist). */
|
|
226
|
+
declare class ComponentNotFoundError extends Error implements OrielError {
|
|
227
|
+
readonly component: string;
|
|
228
|
+
readonly kind: "Server";
|
|
229
|
+
readonly status = 500;
|
|
230
|
+
constructor(component: string);
|
|
231
|
+
}
|
|
232
|
+
/** An Inertia response outside a request, or a misconfiguration. */
|
|
233
|
+
declare class InertiaError extends Error implements OrielError {
|
|
234
|
+
readonly kind: "Server";
|
|
235
|
+
readonly status = 500;
|
|
236
|
+
constructor(message: string);
|
|
237
|
+
}
|
|
238
|
+
/** An SSR render that failed while inertia.ssr.throw_on_error is on. */
|
|
239
|
+
declare class SsrError extends Error implements OrielError {
|
|
240
|
+
readonly kind: "Server";
|
|
241
|
+
readonly status = 500;
|
|
242
|
+
constructor(message: string, options?: {
|
|
243
|
+
cause?: unknown;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
type Obj$2 = Record<string, unknown>;
|
|
248
|
+
/** Session keys inertia-laravel uses (Support\SessionKey). */
|
|
249
|
+
declare const SessionKey: {
|
|
250
|
+
readonly CLEAR_HISTORY: "inertia.clear_history";
|
|
251
|
+
readonly PRESERVE_FRAGMENT: "inertia.preserve_fragment";
|
|
252
|
+
readonly FLASH_DATA: "inertia.flash_data";
|
|
253
|
+
};
|
|
254
|
+
type UrlResolver = (request: HttpRequest) => string;
|
|
255
|
+
/** What the factory hands a response: everything decided before the controller returned. */
|
|
256
|
+
interface ResponseSettings {
|
|
257
|
+
shared: Obj$2;
|
|
258
|
+
rootView: string;
|
|
259
|
+
version: () => Promise<string>;
|
|
260
|
+
encryptHistory: boolean;
|
|
261
|
+
urlResolver?: UrlResolver;
|
|
262
|
+
flash: (key: string | Obj$2, value?: unknown) => void;
|
|
263
|
+
}
|
|
264
|
+
/** Path and query of the request, keeping a trailing slash (inertia-laravel's default URL resolver). */
|
|
265
|
+
declare function defaultUrl(request: HttpRequest): string;
|
|
266
|
+
/**
|
|
267
|
+
* An Inertia page response (inertia-laravel's Response). `C` and `P` carry the component name and props type,
|
|
268
|
+
* which the generated page-prop types read back.
|
|
269
|
+
*/
|
|
270
|
+
declare class Response$1<C extends string = string, P extends Obj$2 = Obj$2> implements InertiaResponse {
|
|
271
|
+
#private;
|
|
272
|
+
readonly component: C;
|
|
273
|
+
private readonly settings;
|
|
274
|
+
readonly __component?: C;
|
|
275
|
+
readonly __props?: P;
|
|
276
|
+
constructor(component: C, props: P, settings: ResponseSettings);
|
|
277
|
+
with(key: string | Obj$2, value?: unknown): this;
|
|
278
|
+
withViewData(key: string | Obj$2, value?: unknown): this;
|
|
279
|
+
rootView(view: string): this;
|
|
280
|
+
flash(key: string | Obj$2, value?: unknown): this;
|
|
281
|
+
/** The page object for this request. */
|
|
282
|
+
toPage(request: HttpRequest): Promise<InertiaPage>;
|
|
283
|
+
toResponse(request: unknown): Promise<globalThis.Response>;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The pages under the page paths, named as inertia() takes them ('Posts/Show'), sorted by name; a page in two paths is
|
|
287
|
+
* listed once, from the first. A file takes its longest matching extension, so `Show.component.ts` is 'Show'.
|
|
288
|
+
*/
|
|
289
|
+
declare function pageNames(paths: string[], extensions: string[]): Array<{
|
|
290
|
+
name: string;
|
|
291
|
+
file: string;
|
|
292
|
+
}>;
|
|
293
|
+
/** Is there a file for `component` ('Posts/Index') under a page path, with one of the extensions? */
|
|
294
|
+
declare function pageExists(component: string, paths: string[], extensions: string[]): boolean;
|
|
295
|
+
|
|
296
|
+
type Obj$1 = Record<string, unknown>;
|
|
297
|
+
type VersionResolver = string | null | (() => string | null | Promise<string | null>);
|
|
298
|
+
/**
|
|
299
|
+
* inertia-laravel's ResponseFactory. The application holds one (the root): props shared from a service provider
|
|
300
|
+
* and the app-wide settings live there. Each request gets a child (scoped): what the HandleInertiaRequests
|
|
301
|
+
* middleware or a controller shares stays in that request. A child reads through to its root.
|
|
302
|
+
*/
|
|
303
|
+
declare class ResponseFactory implements InertiaFactory {
|
|
304
|
+
#private;
|
|
305
|
+
protected readonly app: Application;
|
|
306
|
+
private readonly parent?;
|
|
307
|
+
constructor(app: Application, parent?: ResponseFactory | undefined);
|
|
308
|
+
/** A per-request child of this (root) factory. */
|
|
309
|
+
forRequest(): ResponseFactory;
|
|
310
|
+
setRootView(view: string): void;
|
|
311
|
+
getRootView(): string;
|
|
312
|
+
share(key: string | Obj$1, value?: unknown): void;
|
|
313
|
+
shareOnce(key: string, callback: PropCallback): OnceProp;
|
|
314
|
+
getShared(key?: string, defaultValue?: unknown): unknown;
|
|
315
|
+
flushShared(): void;
|
|
316
|
+
version(version: VersionResolver): void;
|
|
317
|
+
/** The asset version as a string ('' when there is none), like Laravel's `(string) $version`. */
|
|
318
|
+
getVersion(): Promise<string>;
|
|
319
|
+
resolveUrlUsing(resolver: UrlResolver | undefined): void;
|
|
320
|
+
encryptHistory(encrypt?: boolean): void;
|
|
321
|
+
clearHistory(): void;
|
|
322
|
+
preserveFragment(): void;
|
|
323
|
+
optional<T>(callback: PropCallback<T>): OptionalProp<T>;
|
|
324
|
+
defer<T>(callback: PropCallback<T>, group?: string, options?: {
|
|
325
|
+
rescue?: boolean;
|
|
326
|
+
}): DeferProp<T>;
|
|
327
|
+
always<T>(value: PropValue<T>): AlwaysProp<T>;
|
|
328
|
+
merge<T>(value: PropValue<T>): MergeProp<T>;
|
|
329
|
+
deepMerge<T>(value: PropValue<T>): MergeProp<T>;
|
|
330
|
+
once<T>(callback: PropCallback<T>): OnceProp<T>;
|
|
331
|
+
scroll<T>(value: PropValue<T>, wrapper?: string, metadata?: (value: T) => ScrollMetadata): ScrollProp<T>;
|
|
332
|
+
/** Flashes page.flash data for the next Inertia response (stored in the session immediately). */
|
|
333
|
+
flash(key: string | Obj$1, value?: unknown): this;
|
|
334
|
+
back(fallback?: string, status?: number): RedirectResponse;
|
|
335
|
+
/** 409 + X-Inertia-Location for Inertia requests (the client does a full visit), a plain 302 otherwise. */
|
|
336
|
+
location(url: string): globalThis.Response;
|
|
337
|
+
render<C extends string, P extends Obj$1 = Record<never, never>>(component: C, props?: P): Response$1<C, P>;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
type Obj = Record<string, unknown>;
|
|
341
|
+
/**
|
|
342
|
+
* The factory for the current context: the request's own (scoped) factory inside a request, else the
|
|
343
|
+
* application's root factory (a service provider sharing props for every request).
|
|
344
|
+
*/
|
|
345
|
+
declare function inertiaFactory(): ResponseFactory;
|
|
346
|
+
/** inertia('Posts/Index', { posts }) → an Inertia response; inertia() → the factory. */
|
|
347
|
+
declare function inertia(): ResponseFactory;
|
|
348
|
+
declare function inertia<C extends string, P extends Obj = Record<never, never>>(component: C, props?: P): Response$1<C, P>;
|
|
349
|
+
/**
|
|
350
|
+
* The Inertia facade: Inertia.render(), Inertia.share(), Inertia.defer(), Inertia.flash(...).back(), …
|
|
351
|
+
* Resolved on every access, so it always talks to the current request's factory.
|
|
352
|
+
*/
|
|
353
|
+
declare const Inertia: ResponseFactory;
|
|
354
|
+
|
|
355
|
+
/** Markup the view renderer emits as-is (Htmlable, like View's HtmlString; Inertia can't import View). */
|
|
356
|
+
declare class InertiaHtml implements Htmlable {
|
|
357
|
+
private readonly html;
|
|
358
|
+
constructor(html: string);
|
|
359
|
+
toHtml(): string;
|
|
360
|
+
toString(): string;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* The page as JSON for a <script type="application/json"> element: `/` is escaped (the protocol requires it) and
|
|
364
|
+
* `<`, `>` are \u-escaped so the JSON can never close the script element. No HTML entities.
|
|
365
|
+
*/
|
|
366
|
+
declare function pageJson(page: InertiaPage): string;
|
|
367
|
+
/** The client-side-rendered mount point: the page script, then the empty root element (Laravel's @inertia). */
|
|
368
|
+
declare function pageMarkup(page: InertiaPage, id?: string): string;
|
|
369
|
+
/** Laravel's @inertiaHead: the SSR head tags, or nothing when the page is rendered in the browser. */
|
|
370
|
+
declare function inertiaHead(page: InertiaPage): Promise<InertiaHtml>;
|
|
371
|
+
/** Laravel's @inertia: the SSR body, else the page script and the empty mount element. */
|
|
372
|
+
declare function inertiaBody(page: InertiaPage, id?: string): Promise<InertiaHtml>;
|
|
373
|
+
|
|
374
|
+
/** Flat field → first message (or every message with withAllErrors), or bag → fields when named bags are used. */
|
|
375
|
+
type ValidationErrors = Record<string, string | string[]> | Record<string, Record<string, string | string[]>>;
|
|
376
|
+
/**
|
|
377
|
+
* inertia-laravel's Middleware, the base of the app's HandleInertiaRequests (add it to the `web` group). It shares
|
|
378
|
+
* the validation errors and your share() props, sets the asset version and root view, and turns responses into
|
|
379
|
+
* what the Inertia client expects: Vary, 409 on a version change, 303 after PUT/PATCH/DELETE, back() for empty
|
|
380
|
+
* responses and 409 + X-Inertia-Redirect for redirects with a #fragment.
|
|
381
|
+
*/
|
|
382
|
+
declare class InertiaMiddleware implements Middleware {
|
|
383
|
+
/** The root view rendered on the first visit: resources/views/app.tsx. */
|
|
384
|
+
protected rootViewName: string;
|
|
385
|
+
/** Send every message per field instead of the first one. */
|
|
386
|
+
protected withAllErrors: boolean;
|
|
387
|
+
/** Paths (wildcards allowed) rendered without SSR. */
|
|
388
|
+
protected withoutSsr: string[];
|
|
389
|
+
protected readonly container: Container;
|
|
390
|
+
/** The asset version: a hash of app.asset_url, else of public/build/manifest.json, else none. */
|
|
391
|
+
version(_request: HttpRequest): Promise<string | null>;
|
|
392
|
+
/** Props shared with every page. Override and spread `await super.share(request)` into your own. */
|
|
393
|
+
share(request: HttpRequest): Promise<{
|
|
394
|
+
errors: AlwaysProp<ValidationErrors>;
|
|
395
|
+
}>;
|
|
396
|
+
/** Shared once props: sent on the first visit, then kept by the client. */
|
|
397
|
+
shareOnce(_request: HttpRequest): Promise<Record<string, OnceProp | PropCallback>>;
|
|
398
|
+
rootView(_request: HttpRequest): string;
|
|
399
|
+
/** How page.url is built; undefined keeps the default (path + query). */
|
|
400
|
+
urlResolver(): UrlResolver | undefined;
|
|
401
|
+
handle(request: HttpRequest, next: Next): Promise<Response>;
|
|
402
|
+
/** The session's flashed errors ({ [bag]: { field: string[] } }), shaped for the client. */
|
|
403
|
+
resolveValidationErrors(request: HttpRequest): ValidationErrors;
|
|
404
|
+
/** inertia.store_previous_url: Inertia GET visits (not prefetches or same-page partial reloads) become previous(). */
|
|
405
|
+
shouldStoreCurrentUrl(request: HttpRequest, _response: Response): boolean;
|
|
406
|
+
onEmptyResponse(request: HttpRequest, _response: Response): Promise<Response>;
|
|
407
|
+
onRedirectWithFragment(_request: HttpRequest, response: Response): Promise<Response>;
|
|
408
|
+
onVersionChange(request: HttpRequest, _response: Response): Promise<Response>;
|
|
409
|
+
/** Keeps Inertia flash data for the page the redirect leads to. */
|
|
410
|
+
protected reflash(session: Session): void;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** Encrypts the browser history state of the pages behind it (route middleware alias `inertia.encrypt`). */
|
|
414
|
+
declare class EncryptHistory implements Middleware {
|
|
415
|
+
#private;
|
|
416
|
+
handle(request: HttpRequest, next: Next): Promise<Response>;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Laravel's $request->isPrecognitive(): this request only asks whether its data would pass (a `precognitive` route). */
|
|
420
|
+
declare function isPrecognitive(request: HttpRequest): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Laravel's HandlePrecognitiveRequests (the `precognitive` alias): a request with `Precognition: true` (Inertia's
|
|
423
|
+
* `useForm().validate()`, `<Form validate>`, laravel-precognition) runs the route's action only up to its validation.
|
|
424
|
+
* Passing answers 204 with `Precognition-Success: true`; failing, the usual 422 with the errors; and nothing after the
|
|
425
|
+
* validation runs. `Precognition-Validate-Only: name,email` checks those fields only. Every response varies on
|
|
426
|
+
* `Precognition`, an error's too: the middleware renders what is thrown through it before adding its headers.
|
|
427
|
+
*
|
|
428
|
+
* Oriel validates inside the action (`await StoreUserRequest.validate()`, `request().validate({…})`), where Laravel
|
|
429
|
+
* resolves the FormRequest before calling it, so a precognitive route must validate before it changes anything: what
|
|
430
|
+
* comes before the validation runs. An action that answers a success without validating is an error (a 500) on any
|
|
431
|
+
* method but GET and HEAD, which answer 204 as Laravel does; a redirect or an error goes through as it is.
|
|
432
|
+
*/
|
|
433
|
+
declare class HandlePrecognitiveRequests implements Middleware {
|
|
434
|
+
handle(request: HttpRequest, next: Next): Promise<Response>;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Marks `request` as client-rendered when it matches one of `paths` (wildcards allowed). */
|
|
438
|
+
declare function withoutSsr(request: HttpRequest, paths: string[]): void;
|
|
439
|
+
declare function isExcludedFromSsr(request: HttpRequest): boolean;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Binds the Inertia factory (one root factory, plus a scoped child per request), the SSR gateway and the
|
|
443
|
+
* `inertia.encrypt` and `precognitive` middleware aliases, merges config/inertia defaults and registers the inertia:*
|
|
444
|
+
* commands.
|
|
445
|
+
*/
|
|
446
|
+
declare class InertiaServiceProvider extends ServiceProvider {
|
|
447
|
+
register(): void;
|
|
448
|
+
boot(): void;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** Why an SSR render failed (inertia-laravel's SsrRenderFailed event payload). */
|
|
452
|
+
interface SsrFailure {
|
|
453
|
+
page: InertiaPage;
|
|
454
|
+
error: string;
|
|
455
|
+
type: string;
|
|
456
|
+
hint?: string;
|
|
457
|
+
browserApi?: string;
|
|
458
|
+
stack?: string;
|
|
459
|
+
sourceLocation?: string;
|
|
460
|
+
}
|
|
461
|
+
/** The event name dispatched through the EventDispatcher when an SSR render fails. */
|
|
462
|
+
declare const SSR_RENDER_FAILED = "inertia.ssr.failed";
|
|
463
|
+
/**
|
|
464
|
+
* inertia-laravel's HttpGateway. Production: POST the page to {inertia.ssr.url}/render. While Vite runs hot
|
|
465
|
+
* (public/hot exists): POST to {hot url}/__inertia_ssr, which @inertiajs/vite serves. Any failure falls back to
|
|
466
|
+
* client-side rendering (undefined), unless inertia.ssr.throw_on_error is on.
|
|
467
|
+
*/
|
|
468
|
+
declare class HttpGateway implements InertiaSsrGateway {
|
|
469
|
+
#private;
|
|
470
|
+
protected readonly app: Application;
|
|
471
|
+
constructor(app: Application);
|
|
472
|
+
disable(condition?: boolean | (() => boolean)): void;
|
|
473
|
+
/** Paths (wildcards allowed) never rendered on the server. */
|
|
474
|
+
except(paths: string | string[]): void;
|
|
475
|
+
dispatch(page: InertiaPage): Promise<InertiaSsrResponse | undefined>;
|
|
476
|
+
/** GET {inertia.ssr.url}/health: any 2xx is healthy. */
|
|
477
|
+
isHealthy(): Promise<boolean>;
|
|
478
|
+
productionUrl(): string;
|
|
479
|
+
/** inertia.ssr.hot_url, else the Vite dev server URL in public/hot; undefined when Vite isn't running. */
|
|
480
|
+
hotUrl(): string | undefined;
|
|
481
|
+
/** inertia.ssr.bundle, else bootstrap/ssr/{ssr,app}.{js,mjs}, else public/js/{ssr,app}.js (BundleDetector). */
|
|
482
|
+
bundle(): string | undefined;
|
|
483
|
+
enabled(request: HttpRequest | undefined): boolean;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** One named route as the client's route() needs it. */
|
|
487
|
+
interface RouteTableEntry {
|
|
488
|
+
uri: string;
|
|
489
|
+
methods: string[];
|
|
490
|
+
}
|
|
491
|
+
interface RouteParameterInfo {
|
|
492
|
+
name: string;
|
|
493
|
+
optional: boolean;
|
|
494
|
+
/** The binding column from '{post:slug}'. */
|
|
495
|
+
field: string | undefined;
|
|
496
|
+
}
|
|
497
|
+
/** '{post}', '{post?}', '{post:slug}' in URI order. */
|
|
498
|
+
declare function routeParameters(uri: string): RouteParameterInfo[];
|
|
499
|
+
/** Every named route, sorted by name, minus the names matching `except` (wildcards allowed: 'admin.*'). */
|
|
500
|
+
declare function routeTable(routes: readonly Route[], except?: string[]): Record<string, RouteTableEntry>;
|
|
501
|
+
/**
|
|
502
|
+
* resources/js/oriel/routes.ts: the route table the browser's route() reads, and the RouteList augmentation that
|
|
503
|
+
* types route names and parameters.
|
|
504
|
+
*/
|
|
505
|
+
declare function renderRoutesModule(table: Record<string, RouteTableEntry>, clientModule?: string): string;
|
|
506
|
+
/**
|
|
507
|
+
* types/routes.d.ts: the route names for the server's route(), redirect().route() and UrlGenerator. The bundled
|
|
508
|
+
* @orieljs/framework declares RouteList in both entry points, so both are augmented.
|
|
509
|
+
*/
|
|
510
|
+
declare function renderServerRouteTypes(table: Record<string, RouteTableEntry>): string;
|
|
511
|
+
|
|
512
|
+
/** app/Http/Middleware/HandleInertiaRequests.ts, written by inertia:middleware. */
|
|
513
|
+
declare const MIDDLEWARE_STUB = "import { InertiaMiddleware } from '@orieljs/framework'\nimport type { HttpRequest } from '@orieljs/framework/contracts'\n\nexport class {{ class }} extends InertiaMiddleware {\n /** The root view loaded on the first page visit: resources/views/app.tsx. */\n protected override rootViewName = 'app'\n\n /** Props shared with every page (typed for the pages by `oriel inertia:types`). */\n override async share(request: HttpRequest) {\n return {\n ...(await super.share(request)),\n }\n }\n}\n";
|
|
514
|
+
/** The page-type generator lives in @orieljs/vite (it needs the TypeScript compiler, a dev dependency). */
|
|
515
|
+
interface PageTypesModule {
|
|
516
|
+
generatePageTypes(options: {
|
|
517
|
+
root: string;
|
|
518
|
+
output: string;
|
|
519
|
+
tsconfig?: string;
|
|
520
|
+
}): Promise<{
|
|
521
|
+
output: string;
|
|
522
|
+
pages: number;
|
|
523
|
+
warnings: string[];
|
|
524
|
+
}>;
|
|
525
|
+
}
|
|
526
|
+
interface InertiaCommandOptions {
|
|
527
|
+
/** Replaces the dynamic import of @orieljs/vite/types (tests). */
|
|
528
|
+
pageTypes?: () => Promise<PageTypesModule | undefined>;
|
|
529
|
+
/** Replaces child_process.spawn for inertia:start-ssr (tests). */
|
|
530
|
+
spawn?: typeof spawn;
|
|
531
|
+
}
|
|
532
|
+
/** route:types, inertia:types, inertia:middleware, inertia:start-ssr, inertia:stop-ssr and inertia:check-ssr. */
|
|
533
|
+
declare function registerInertiaCommands(kernel: ConsoleKernel, app: Application, gateway: HttpGateway, options?: InertiaCommandOptions): void;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Types that turn what a controller passes to inertia() into what the page receives: prop types unwrapped,
|
|
537
|
+
* callbacks resolved, models, paginators and dates serialized the way JSON.stringify(toJSON()) does.
|
|
538
|
+
* The generated page-prop types (resources/js/oriel/pages.d.ts) are built from these.
|
|
539
|
+
*/
|
|
540
|
+
/** Deferred and optional props are missing on the first load, so they are optional keys. */
|
|
541
|
+
interface MaybeMissingProp {
|
|
542
|
+
readonly kind: 'defer' | 'optional';
|
|
543
|
+
}
|
|
544
|
+
/** The value inside an Inertia prop type, or the value itself. */
|
|
545
|
+
type Unwrap<V> = V extends {
|
|
546
|
+
readonly kind: string;
|
|
547
|
+
readonly __value?: infer T;
|
|
548
|
+
} ? T : V;
|
|
549
|
+
type Simplify<T> = {
|
|
550
|
+
[K in keyof T]: T[K];
|
|
551
|
+
} & {};
|
|
552
|
+
/** Keys that may be absent: deferred/optional props and values that can be undefined (JSON drops them). */
|
|
553
|
+
type OptionalKeys<T> = {
|
|
554
|
+
[K in keyof T]-?: T[K] extends MaybeMissingProp ? K : undefined extends T[K] ? K : never;
|
|
555
|
+
}[keyof T];
|
|
556
|
+
interface LengthAwarePage<T> {
|
|
557
|
+
current_page: number;
|
|
558
|
+
data: T[];
|
|
559
|
+
first_page_url: string;
|
|
560
|
+
from: number | null;
|
|
561
|
+
last_page: number;
|
|
562
|
+
last_page_url: string;
|
|
563
|
+
links: Array<{
|
|
564
|
+
url: string | null;
|
|
565
|
+
label: string;
|
|
566
|
+
active: boolean;
|
|
567
|
+
}>;
|
|
568
|
+
next_page_url: string | null;
|
|
569
|
+
path: string;
|
|
570
|
+
per_page: number;
|
|
571
|
+
prev_page_url: string | null;
|
|
572
|
+
to: number | null;
|
|
573
|
+
total: number;
|
|
574
|
+
}
|
|
575
|
+
interface SimplePage<T> {
|
|
576
|
+
current_page: number;
|
|
577
|
+
current_page_url: string;
|
|
578
|
+
data: T[];
|
|
579
|
+
first_page_url: string;
|
|
580
|
+
from: number | null;
|
|
581
|
+
next_page_url: string | null;
|
|
582
|
+
path: string;
|
|
583
|
+
per_page: number;
|
|
584
|
+
prev_page_url: string | null;
|
|
585
|
+
to: number | null;
|
|
586
|
+
}
|
|
587
|
+
interface CursorPage<T> {
|
|
588
|
+
data: T[];
|
|
589
|
+
path: string;
|
|
590
|
+
per_page: number;
|
|
591
|
+
next_cursor: string | null;
|
|
592
|
+
next_page_url: string | null;
|
|
593
|
+
prev_cursor: string | null;
|
|
594
|
+
prev_page_url: string | null;
|
|
595
|
+
}
|
|
596
|
+
/** An object after serialization: keys typed one by one, optional where the value may be missing. */
|
|
597
|
+
type SerializedObject<T> = Simplify<{
|
|
598
|
+
[K in Exclude<keyof T, OptionalKeys<T>> as K extends string ? K : never]: Serialized<Unwrap<T[K]>>;
|
|
599
|
+
} & {
|
|
600
|
+
[K in OptionalKeys<T> as K extends string ? K : never]?: Serialized<Exclude<Unwrap<T[K]>, undefined>>;
|
|
601
|
+
}>;
|
|
602
|
+
/** A model's generated column types (types/models.d.ts declares `$attributes`), or never for anything else. */
|
|
603
|
+
type ModelAttributes<T> = T extends {
|
|
604
|
+
$attributes?: infer A;
|
|
605
|
+
} ? (unknown extends A ? never : NonNullable<A>) : never;
|
|
606
|
+
/** What a prop value looks like on the page. */
|
|
607
|
+
type Serialized<T> = T extends string | number | boolean | null ? T : T extends undefined | symbol | bigint ? never : T extends Date ? string : T extends {
|
|
608
|
+
readonly kind: string;
|
|
609
|
+
readonly __value?: infer V;
|
|
610
|
+
} ? Serialized<V> : T extends (...args: never[]) => infer R ? Serialized<Awaited<R>> : T extends PromiseLike<infer R> ? Serialized<R> : T extends {
|
|
611
|
+
items(): Array<infer I>;
|
|
612
|
+
total(): number;
|
|
613
|
+
lastPage(): number;
|
|
614
|
+
} ? LengthAwarePage<Serialized<I>> : T extends {
|
|
615
|
+
items(): Array<infer I>;
|
|
616
|
+
getCursorName(): string;
|
|
617
|
+
} ? CursorPage<Serialized<I>> : T extends {
|
|
618
|
+
items(): Array<infer I>;
|
|
619
|
+
getPageName(): string;
|
|
620
|
+
} ? SimplePage<Serialized<I>> : T extends {
|
|
621
|
+
toJSON(): infer J;
|
|
622
|
+
} ? ModelAttributes<T> extends never ? Serialized<J> : SerializedObject<ModelAttributes<T>> : T extends ReadonlyArray<infer I> ? Array<Serialized<I>> : T extends object ? SerializedObject<T> : unknown;
|
|
623
|
+
/** The props of component `C` from a controller method's return type `R` (a union when it returns several). */
|
|
624
|
+
type PagePropsFrom<R, C extends string> = Awaited<R> extends infer Result ? Result extends {
|
|
625
|
+
readonly component: C;
|
|
626
|
+
readonly __props?: infer P;
|
|
627
|
+
} ? SerializedObject<P> : never : never;
|
|
628
|
+
/** The shared props of the app's HandleInertiaRequests middleware (the resolved share() result). */
|
|
629
|
+
type SharedPropsFrom<M> = M extends {
|
|
630
|
+
share(...args: never[]): infer R;
|
|
631
|
+
} ? SerializedObject<Awaited<R>> : Record<never, never>;
|
|
632
|
+
|
|
633
|
+
export { AlwaysProp, ComponentNotFoundError, type CursorPage, DeferProp, EncryptHistory, HandlePrecognitiveRequests, Header, HttpGateway, Inertia, type InertiaCommandOptions, InertiaError, InertiaHtml, InertiaMiddleware, Response$1 as InertiaPageResponse, ResponseFactory as InertiaResponseFactory, InertiaServiceProvider, type LengthAwarePage, MIDDLEWARE_STUB, MergeProp, MergeableProp, OnceProp, OptionalProp, type PagePropsFrom, type PageTypesModule, Prop, type PropValue, type PropsMetadata, PropsResolver, type PropsResolverOptions, type ResponseSettings, type RouteParameterInfo, type RouteTableEntry, SSR_RENDER_FAILED, type ScrollMetadata, ScrollProp, type Serialized, type SerializedObject, SessionKey, type SharedPropsFrom, type SimplePage, SsrError, type SsrFailure, type UrlResolver, type ValidationErrors, currentRequest, defaultUrl, inertia, inertiaBody, inertiaFactory, inertiaHead, isExcludedFromSsr, isInertiaRequest, isPrecognitive, isPrefetch, isProp, isRedirect, optionalSession, pageExists, pageJson, pageMarkup, pageNames, parseList, rebuild, registerInertiaCommands, renderRoutesModule, renderServerRouteTypes, requestScope, routeParameters, routeTable, scrollMetadataFrom, secondsUntil, withoutSsr };
|