@blacklizard/inertia-express 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -23
- package/dist/core/index.d.ts +2 -552
- package/dist/core/index.js +2 -662
- package/dist/core-ChQbBw-k.js +1499 -0
- package/dist/core-ChQbBw-k.js.map +1 -0
- package/dist/express/index.d.ts +17 -3
- package/dist/express/index.d.ts.map +1 -1
- package/dist/express/index.js +35 -6
- package/dist/express/index.js.map +1 -1
- package/dist/index-PWaujyMo.d.ts +1133 -0
- package/dist/index-PWaujyMo.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
//#region src/core/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Inertia.js v3 protocol types.
|
|
4
|
+
*
|
|
5
|
+
* Reference: https://inertiajs.com/the-protocol
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Free-form bag of page props handed to the client component.
|
|
9
|
+
*/
|
|
10
|
+
type PageProps = Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* The page object returned to the Inertia client (for `X-Inertia` requests)
|
|
13
|
+
* or embedded into the initial HTML response on first load.
|
|
14
|
+
*/
|
|
15
|
+
interface InertiaPage<TProps extends PageProps = PageProps> {
|
|
16
|
+
component: string;
|
|
17
|
+
props: TProps;
|
|
18
|
+
url: string;
|
|
19
|
+
version: string | null;
|
|
20
|
+
/**
|
|
21
|
+
* v3: instructs the client to clear browser history state on this visit.
|
|
22
|
+
*/
|
|
23
|
+
clearHistory: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* v3: instructs the client to encrypt history state for this page.
|
|
26
|
+
*/
|
|
27
|
+
encryptHistory: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* v3: instructs the client to preserve the URL fragment across this visit.
|
|
30
|
+
*/
|
|
31
|
+
preserveFragment: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* v3: top-level keys of props that came from shared props.
|
|
34
|
+
*/
|
|
35
|
+
sharedProps?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* v3: keys whose props should be merged (appended) on the client rather than replaced.
|
|
38
|
+
*/
|
|
39
|
+
mergeProps?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* v3: keys whose props should be prepended on the client rather than replaced.
|
|
42
|
+
*/
|
|
43
|
+
prependProps?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* v3: keys whose props should be *deep*-merged on the client (recursive merge
|
|
46
|
+
* rather than shallow append).
|
|
47
|
+
*/
|
|
48
|
+
deepMergeProps?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* v3: dotted `prop.field` paths telling the client which field to match on
|
|
51
|
+
* when merging arrays of objects (used to dedupe rather than blindly append).
|
|
52
|
+
*/
|
|
53
|
+
matchPropsOn?: string[];
|
|
54
|
+
/**
|
|
55
|
+
* v3: keys whose props should be deferred and fetched in a follow-up partial reload.
|
|
56
|
+
* Grouped by deferred-load group name.
|
|
57
|
+
*/
|
|
58
|
+
deferredProps?: Record<string, string[]>;
|
|
59
|
+
/**
|
|
60
|
+
* v3: keys of props whose resolution failed and was rescued by the server.
|
|
61
|
+
*/
|
|
62
|
+
rescuedProps?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* v3: infinite-scroll pagination metadata, keyed by prop path.
|
|
65
|
+
*/
|
|
66
|
+
scrollProps?: Record<string, ScrollMetadata & {
|
|
67
|
+
reset: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* v3: once-prop metadata, keyed by once key.
|
|
71
|
+
*/
|
|
72
|
+
onceProps?: Record<string, OnceMetadata>;
|
|
73
|
+
/**
|
|
74
|
+
* Read-once flash data, surfaced as a *top-level* page key (sibling to
|
|
75
|
+
* `props`) rather than a prop — mirroring inertia-laravel's
|
|
76
|
+
* `Response::resolveFlashData`. Omitted entirely when there is no flash.
|
|
77
|
+
*/
|
|
78
|
+
flash?: unknown;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Globally shared props: either a static object merged into every page, or
|
|
82
|
+
* a (possibly async) function that returns one for the current request.
|
|
83
|
+
*/
|
|
84
|
+
type SharedPropsInput<TReq = unknown> = PageProps | ((req: TReq) => PageProps | Promise<PageProps>);
|
|
85
|
+
/**
|
|
86
|
+
* Infinite-scroll pagination metadata for one scroll prop.
|
|
87
|
+
*/
|
|
88
|
+
interface ScrollMetadata {
|
|
89
|
+
pageName: string;
|
|
90
|
+
previousPage: number | string | null;
|
|
91
|
+
nextPage: number | string | null;
|
|
92
|
+
currentPage: number | string | null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Metadata for one once-prop: the prop path it resolves and its expiry as a
|
|
96
|
+
* millisecond epoch timestamp, or `null` when it never expires.
|
|
97
|
+
*/
|
|
98
|
+
interface OnceMetadata {
|
|
99
|
+
prop: string;
|
|
100
|
+
expiresAt: number | null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Page-level metadata produced while resolving props; every key is omitted
|
|
104
|
+
* when empty.
|
|
105
|
+
*/
|
|
106
|
+
interface PropsMetadata {
|
|
107
|
+
sharedProps?: string[];
|
|
108
|
+
mergeProps?: string[];
|
|
109
|
+
prependProps?: string[];
|
|
110
|
+
deepMergeProps?: string[];
|
|
111
|
+
matchPropsOn?: string[];
|
|
112
|
+
deferredProps?: Record<string, string[]>;
|
|
113
|
+
rescuedProps?: string[];
|
|
114
|
+
scrollProps?: Record<string, ScrollMetadata & {
|
|
115
|
+
reset: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
onceProps?: Record<string, OnceMetadata>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Callback invoked when a rescued prop throws during resolution. The hook's
|
|
121
|
+
* own failures are contained: a synchronous throw or a rejected returned
|
|
122
|
+
* promise is logged through the default reporter (`console.error`) and never
|
|
123
|
+
* propagates or surfaces as an unhandled rejection.
|
|
124
|
+
*
|
|
125
|
+
* @param error The thrown value.
|
|
126
|
+
* @param path Dotted path of the prop that failed.
|
|
127
|
+
*/
|
|
128
|
+
type RescueHandler = (error: unknown, path: string) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Per-response overrides for history-related page flags.
|
|
131
|
+
*/
|
|
132
|
+
interface RenderOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Override `clearHistory` for this response.
|
|
135
|
+
*/
|
|
136
|
+
clearHistory?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Override `encryptHistory` for this response.
|
|
139
|
+
*/
|
|
140
|
+
encryptHistory?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Override `preserveFragment` for this response.
|
|
143
|
+
*/
|
|
144
|
+
preserveFragment?: boolean;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Normalized view of an incoming HTTP request from the perspective of the
|
|
148
|
+
* Inertia v3 protocol. Produced by {@link parseInertiaRequest}.
|
|
149
|
+
*/
|
|
150
|
+
interface InertiaRequestInfo {
|
|
151
|
+
isInertia: boolean;
|
|
152
|
+
version: string | null;
|
|
153
|
+
partialComponent: string | null;
|
|
154
|
+
partialOnly: string[] | null;
|
|
155
|
+
partialExcept: string[] | null;
|
|
156
|
+
errorBag: string | null;
|
|
157
|
+
resetKeys: string[] | null;
|
|
158
|
+
/**
|
|
159
|
+
* Once-prop keys the client already holds (`X-Inertia-Except-Once-Props`);
|
|
160
|
+
* `[]` when the header is absent.
|
|
161
|
+
*/
|
|
162
|
+
exceptOnceProps: string[];
|
|
163
|
+
/**
|
|
164
|
+
* Infinite-scroll merge direction (`X-Inertia-Infinite-Scroll-Merge-Intent`);
|
|
165
|
+
* `'prepend'` only on that exact value, otherwise `'append'`.
|
|
166
|
+
*/
|
|
167
|
+
mergeIntent: 'append' | 'prepend';
|
|
168
|
+
method: string;
|
|
169
|
+
url: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Asset version source: a literal string, `null` (disables checks), or a
|
|
173
|
+
* (possibly async) function that derives a version per request.
|
|
174
|
+
*/
|
|
175
|
+
type VersionResolver<TReq = unknown> = string | null | (() => string | null | Promise<string | null>) | ((req: TReq) => string | null | Promise<string | null>);
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/core/cache.d.ts
|
|
178
|
+
/**
|
|
179
|
+
* Pluggable storage interface for the SSR view cache.
|
|
180
|
+
*
|
|
181
|
+
* Implementations live outside the core package — see
|
|
182
|
+
* `createMemoryCacheStore` in `@blacklizard/inertia-express` and
|
|
183
|
+
* `createRedisCacheStore` in `@blacklizard/inertia-cache-redis`.
|
|
184
|
+
*
|
|
185
|
+
* Values are arbitrary JSON — usually `SsrCacheEntry` (`{ head, body, ... }`).
|
|
186
|
+
* The store should not interpret them.
|
|
187
|
+
*/
|
|
188
|
+
interface SsrCacheStore {
|
|
189
|
+
get: (key: string) => Promise<SsrCacheEntry | null>;
|
|
190
|
+
set: (key: string, value: SsrCacheEntry, ttlSeconds: number) => Promise<void>;
|
|
191
|
+
delete: (key: string) => Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* What we actually store per cache hit. Includes everything needed to
|
|
195
|
+
* reconstruct the HTML response without re-running the SSR renderer.
|
|
196
|
+
*/
|
|
197
|
+
interface SsrCacheEntry {
|
|
198
|
+
head: string | string[];
|
|
199
|
+
body: string;
|
|
200
|
+
bodyIsFullRoot?: boolean;
|
|
201
|
+
/** ISO timestamp when this entry was stored. Useful for debugging. */
|
|
202
|
+
storedAt: string;
|
|
203
|
+
/**
|
|
204
|
+
* The page object the entry was rendered from, kept for inspection and
|
|
205
|
+
* invalidation tooling. A cache hit renders the page resolved for the
|
|
206
|
+
* current request, not this one, so per-request fields such as `url` and
|
|
207
|
+
* once-prop expiry stay current.
|
|
208
|
+
*/
|
|
209
|
+
page: InertiaPage;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Stable JSON encoding: keys sorted recursively, undefined dropped, NaN/Inf
|
|
213
|
+
* normalized. Two equal-by-value objects always produce the same string,
|
|
214
|
+
* so they hash to the same cache key.
|
|
215
|
+
*
|
|
216
|
+
* @param value Arbitrary JSON-shaped input.
|
|
217
|
+
*/
|
|
218
|
+
declare function canonicalStringify(value: unknown): string;
|
|
219
|
+
/**
|
|
220
|
+
* Inputs to {@link computeSsrCacheKey}.
|
|
221
|
+
*/
|
|
222
|
+
interface ComputeCacheKeyInput {
|
|
223
|
+
/** Cache namespace, e.g. `"inertia:ssr"`. */
|
|
224
|
+
prefix: string;
|
|
225
|
+
/** Asset version. Becomes part of the key so deploys auto-invalidate. */
|
|
226
|
+
version: string | null;
|
|
227
|
+
/** Component name being rendered. */
|
|
228
|
+
component: string;
|
|
229
|
+
/** Final, fully-resolved props (post shared-merge, post closure and descriptor resolution). */
|
|
230
|
+
props: PageProps;
|
|
231
|
+
/** Optional extra discriminator (locale, theme, A/B bucket, etc.). */
|
|
232
|
+
discriminator?: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Build the cache key for an SSR cache entry.
|
|
236
|
+
*
|
|
237
|
+
* Shape: `${prefix}:${version}:${component}:${sha256(props[+discriminator])}`
|
|
238
|
+
*
|
|
239
|
+
* Including `version` in the key namespace means a deploy that bumps the
|
|
240
|
+
* asset version atomically retires every old key — no flush, no race.
|
|
241
|
+
*
|
|
242
|
+
* @param input Prefix, version, component, resolved props, optional discriminator.
|
|
243
|
+
*/
|
|
244
|
+
declare function computeSsrCacheKey(input: ComputeCacheKeyInput): string;
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/core/dot-props.d.ts
|
|
247
|
+
/**
|
|
248
|
+
* Unpacks top-level dot-notation keys into nested objects, like `Arr::set`.
|
|
249
|
+
*
|
|
250
|
+
* Bare functions along the intermediate segments, and at the dotted key itself, are called and
|
|
251
|
+
* awaited first. Non-object segments are replaced by fresh objects. Prop descriptors are left as
|
|
252
|
+
* values for the resolver. The input and the nested objects it holds are never mutated.
|
|
253
|
+
*
|
|
254
|
+
* @param props Page props that may contain dotted keys.
|
|
255
|
+
*/
|
|
256
|
+
declare function unpackDotProps(props: PageProps): Promise<PageProps>;
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/core/errors.d.ts
|
|
259
|
+
/**
|
|
260
|
+
* Flat map of `field → first error message`, the shape the Inertia client
|
|
261
|
+
* expects under `props.errors`.
|
|
262
|
+
*/
|
|
263
|
+
type ValidationErrors = Record<string, string>;
|
|
264
|
+
/**
|
|
265
|
+
* Apply error-bag scoping to a flat errors object, matching the official
|
|
266
|
+
* Inertia behavior. When `bag` is set, errors are namespaced under
|
|
267
|
+
* `props.errors[bag]`. When `bag` is null, errors live at `props.errors`.
|
|
268
|
+
*
|
|
269
|
+
* @param errors Flat field-to-message map.
|
|
270
|
+
* @param bag Optional error-bag name (e.g. `"createUser"`); null for top-level.
|
|
271
|
+
*/
|
|
272
|
+
declare function scopeErrors(errors: ValidationErrors, bag: string | null): PageProps;
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/core/headers.d.ts
|
|
275
|
+
/**
|
|
276
|
+
* Canonical Inertia v3 protocol header names.
|
|
277
|
+
*
|
|
278
|
+
* The Inertia client sends these headers on every visit. The server uses
|
|
279
|
+
* them to decide between a full HTML response and a JSON page response,
|
|
280
|
+
* and to scope partial reloads.
|
|
281
|
+
*/
|
|
282
|
+
declare const INERTIA_HEADERS: {
|
|
283
|
+
readonly inertia: "x-inertia";
|
|
284
|
+
readonly version: "x-inertia-version";
|
|
285
|
+
readonly partialComponent: "x-inertia-partial-component";
|
|
286
|
+
readonly partialData: "x-inertia-partial-data";
|
|
287
|
+
readonly partialExcept: "x-inertia-partial-except";
|
|
288
|
+
readonly errorBag: "x-inertia-error-bag";
|
|
289
|
+
readonly reset: "x-inertia-reset";
|
|
290
|
+
readonly location: "x-inertia-location";
|
|
291
|
+
readonly exceptOnceProps: "x-inertia-except-once-props";
|
|
292
|
+
readonly mergeIntent: "x-inertia-infinite-scroll-merge-intent";
|
|
293
|
+
};
|
|
294
|
+
type HeaderRecord = Record<string, string | string[] | undefined>;
|
|
295
|
+
/**
|
|
296
|
+
* Parse a request's headers into a normalized {@link InertiaRequestInfo}.
|
|
297
|
+
*
|
|
298
|
+
* @param input Headers, HTTP method, and request URL. Method is uppercased in
|
|
299
|
+
* the returned object; the URL is passed through unchanged.
|
|
300
|
+
*/
|
|
301
|
+
declare function parseInertiaRequest(input: {
|
|
302
|
+
headers: HeaderRecord;
|
|
303
|
+
method: string;
|
|
304
|
+
url: string;
|
|
305
|
+
}): InertiaRequestInfo;
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/core/html.d.ts
|
|
308
|
+
/**
|
|
309
|
+
* Encode an Inertia page object for embedding inside a
|
|
310
|
+
* `<script type="application/json" data-page="...">` tag — the Inertia v3
|
|
311
|
+
* initial-page transport that the client reads via `getInitialPageFromDOM`.
|
|
312
|
+
*
|
|
313
|
+
* Every `<` is replaced with its JSON unicode escape so the payload cannot
|
|
314
|
+
* terminate the surrounding `</script>` element or open an HTML comment. The
|
|
315
|
+
* escape is transparent — JSON.parse decodes it back to `<`.
|
|
316
|
+
*
|
|
317
|
+
* @param page Resolved Inertia page object.
|
|
318
|
+
*/
|
|
319
|
+
declare function encodePageScript(page: InertiaPage): string;
|
|
320
|
+
/**
|
|
321
|
+
* Inputs to {@link renderDefaultHtml}.
|
|
322
|
+
*/
|
|
323
|
+
interface DefaultRootViewInput {
|
|
324
|
+
page: InertiaPage;
|
|
325
|
+
/** Optional `<title>` for the document. */
|
|
326
|
+
title?: string;
|
|
327
|
+
/** Optional <head> content (meta tags, links, etc.). */
|
|
328
|
+
head?: string;
|
|
329
|
+
/** ID of the SPA root element. Defaults to `app`. */
|
|
330
|
+
rootId?: string;
|
|
331
|
+
/** Path to the client entry script, e.g. `/assets/app.js`. */
|
|
332
|
+
scriptSrc?: string;
|
|
333
|
+
/**
|
|
334
|
+
* Pre-rendered SSR HTML for the root element's *inner* content. When set,
|
|
335
|
+
* the inner HTML of the root div is replaced with this string so the
|
|
336
|
+
* client hydrates over server-rendered markup.
|
|
337
|
+
*/
|
|
338
|
+
ssrBody?: string;
|
|
339
|
+
/**
|
|
340
|
+
* Pre-rendered SSR HTML representing the entire root element. When set,
|
|
341
|
+
* `ssrBody`, `rootId`, and the page `<script>` tag are ignored — the
|
|
342
|
+
* provided string is inserted into `<body>` as-is. Use this when your
|
|
343
|
+
* SSR renderer already returns the full root element + page script (the
|
|
344
|
+
* Inertia v3 SSR servers do).
|
|
345
|
+
*/
|
|
346
|
+
ssrFull?: string;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Minimal default HTML shell for use when no custom root view is provided.
|
|
350
|
+
* Real apps should plug in a template engine (pug, ejs, react-dom/server,
|
|
351
|
+
* etc.) and embed `encodePageScript(page)` themselves.
|
|
352
|
+
*
|
|
353
|
+
* The initial page object is emitted as a
|
|
354
|
+
* `<script type="application/json" data-page="...">` tag, the Inertia v3
|
|
355
|
+
* transport that the client reads on boot.
|
|
356
|
+
*
|
|
357
|
+
* @param input Page object plus optional title/head/rootId/scriptSrc/SSR markup
|
|
358
|
+
* — see {@link DefaultRootViewInput}.
|
|
359
|
+
*/
|
|
360
|
+
declare function renderDefaultHtml(input: DefaultRootViewInput): string;
|
|
361
|
+
/**
|
|
362
|
+
* Inputs to {@link renderErrorPage}.
|
|
363
|
+
*/
|
|
364
|
+
interface ErrorPageInput {
|
|
365
|
+
/** HTTP status code to surface to the user. */
|
|
366
|
+
status: number;
|
|
367
|
+
/** Optional message; falls back to a default for the status, then a generic line. */
|
|
368
|
+
message?: string;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Render a minimal, SPA-less standalone HTML error page. Used as the hard
|
|
372
|
+
* fallback when no client `Error` component can be resolved (e.g. a plain
|
|
373
|
+
* browser load, or an SSR/render failure on the Inertia path), so a user
|
|
374
|
+
* never receives a raw JSON error or a blank page.
|
|
375
|
+
*
|
|
376
|
+
* @param input HTTP status plus an optional override message — see {@link ErrorPageInput}.
|
|
377
|
+
*/
|
|
378
|
+
declare function renderErrorPage(input: ErrorPageInput): string;
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/core/page.d.ts
|
|
381
|
+
/**
|
|
382
|
+
* Inputs to {@link createPage} — the fields of an {@link InertiaPage} plus
|
|
383
|
+
* optional history flags and the v3 prop metadata produced by the resolver.
|
|
384
|
+
*/
|
|
385
|
+
interface CreatePageInput<TProps extends PageProps = PageProps> {
|
|
386
|
+
component: string;
|
|
387
|
+
props: TProps;
|
|
388
|
+
url: string;
|
|
389
|
+
version: string | null;
|
|
390
|
+
clearHistory?: boolean;
|
|
391
|
+
encryptHistory?: boolean;
|
|
392
|
+
preserveFragment?: boolean;
|
|
393
|
+
metadata?: PropsMetadata;
|
|
394
|
+
flash?: unknown;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Build a normalized Inertia v3 page object. `clearHistory`, `encryptHistory`
|
|
398
|
+
* and `preserveFragment` default to `false` and are always present. Each
|
|
399
|
+
* `metadata` key is copied onto the page only when non-empty so the JSON over
|
|
400
|
+
* the wire stays compact. `flash` is emitted as a top-level key only when it
|
|
401
|
+
* carries data (non-nullish, and a non-empty object when object-valued) —
|
|
402
|
+
* mirroring inertia-laravel's `$flash ? ['flash' => $flash] : []`.
|
|
403
|
+
*
|
|
404
|
+
* @param input Required page fields plus the optional v3 extras.
|
|
405
|
+
*/
|
|
406
|
+
declare function createPage<TProps extends PageProps>(input: CreatePageInput<TProps>): InertiaPage<TProps>;
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/core/partial-filter.d.ts
|
|
409
|
+
/**
|
|
410
|
+
* `true` when `path` equals `parent` or lies in its dot-notation subtree.
|
|
411
|
+
*
|
|
412
|
+
* @param path Dot-notation prop path to test.
|
|
413
|
+
* @param parent Dot-notation path that may contain `path`.
|
|
414
|
+
*/
|
|
415
|
+
declare function pathIsSameOrDescendant(path: string, parent: string): boolean;
|
|
416
|
+
/**
|
|
417
|
+
* `true` when `path` matches an `only` entry or is a descendant of one.
|
|
418
|
+
*
|
|
419
|
+
* @param path Dot-notation prop path to test.
|
|
420
|
+
* @param only Requested partial-reload `only` paths.
|
|
421
|
+
*/
|
|
422
|
+
declare function matchesOnly(path: string, only: string[]): boolean;
|
|
423
|
+
/**
|
|
424
|
+
* `true` when `path` is a strict ancestor of an `only` entry.
|
|
425
|
+
*
|
|
426
|
+
* @param path Dot-notation prop path to test.
|
|
427
|
+
* @param only Requested partial-reload `only` paths.
|
|
428
|
+
*/
|
|
429
|
+
declare function leadsToOnly(path: string, only: string[]): boolean;
|
|
430
|
+
/**
|
|
431
|
+
* `true` when `path` equals an `except` entry, is a descendant of one, or is
|
|
432
|
+
* an ancestor of one. Matching ancestors mirrors the reference Node server,
|
|
433
|
+
* whose flat filter drops a top-level key whenever any `except` entry lives
|
|
434
|
+
* under it; inertia-laravel keeps the ancestor and drops only the child.
|
|
435
|
+
*
|
|
436
|
+
* @param path Dot-notation prop path to test.
|
|
437
|
+
* @param except Requested partial-reload `except` paths.
|
|
438
|
+
*/
|
|
439
|
+
declare function matchesExcept(path: string, except: string[]): boolean;
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/core/prop-descriptor.d.ts
|
|
442
|
+
/**
|
|
443
|
+
* The constructor a {@link PropDescriptor} was created by.
|
|
444
|
+
*/
|
|
445
|
+
type PropKind = 'optional' | 'defer' | 'always' | 'merge' | 'once' | 'scroll';
|
|
446
|
+
/**
|
|
447
|
+
* A prop's raw source: a plain value or a (possibly async) producer.
|
|
448
|
+
*/
|
|
449
|
+
type PropSource<T> = T | (() => T | Promise<T>);
|
|
450
|
+
/**
|
|
451
|
+
* Options accepted by the `scroll()` prop constructor.
|
|
452
|
+
*/
|
|
453
|
+
interface ScrollOptions<T> {
|
|
454
|
+
/** Key inside the resolved value that holds the scrolled items. Defaults to `'data'`. */
|
|
455
|
+
wrapper?: string;
|
|
456
|
+
/** Pagination metadata, or a function deriving it from the resolved value. */
|
|
457
|
+
metadata: ScrollMetadata | ((resolved: T) => ScrollMetadata);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* A prop wrapped with resolution and merge behaviour, ported from
|
|
461
|
+
* inertia-laravel's prop classes and their `MergesProps`, `DefersProps`
|
|
462
|
+
* and `ResolvesOnce` traits. The descriptor holds the wrapped value by
|
|
463
|
+
* reference and never mutates it.
|
|
464
|
+
*/
|
|
465
|
+
declare class PropDescriptor<T = unknown> {
|
|
466
|
+
readonly kind: PropKind;
|
|
467
|
+
readonly source: PropSource<T>;
|
|
468
|
+
ignoreFirstLoad: boolean;
|
|
469
|
+
defers: boolean;
|
|
470
|
+
group: string;
|
|
471
|
+
merges: boolean;
|
|
472
|
+
deep: boolean;
|
|
473
|
+
appends: boolean;
|
|
474
|
+
appendPaths: string[];
|
|
475
|
+
prependPaths: string[];
|
|
476
|
+
matchOnPaths: string[];
|
|
477
|
+
resolvesOnce: boolean;
|
|
478
|
+
onceKey: string | null;
|
|
479
|
+
ttlSeconds: number | null;
|
|
480
|
+
expiresAtDate: Date | null;
|
|
481
|
+
isFresh: boolean;
|
|
482
|
+
rescues: boolean;
|
|
483
|
+
isAlways: boolean;
|
|
484
|
+
isScroll: boolean;
|
|
485
|
+
wrapper: string;
|
|
486
|
+
scrollMetadata: ScrollMetadata | ((resolved: T) => ScrollMetadata) | null;
|
|
487
|
+
/**
|
|
488
|
+
* Create a descriptor around a prop source.
|
|
489
|
+
*
|
|
490
|
+
* @param kind The constructor that produced this descriptor.
|
|
491
|
+
* @param source The plain value or producer function being wrapped.
|
|
492
|
+
*/
|
|
493
|
+
constructor(kind: PropKind, source: PropSource<T>);
|
|
494
|
+
/**
|
|
495
|
+
* `true` when the prop appends at its root: the append flag is set and no
|
|
496
|
+
* append/prepend paths were recorded.
|
|
497
|
+
*/
|
|
498
|
+
get appendsAtRoot(): boolean;
|
|
499
|
+
/**
|
|
500
|
+
* `true` when the prop prepends at its root: the append flag is cleared and
|
|
501
|
+
* no append/prepend paths were recorded.
|
|
502
|
+
*/
|
|
503
|
+
get prependsAtRoot(): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Mark the prop for a shallow client-side merge.
|
|
506
|
+
*/
|
|
507
|
+
merge(): this;
|
|
508
|
+
/**
|
|
509
|
+
* Mark the prop for a deep client-side merge.
|
|
510
|
+
*/
|
|
511
|
+
deepMerge(): this;
|
|
512
|
+
/**
|
|
513
|
+
* Configure appending. A boolean sets the root append flag; a string
|
|
514
|
+
* records an append path; a list records each path; a record maps each
|
|
515
|
+
* path to its match-on field.
|
|
516
|
+
*
|
|
517
|
+
* @param path Root flag, path, list of paths, or path-to-matchOn record.
|
|
518
|
+
* @param matchOn Field to dedupe on, recorded as `path.matchOn` when `path` is a string.
|
|
519
|
+
*/
|
|
520
|
+
append(path?: boolean | string | string[] | Record<string, string>, matchOn?: string): this;
|
|
521
|
+
/**
|
|
522
|
+
* Configure prepending. A boolean clears (or sets) the root append flag; a
|
|
523
|
+
* string records a prepend path; a list records each path; a record maps
|
|
524
|
+
* each path to its match-on field.
|
|
525
|
+
*
|
|
526
|
+
* @param path Root flag, path, list of paths, or path-to-matchOn record.
|
|
527
|
+
* @param matchOn Field to dedupe on, recorded as `path.matchOn` when `path` is a string.
|
|
528
|
+
*/
|
|
529
|
+
prepend(path?: boolean | string | string[] | Record<string, string>, matchOn?: string): this;
|
|
530
|
+
/**
|
|
531
|
+
* Replace the match-on paths the client dedupes merged items by.
|
|
532
|
+
*
|
|
533
|
+
* @param path A single path or a list of paths.
|
|
534
|
+
*/
|
|
535
|
+
matchOn(path: string | string[]): this;
|
|
536
|
+
/**
|
|
537
|
+
* Defer the prop to a follow-up request.
|
|
538
|
+
*
|
|
539
|
+
* @param group Load group; props sharing a group are fetched together. Defaults to `'default'`.
|
|
540
|
+
*/
|
|
541
|
+
defer(group?: string): this;
|
|
542
|
+
/**
|
|
543
|
+
* Toggle once-resolution, optionally setting its key and expiry.
|
|
544
|
+
*
|
|
545
|
+
* @param value Whether the prop resolves once. Defaults to `true`.
|
|
546
|
+
* @param as Custom once key.
|
|
547
|
+
* @param until TTL in seconds, or an absolute expiry date.
|
|
548
|
+
*/
|
|
549
|
+
once(value?: boolean, as?: string, until?: number | Date): this;
|
|
550
|
+
/**
|
|
551
|
+
* Set the key the client caches a once-prop under.
|
|
552
|
+
*
|
|
553
|
+
* @param key The once key.
|
|
554
|
+
*/
|
|
555
|
+
as(key: string): this;
|
|
556
|
+
/**
|
|
557
|
+
* Set the once-prop's expiry, replacing any expiry set by an earlier call.
|
|
558
|
+
*
|
|
559
|
+
* @param delay TTL in seconds, or an absolute expiry date.
|
|
560
|
+
*/
|
|
561
|
+
until(delay: number | Date): this;
|
|
562
|
+
/**
|
|
563
|
+
* Force a once-prop to be re-resolved.
|
|
564
|
+
*
|
|
565
|
+
* @param value Whether to refresh. Defaults to `true`.
|
|
566
|
+
*/
|
|
567
|
+
fresh(value?: boolean): this;
|
|
568
|
+
/**
|
|
569
|
+
* Opt into rescuing errors thrown while resolving the prop.
|
|
570
|
+
*
|
|
571
|
+
* @param value Whether to rescue. Defaults to `true`.
|
|
572
|
+
*/
|
|
573
|
+
rescue(value?: boolean): this;
|
|
574
|
+
/**
|
|
575
|
+
* The once-prop's expiry as a millisecond epoch, or `null` without a TTL or date.
|
|
576
|
+
*
|
|
577
|
+
* @param now Current time in milliseconds. Defaults to `Date.now()`.
|
|
578
|
+
*/
|
|
579
|
+
expiresAt(now?: number): number | null;
|
|
580
|
+
/**
|
|
581
|
+
* Resolve the source: call it when it is a function, then await the result.
|
|
582
|
+
*/
|
|
583
|
+
resolveSource(): Promise<T>;
|
|
584
|
+
/**
|
|
585
|
+
* Scroll metadata for a resolved value: the configured object, or the
|
|
586
|
+
* configured function applied to `resolved`.
|
|
587
|
+
*
|
|
588
|
+
* @param resolved The resolved prop value.
|
|
589
|
+
*/
|
|
590
|
+
metadataFor(resolved: T): ScrollMetadata;
|
|
591
|
+
/**
|
|
592
|
+
* `true` when no append or prepend paths were recorded.
|
|
593
|
+
*/
|
|
594
|
+
private mergesAtRoot;
|
|
595
|
+
/**
|
|
596
|
+
* Record `path.matchOn` as a match-on path when `matchOn` is given.
|
|
597
|
+
*
|
|
598
|
+
* @param path The append/prepend path.
|
|
599
|
+
* @param matchOn Field to dedupe on.
|
|
600
|
+
*/
|
|
601
|
+
private recordMatchOn;
|
|
602
|
+
}
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/core/props.d.ts
|
|
605
|
+
/**
|
|
606
|
+
* Argument accepted by `append()` / `prepend()`: a root flag, a path, a list
|
|
607
|
+
* of paths, or a path-to-matchOn record.
|
|
608
|
+
*/
|
|
609
|
+
type MergePath = boolean | string | string[] | Record<string, string>;
|
|
610
|
+
/**
|
|
611
|
+
* Prop omitted from the first load and resolved only when requested.
|
|
612
|
+
*/
|
|
613
|
+
interface OptionalProp<T> {
|
|
614
|
+
once: (value?: boolean, as?: string, until?: number | Date) => OptionalProp<T>;
|
|
615
|
+
as: (key: string) => OptionalProp<T>;
|
|
616
|
+
until: (delay: number | Date) => OptionalProp<T>;
|
|
617
|
+
fresh: (value?: boolean) => OptionalProp<T>;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Prop resolved in a follow-up request after the first load.
|
|
621
|
+
*/
|
|
622
|
+
interface DeferProp<T> {
|
|
623
|
+
merge: () => DeferProp<T>;
|
|
624
|
+
deepMerge: () => DeferProp<T>;
|
|
625
|
+
append: (path?: MergePath, matchOn?: string) => DeferProp<T>;
|
|
626
|
+
prepend: (path?: MergePath, matchOn?: string) => DeferProp<T>;
|
|
627
|
+
matchOn: (path: string | string[]) => DeferProp<T>;
|
|
628
|
+
once: (value?: boolean, as?: string, until?: number | Date) => DeferProp<T>;
|
|
629
|
+
as: (key: string) => DeferProp<T>;
|
|
630
|
+
until: (delay: number | Date) => DeferProp<T>;
|
|
631
|
+
fresh: (value?: boolean) => DeferProp<T>;
|
|
632
|
+
rescue: (value?: boolean) => DeferProp<T>;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Prop the client merges into its existing value.
|
|
636
|
+
*/
|
|
637
|
+
interface MergeProp<T> {
|
|
638
|
+
deepMerge: () => MergeProp<T>;
|
|
639
|
+
append: (path?: MergePath, matchOn?: string) => MergeProp<T>;
|
|
640
|
+
prepend: (path?: MergePath, matchOn?: string) => MergeProp<T>;
|
|
641
|
+
matchOn: (path: string | string[]) => MergeProp<T>;
|
|
642
|
+
once: (value?: boolean, as?: string, until?: number | Date) => MergeProp<T>;
|
|
643
|
+
as: (key: string) => MergeProp<T>;
|
|
644
|
+
until: (delay: number | Date) => MergeProp<T>;
|
|
645
|
+
fresh: (value?: boolean) => MergeProp<T>;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Prop included on every response, regardless of partial filtering. It has
|
|
649
|
+
* no chain methods.
|
|
650
|
+
*/
|
|
651
|
+
type AlwaysProp<T> = Pick<PropDescriptor<T>, never>;
|
|
652
|
+
/**
|
|
653
|
+
* Prop the client resolves once and caches across visits.
|
|
654
|
+
*/
|
|
655
|
+
interface OnceProp<T> {
|
|
656
|
+
as: (key: string) => OnceProp<T>;
|
|
657
|
+
until: (delay: number | Date) => OnceProp<T>;
|
|
658
|
+
fresh: (value?: boolean) => OnceProp<T>;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Infinite-scroll prop carrying pagination metadata.
|
|
662
|
+
*/
|
|
663
|
+
interface ScrollProp<T> {
|
|
664
|
+
defer: (group?: string) => ScrollProp<T>;
|
|
665
|
+
matchOn: (path: string | string[]) => ScrollProp<T>;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* An optional prop: omitted from the first load, resolved when requested.
|
|
669
|
+
*
|
|
670
|
+
* @param fn Producer called (and awaited) when the prop is requested.
|
|
671
|
+
*/
|
|
672
|
+
declare function optional<T>(fn: () => T | Promise<T>): OptionalProp<T>;
|
|
673
|
+
/**
|
|
674
|
+
* A deferred prop: omitted from the first load and fetched by the client in
|
|
675
|
+
* a follow-up request with the rest of its group.
|
|
676
|
+
*
|
|
677
|
+
* @param fn Producer called (and awaited) on the follow-up request.
|
|
678
|
+
* @param group Load group; props sharing a group are fetched together.
|
|
679
|
+
*/
|
|
680
|
+
declare function defer<T>(fn: () => T | Promise<T>, group?: string): DeferProp<T>;
|
|
681
|
+
/**
|
|
682
|
+
* An always prop: included on every response, even partial reloads that do
|
|
683
|
+
* not request it.
|
|
684
|
+
*
|
|
685
|
+
* @param value Plain value or producer.
|
|
686
|
+
*/
|
|
687
|
+
declare function always<T>(value: PropSource<T>): AlwaysProp<T>;
|
|
688
|
+
/**
|
|
689
|
+
* A merge prop: the client appends it to its existing value at the root.
|
|
690
|
+
* Throws a `TypeError` when given a second argument (the 2.x `matchOn`
|
|
691
|
+
* form); chain `.matchOn()` instead.
|
|
692
|
+
*
|
|
693
|
+
* @param value Plain value or producer.
|
|
694
|
+
* @param extra Rejected; present only to catch the 2.x call form.
|
|
695
|
+
*/
|
|
696
|
+
declare function merge<T>(value: PropSource<T>, ...extra: never[]): MergeProp<T>;
|
|
697
|
+
/**
|
|
698
|
+
* A deep-merge prop: the client recursively merges it into its existing value.
|
|
699
|
+
* Throws a `TypeError` when given a second argument (the 2.x `matchOn`
|
|
700
|
+
* form); chain `.matchOn()` instead.
|
|
701
|
+
*
|
|
702
|
+
* @param value Plain value or producer.
|
|
703
|
+
* @param extra Rejected; present only to catch the 2.x call form.
|
|
704
|
+
*/
|
|
705
|
+
declare function deepMerge<T>(value: PropSource<T>, ...extra: never[]): MergeProp<T>;
|
|
706
|
+
/**
|
|
707
|
+
* A once prop: resolved once and cached by the client across visits.
|
|
708
|
+
*
|
|
709
|
+
* @param fn Producer called (and awaited) when the client lacks the value.
|
|
710
|
+
*/
|
|
711
|
+
declare function once<T>(fn: () => T | Promise<T>): OnceProp<T>;
|
|
712
|
+
/**
|
|
713
|
+
* An infinite-scroll prop: merged at its wrapper key and carrying
|
|
714
|
+
* pagination metadata.
|
|
715
|
+
*
|
|
716
|
+
* @param fn Producer called (and awaited) for each page.
|
|
717
|
+
* @param options Wrapper key (default `'data'`) and pagination metadata.
|
|
718
|
+
*/
|
|
719
|
+
declare function scroll<T>(fn: () => T | Promise<T>, options: ScrollOptions<T>): ScrollProp<T>;
|
|
720
|
+
/**
|
|
721
|
+
* Type guard: `true` when `value` is a {@link PropDescriptor}.
|
|
722
|
+
*
|
|
723
|
+
* @param value Value to test.
|
|
724
|
+
*/
|
|
725
|
+
declare function isPropDescriptor(value: unknown): value is PropDescriptor;
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/core/props-resolver.d.ts
|
|
728
|
+
/**
|
|
729
|
+
* Input to {@link resolveProps}.
|
|
730
|
+
*/
|
|
731
|
+
interface ResolvePropsInput {
|
|
732
|
+
/** Page props for the component being rendered. */
|
|
733
|
+
props: PageProps;
|
|
734
|
+
/** Already-evaluated shared props; page props win on key collision. */
|
|
735
|
+
shared: PageProps;
|
|
736
|
+
/** Component being rendered; a partial reload only applies when it matches. */
|
|
737
|
+
component: string;
|
|
738
|
+
/** Normalized Inertia request state. */
|
|
739
|
+
request: InertiaRequestInfo;
|
|
740
|
+
/** Hook called when a rescued prop throws. */
|
|
741
|
+
onRescue?: RescueHandler;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Output of {@link resolveProps}.
|
|
745
|
+
*/
|
|
746
|
+
interface ResolvePropsResult {
|
|
747
|
+
/** Fully resolved props tree. */
|
|
748
|
+
props: PageProps;
|
|
749
|
+
/** Page-level metadata; only non-empty keys are present. */
|
|
750
|
+
metadata: PropsMetadata;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Resolves shared and page props for one response, applying partial-reload
|
|
754
|
+
* filtering and initial-load exclusion and collecting page metadata. Port of
|
|
755
|
+
* inertia-laravel's `PropsResolver`. Use one instance per response: the
|
|
756
|
+
* instance accumulates metadata, so {@link PropsResolver.resolve} throws when
|
|
757
|
+
* called a second time. The resolver only reads descriptors, never writes
|
|
758
|
+
* them. Metadata maps keyed by user input (`deferredProps`, `scrollProps`,
|
|
759
|
+
* `onceProps`) have a null prototype, so any key, `__proto__` included, is
|
|
760
|
+
* stored as an own property.
|
|
761
|
+
*/
|
|
762
|
+
declare class PropsResolver {
|
|
763
|
+
private readonly request;
|
|
764
|
+
private readonly component;
|
|
765
|
+
private readonly onRescue;
|
|
766
|
+
private readonly isPartial;
|
|
767
|
+
private readonly isInertia;
|
|
768
|
+
private readonly only;
|
|
769
|
+
private readonly except;
|
|
770
|
+
private readonly sharedPropKeys;
|
|
771
|
+
private readonly mergeProps;
|
|
772
|
+
private readonly prependProps;
|
|
773
|
+
private readonly deepMergeProps;
|
|
774
|
+
private readonly matchPropsOn;
|
|
775
|
+
private readonly deferredProps;
|
|
776
|
+
private readonly rescuedProps;
|
|
777
|
+
private readonly scrollProps;
|
|
778
|
+
private readonly onceProps;
|
|
779
|
+
private used;
|
|
780
|
+
/**
|
|
781
|
+
* Create a resolver for one request and component.
|
|
782
|
+
*
|
|
783
|
+
* @param request Normalized Inertia request state.
|
|
784
|
+
* @param component Component being rendered.
|
|
785
|
+
* @param onRescue Hook called when a rescued prop throws.
|
|
786
|
+
*/
|
|
787
|
+
constructor(request: InertiaRequestInfo, component: string, onRescue?: RescueHandler);
|
|
788
|
+
/**
|
|
789
|
+
* Resolve the given shared and page props, collecting their metadata.
|
|
790
|
+
*
|
|
791
|
+
* @param shared Already-evaluated shared props.
|
|
792
|
+
* @param props Page props; these win over shared props on collision.
|
|
793
|
+
*/
|
|
794
|
+
resolve(shared: PageProps, props: PageProps): Promise<ResolvePropsResult>;
|
|
795
|
+
/**
|
|
796
|
+
* Record the top-level keys of shared props (the segment before the first
|
|
797
|
+
* `.` for dot-notation keys), deduplicated in first-seen order.
|
|
798
|
+
*
|
|
799
|
+
* @param shared Already-evaluated shared props.
|
|
800
|
+
*/
|
|
801
|
+
private resolveSharedProps;
|
|
802
|
+
/**
|
|
803
|
+
* Build the non-empty metadata entries for the page response, in protocol order.
|
|
804
|
+
*/
|
|
805
|
+
private buildMetadata;
|
|
806
|
+
/**
|
|
807
|
+
* Recursively resolve a props node, collecting metadata along the way.
|
|
808
|
+
* Every included entry that needs resolving is started in insertion order
|
|
809
|
+
* before any is awaited, so siblings resolve concurrently; each entry is
|
|
810
|
+
* then settled in insertion order (rescue, one-level unwrap, metadata,
|
|
811
|
+
* recursion), keeping output key order and metadata order deterministic.
|
|
812
|
+
* Plain values are copied synchronously, so a node without closures or
|
|
813
|
+
* descriptors comes back without a promise. Arrays come back as arrays
|
|
814
|
+
* with excluded entries dropped, so later index-based `except`/`reset`
|
|
815
|
+
* paths shift down; objects come back as fresh plain objects. When the
|
|
816
|
+
* original prop was not itself a plain object or array (e.g. a closure
|
|
817
|
+
* that returned one), its children bypass partial filtering.
|
|
818
|
+
*
|
|
819
|
+
* @param node Plain object or array to walk.
|
|
820
|
+
* @param prefix Dot path of `node`, or `''` at the root.
|
|
821
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
822
|
+
*/
|
|
823
|
+
private walk;
|
|
824
|
+
/**
|
|
825
|
+
* Continue a walk asynchronously from the first entry whose outcome is pending.
|
|
826
|
+
*
|
|
827
|
+
* @param entries Started entries of the node.
|
|
828
|
+
* @param index Index of the pending entry.
|
|
829
|
+
* @param pending Outcome of the entry at `index`.
|
|
830
|
+
* @param result Node being built; written in place.
|
|
831
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
832
|
+
*/
|
|
833
|
+
private finishWalk;
|
|
834
|
+
/**
|
|
835
|
+
* Run the synchronous pre-resolve checks (partial filter, initial-load
|
|
836
|
+
* exclusion) over a node's entries in insertion order and start resolving
|
|
837
|
+
* every included entry that needs it.
|
|
838
|
+
*
|
|
839
|
+
* @param node Plain object or array to walk.
|
|
840
|
+
* @param prefix Dot path of `node`, or `''` at the root.
|
|
841
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
842
|
+
*/
|
|
843
|
+
private startEntries;
|
|
844
|
+
/**
|
|
845
|
+
* Classify one included entry: excluded from the initial load, pending
|
|
846
|
+
* resolution (started now), or a plain value copied as is.
|
|
847
|
+
*
|
|
848
|
+
* @param key Key of the entry in its parent node.
|
|
849
|
+
* @param path Dot path of the entry.
|
|
850
|
+
* @param prop The prop as found in its parent node.
|
|
851
|
+
*/
|
|
852
|
+
private startEntry;
|
|
853
|
+
/**
|
|
854
|
+
* Finish one started entry in insertion order. Returns the value to write,
|
|
855
|
+
* {@link EXCLUDED}, or a promise of either when the entry needs awaiting.
|
|
856
|
+
*
|
|
857
|
+
* @param entry The started entry.
|
|
858
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
859
|
+
*/
|
|
860
|
+
private settleEntry;
|
|
861
|
+
/**
|
|
862
|
+
* Await a started resolution, then apply rescue, the one-level descriptor
|
|
863
|
+
* unwrap (with its own initial-load exclusion) and inclusion.
|
|
864
|
+
*
|
|
865
|
+
* @param entry The started entry.
|
|
866
|
+
* @param pending The entry's resolution.
|
|
867
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
868
|
+
*/
|
|
869
|
+
private settleResolved;
|
|
870
|
+
/**
|
|
871
|
+
* Include a resolved prop: check scroll shape, collect metadata, and walk
|
|
872
|
+
* into plain objects and arrays.
|
|
873
|
+
*
|
|
874
|
+
* @param prop The prop that produced `value`.
|
|
875
|
+
* @param value The prop's resolved value.
|
|
876
|
+
* @param path Dot path of the prop.
|
|
877
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
878
|
+
*/
|
|
879
|
+
private include;
|
|
880
|
+
/**
|
|
881
|
+
* Determine if a prop belongs in the response: always on a full visit;
|
|
882
|
+
* on a partial reload, when it bypasses filtering or its path matches the request.
|
|
883
|
+
*
|
|
884
|
+
* @param prop The prop being considered.
|
|
885
|
+
* @param path Dot path of the prop.
|
|
886
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
887
|
+
*/
|
|
888
|
+
private shouldIncludeInPartialResponse;
|
|
889
|
+
/**
|
|
890
|
+
* Determine if a prop is resolved independently of partial filters:
|
|
891
|
+
* always props, and children of already-resolved values.
|
|
892
|
+
*
|
|
893
|
+
* @param prop The prop being considered.
|
|
894
|
+
* @param parentWasResolved Whether an ancestor was produced by resolving a closure or descriptor.
|
|
895
|
+
*/
|
|
896
|
+
private bypassesPartialFiltering;
|
|
897
|
+
/**
|
|
898
|
+
* Determine if the path matches the partial request using bidirectional
|
|
899
|
+
* prefix matching on both the only list and the except list.
|
|
900
|
+
*
|
|
901
|
+
* @param path Dot path of the prop.
|
|
902
|
+
*/
|
|
903
|
+
private pathMatchesPartialRequest;
|
|
904
|
+
/**
|
|
905
|
+
* Determine if a prop is excluded from the initial page response: an
|
|
906
|
+
* optional or deferred descriptor, or a once-prop the client already holds.
|
|
907
|
+
*
|
|
908
|
+
* @param prop The prop being considered.
|
|
909
|
+
* @param path Dot path of the prop.
|
|
910
|
+
*/
|
|
911
|
+
private isExcludedFromInitialResponse;
|
|
912
|
+
/**
|
|
913
|
+
* Collect the metadata of a prop excluded from the initial response
|
|
914
|
+
* according to why it was excluded.
|
|
915
|
+
*
|
|
916
|
+
* @param prop The descriptor being excluded.
|
|
917
|
+
* @param path Dot path of the prop.
|
|
918
|
+
*/
|
|
919
|
+
private collectExclusionMetadata;
|
|
920
|
+
/**
|
|
921
|
+
* Collect the deferred, merge and once metadata of an excluded
|
|
922
|
+
* first-load-ignored prop (optional, defer).
|
|
923
|
+
*
|
|
924
|
+
* @param prop The descriptor being excluded.
|
|
925
|
+
* @param path Dot path of the prop.
|
|
926
|
+
*/
|
|
927
|
+
private collectIgnoredPropMetadata;
|
|
928
|
+
/**
|
|
929
|
+
* Collect the deferred-group and merge metadata of an excluded deferred prop.
|
|
930
|
+
*
|
|
931
|
+
* @param prop The descriptor being excluded.
|
|
932
|
+
* @param path Dot path of the prop.
|
|
933
|
+
*/
|
|
934
|
+
private collectDeferredExclusionMetadata;
|
|
935
|
+
/**
|
|
936
|
+
* Determine if a once-prop has already been loaded by the client: it
|
|
937
|
+
* resolves once, is not forced fresh, and its key (or path) is listed in
|
|
938
|
+
* the client's except-once header.
|
|
939
|
+
*
|
|
940
|
+
* @param prop The descriptor being considered.
|
|
941
|
+
* @param path Dot path of the prop.
|
|
942
|
+
*/
|
|
943
|
+
private wasAlreadyLoadedByClient;
|
|
944
|
+
/**
|
|
945
|
+
* Resolve a single prop value: a descriptor resolves its source, a bare
|
|
946
|
+
* function is called, and the result is awaited; anything else passes
|
|
947
|
+
* through. An error thrown by a rescuable descriptor comes back wrapped in
|
|
948
|
+
* {@link Rescued}; any other error rejects.
|
|
949
|
+
*
|
|
950
|
+
* @param prop The prop to resolve.
|
|
951
|
+
*/
|
|
952
|
+
private resolveValue;
|
|
953
|
+
/**
|
|
954
|
+
* Throw when a scroll prop did not resolve to a plain object holding its
|
|
955
|
+
* wrapper key as an own property.
|
|
956
|
+
*
|
|
957
|
+
* @param prop The prop being included.
|
|
958
|
+
* @param path Dot path of the prop.
|
|
959
|
+
* @param resolved The prop's resolved value.
|
|
960
|
+
*/
|
|
961
|
+
private assertScrollShape;
|
|
962
|
+
/**
|
|
963
|
+
* Record a rescued prop: report the error, add its path to `rescuedProps`
|
|
964
|
+
* and omit it from the response.
|
|
965
|
+
*
|
|
966
|
+
* @param error The thrown value.
|
|
967
|
+
* @param path Dot path of the prop.
|
|
968
|
+
*/
|
|
969
|
+
private rescue;
|
|
970
|
+
/**
|
|
971
|
+
* Call the rescue hook with the failure contained: a synchronous throw or
|
|
972
|
+
* a rejected returned thenable is logged through the default reporter and
|
|
973
|
+
* never propagates or surfaces as an unhandled rejection.
|
|
974
|
+
*
|
|
975
|
+
* @param error The thrown value.
|
|
976
|
+
* @param path Dot path of the prop.
|
|
977
|
+
*/
|
|
978
|
+
private reportRescue;
|
|
979
|
+
/**
|
|
980
|
+
* Determine if the value is a prop type that needs further filtering or
|
|
981
|
+
* metadata collection.
|
|
982
|
+
*
|
|
983
|
+
* @param value The resolved value.
|
|
984
|
+
*/
|
|
985
|
+
private isPropType;
|
|
986
|
+
/**
|
|
987
|
+
* Collect metadata for a prop that will be included in the response.
|
|
988
|
+
*
|
|
989
|
+
* @param prop The prop being included.
|
|
990
|
+
* @param path Dot path of the prop.
|
|
991
|
+
* @param resolved The prop's resolved value.
|
|
992
|
+
*/
|
|
993
|
+
private collectMetadata;
|
|
994
|
+
/**
|
|
995
|
+
* Collect the deferred prop under its group.
|
|
996
|
+
*
|
|
997
|
+
* @param path Dot path of the prop.
|
|
998
|
+
* @param prop The deferred descriptor.
|
|
999
|
+
*/
|
|
1000
|
+
private collectDeferredPropMetadata;
|
|
1001
|
+
/**
|
|
1002
|
+
* Collect the merge strategy for a mergeable prop, unless the client asked
|
|
1003
|
+
* to reset it or a partial request filters it out.
|
|
1004
|
+
*
|
|
1005
|
+
* @param path Dot path of the prop.
|
|
1006
|
+
* @param prop The mergeable descriptor.
|
|
1007
|
+
* @param excluded Whether the prop is being excluded from this response rather than resolved.
|
|
1008
|
+
*/
|
|
1009
|
+
private collectMergeableMetadata;
|
|
1010
|
+
/**
|
|
1011
|
+
* The merge layout of a descriptor for this request, read without writing
|
|
1012
|
+
* to the descriptor. A scroll descriptor derives its layout per request:
|
|
1013
|
+
* a root append while it is excluded as deferred, otherwise its wrapper key
|
|
1014
|
+
* appended or prepended according to the client's merge intent (the
|
|
1015
|
+
* read-only equivalent of `ScrollProp::configureMergeIntent`).
|
|
1016
|
+
*
|
|
1017
|
+
* @param prop The mergeable descriptor.
|
|
1018
|
+
* @param excluded Whether the prop is being excluded from this response rather than resolved.
|
|
1019
|
+
*/
|
|
1020
|
+
private mergeLayoutFor;
|
|
1021
|
+
/**
|
|
1022
|
+
* Determine if the path should contribute metadata during a partial request.
|
|
1023
|
+
*
|
|
1024
|
+
* @param path Dot path of the prop.
|
|
1025
|
+
*/
|
|
1026
|
+
private isIncludedInPartialMetadata;
|
|
1027
|
+
/**
|
|
1028
|
+
* Collect scroll pagination metadata, flagged for reset when the client
|
|
1029
|
+
* asked to reset the prop.
|
|
1030
|
+
*
|
|
1031
|
+
* @param path Dot path of the prop.
|
|
1032
|
+
* @param prop The scroll descriptor.
|
|
1033
|
+
* @param resolved The prop's resolved value.
|
|
1034
|
+
*/
|
|
1035
|
+
private collectScrollMetadata;
|
|
1036
|
+
/**
|
|
1037
|
+
* Collect once-prop metadata under its custom key (or path), unless a
|
|
1038
|
+
* partial request filters it out.
|
|
1039
|
+
*
|
|
1040
|
+
* @param path Dot path of the prop.
|
|
1041
|
+
* @param prop The once descriptor.
|
|
1042
|
+
*/
|
|
1043
|
+
private collectOnceMetadata;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Resolve shared and page props for one response.
|
|
1047
|
+
*
|
|
1048
|
+
* @param input Props, shared props, component, request state and rescue hook.
|
|
1049
|
+
*/
|
|
1050
|
+
declare function resolveProps(input: ResolvePropsInput): Promise<ResolvePropsResult>;
|
|
1051
|
+
//#endregion
|
|
1052
|
+
//#region src/core/redirects.d.ts
|
|
1053
|
+
/**
|
|
1054
|
+
* Status code Inertia uses for "soft" redirects after PUT/PATCH/DELETE so the
|
|
1055
|
+
* follow-up GET is forced to also be a GET on every browser.
|
|
1056
|
+
*/
|
|
1057
|
+
declare const INERTIA_REDIRECT_STATUS = 303;
|
|
1058
|
+
/**
|
|
1059
|
+
* Status code used for the `X-Inertia-Location` external redirect
|
|
1060
|
+
* mechanism. The client intercepts the 409 and performs a window.location
|
|
1061
|
+
* navigation rather than a fetch.
|
|
1062
|
+
*/
|
|
1063
|
+
declare const INERTIA_LOCATION_STATUS = 409;
|
|
1064
|
+
/**
|
|
1065
|
+
* Decide which status code to use for a redirect produced by an Inertia
|
|
1066
|
+
* request. After a non-GET/HEAD form submission the response must be 303
|
|
1067
|
+
* so the client's follow-up request becomes a GET.
|
|
1068
|
+
*
|
|
1069
|
+
* @param method HTTP method of the inbound request (case-insensitive).
|
|
1070
|
+
* @param fallback Status code to use for GET/HEAD/POST. Defaults to 302.
|
|
1071
|
+
*/
|
|
1072
|
+
declare function inertiaRedirectStatus(method: string, fallback?: number): number;
|
|
1073
|
+
//#endregion
|
|
1074
|
+
//#region src/core/render.d.ts
|
|
1075
|
+
/**
|
|
1076
|
+
* Inputs to {@link buildPage}. `TReq` is the framework's request type so
|
|
1077
|
+
* `shared` (when a function) receives the correct argument shape.
|
|
1078
|
+
*/
|
|
1079
|
+
interface BuildPageInput<TReq = unknown> {
|
|
1080
|
+
component: string;
|
|
1081
|
+
props: PageProps;
|
|
1082
|
+
request: InertiaRequestInfo;
|
|
1083
|
+
req: TReq;
|
|
1084
|
+
shared: SharedPropsInput<TReq> | undefined;
|
|
1085
|
+
version: string | null;
|
|
1086
|
+
options?: RenderOptions;
|
|
1087
|
+
/**
|
|
1088
|
+
* Read-once flash data to emit as a top-level page key. Resolved by the
|
|
1089
|
+
* caller (e.g. from the session); omitted from the page when nullish/empty.
|
|
1090
|
+
*/
|
|
1091
|
+
flash?: unknown;
|
|
1092
|
+
/**
|
|
1093
|
+
* Called with the error and dotted path whenever a rescued prop throws.
|
|
1094
|
+
*/
|
|
1095
|
+
onRescue?: RescueHandler;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Build the final {@link InertiaPage} object given a controller's component
|
|
1099
|
+
* + props, the request info, and configured shared props / version.
|
|
1100
|
+
*
|
|
1101
|
+
* Returned page is suitable for either:
|
|
1102
|
+
* - JSON serialization on `X-Inertia` requests, or
|
|
1103
|
+
* - embedding into the root HTML view via a `<script>` page tag.
|
|
1104
|
+
*
|
|
1105
|
+
* @param input Component, props, parsed request, shared resolver, version,
|
|
1106
|
+
* optional `clearHistory` / `encryptHistory` / `preserveFragment` flags, and
|
|
1107
|
+
* an optional rescue handler.
|
|
1108
|
+
*/
|
|
1109
|
+
declare function buildPage<TReq>(input: BuildPageInput<TReq>): Promise<InertiaPage>;
|
|
1110
|
+
//#endregion
|
|
1111
|
+
//#region src/core/versioning.d.ts
|
|
1112
|
+
/**
|
|
1113
|
+
* Resolve a version value (string, async function, or null) against a request.
|
|
1114
|
+
*
|
|
1115
|
+
* Returns `null` when no version is configured — in which case asset version
|
|
1116
|
+
* mismatch detection is disabled.
|
|
1117
|
+
*
|
|
1118
|
+
* @param resolver Static version string, a (possibly async) function, or undefined.
|
|
1119
|
+
* @param req Request passed to the resolver when it is a function.
|
|
1120
|
+
*/
|
|
1121
|
+
declare function resolveVersion<TReq>(resolver: VersionResolver<TReq> | undefined, req: TReq): Promise<string | null>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Returns true if the client's version (`X-Inertia-Version`) does not match
|
|
1124
|
+
* the server's current version. Mismatches on GET requests should trigger a
|
|
1125
|
+
* full reload via the `X-Inertia-Location` mechanism.
|
|
1126
|
+
*
|
|
1127
|
+
* @param serverVersion Currently configured server version; `null` disables checks.
|
|
1128
|
+
* @param clientVersion Value of the `X-Inertia-Version` header; `null` is treated as empty.
|
|
1129
|
+
*/
|
|
1130
|
+
declare function isVersionMismatch(serverVersion: string | null, clientVersion: string | null): boolean;
|
|
1131
|
+
//#endregion
|
|
1132
|
+
export { OnceMetadata as $, leadsToOnly as A, renderErrorPage as B, once as C, PropKind as D, PropDescriptor as E, createPage as F, unpackDotProps as G, parseInertiaRequest as H, DefaultRootViewInput as I, SsrCacheStore as J, ComputeCacheKeyInput as K, ErrorPageInput as L, matchesOnly as M, pathIsSameOrDescendant as N, PropSource as O, CreatePageInput as P, InertiaRequestInfo as Q, encodePageScript as R, merge as S, scroll as T, ValidationErrors as U, INERTIA_HEADERS as V, scopeErrors as W, computeSsrCacheKey as X, canonicalStringify as Y, InertiaPage as Z, ScrollProp as _, INERTIA_LOCATION_STATUS as a, SharedPropsInput as at, defer as b, PropsResolver as c, resolveProps as d, PageProps as et, AlwaysProp as f, OptionalProp as g, OnceProp as h, buildPage as i, ScrollMetadata as it, matchesExcept as j, ScrollOptions as k, ResolvePropsInput as l, MergeProp as m, resolveVersion as n, RenderOptions as nt, INERTIA_REDIRECT_STATUS as o, VersionResolver as ot, DeferProp as p, SsrCacheEntry as q, BuildPageInput as r, RescueHandler as rt, inertiaRedirectStatus as s, isVersionMismatch as t, PropsMetadata as tt, ResolvePropsResult as u, always as v, optional as w, isPropDescriptor as x, deepMerge as y, renderDefaultHtml as z };
|
|
1133
|
+
//# sourceMappingURL=index-PWaujyMo.d.ts.map
|