@tinvar/react 0.0.0-stage → 0.4.1

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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +168 -4
  3. package/src/action-server.js +41 -0
  4. package/src/action.d.ts +68 -0
  5. package/src/action.js +167 -0
  6. package/src/bootstrap.js +153 -0
  7. package/src/channel.d.ts +46 -0
  8. package/src/channel.js +132 -0
  9. package/src/client-modules.d.ts +8 -0
  10. package/src/client-modules.js +88 -0
  11. package/src/client.d.ts +36 -0
  12. package/src/client.js +42 -0
  13. package/src/compose-route.d.ts +33 -0
  14. package/src/compose-route.js +107 -0
  15. package/src/csrf.d.ts +11 -0
  16. package/src/csrf.js +49 -0
  17. package/src/deferred-boundary.d.ts +61 -0
  18. package/src/deferred-boundary.js +646 -0
  19. package/src/deferred-groups.d.ts +24 -0
  20. package/src/deferred-groups.js +198 -0
  21. package/src/deferred-revalidation.d.ts +37 -0
  22. package/src/deferred-revalidation.js +108 -0
  23. package/src/deferred-triggers.d.ts +26 -0
  24. package/src/deferred-triggers.js +172 -0
  25. package/src/deferred.d.ts +24 -0
  26. package/src/deferred.jsx +100 -0
  27. package/src/document-load.js +95 -0
  28. package/src/endpoint.d.ts +87 -0
  29. package/src/endpoint.js +304 -0
  30. package/src/form-data.js +219 -0
  31. package/src/form.d.ts +177 -0
  32. package/src/form.js +615 -0
  33. package/src/forms.d.ts +4 -0
  34. package/src/forms.js +10 -0
  35. package/src/fragment-client.d.ts +70 -0
  36. package/src/fragment-client.js +510 -0
  37. package/src/head.d.ts +85 -0
  38. package/src/head.js +360 -0
  39. package/src/inbox-view.d.ts +17 -0
  40. package/src/inbox-view.js +105 -0
  41. package/src/inbox.d.ts +108 -0
  42. package/src/inbox.js +293 -0
  43. package/src/index.combined.d.ts +31 -0
  44. package/src/index.d.ts +5 -0
  45. package/src/index.js +29 -0
  46. package/src/index.server.d.ts +4 -0
  47. package/src/index.server.js +8 -0
  48. package/src/infinite-scroll.d.ts +108 -0
  49. package/src/infinite-scroll.js +715 -0
  50. package/src/layout-props.d.ts +30 -0
  51. package/src/layout-props.js +143 -0
  52. package/src/link-click.d.ts +3 -0
  53. package/src/link-click.js +68 -0
  54. package/src/link.d.ts +63 -0
  55. package/src/link.js +274 -0
  56. package/src/live.d.ts +65 -0
  57. package/src/live.js +977 -0
  58. package/src/merge-slot.d.ts +41 -0
  59. package/src/merge-slot.js +253 -0
  60. package/src/merge.d.ts +111 -0
  61. package/src/merge.js +149 -0
  62. package/src/once-slot.d.ts +14 -0
  63. package/src/once-slot.js +75 -0
  64. package/src/once-store.d.ts +26 -0
  65. package/src/once-store.js +211 -0
  66. package/src/once.d.ts +44 -0
  67. package/src/once.js +65 -0
  68. package/src/optimistic.d.ts +14 -0
  69. package/src/optimistic.js +159 -0
  70. package/src/optional.d.ts +10 -0
  71. package/src/optional.js +31 -0
  72. package/src/page-root.d.ts +56 -0
  73. package/src/page-root.js +455 -0
  74. package/src/payload.d.ts +15 -0
  75. package/src/payload.js +101 -0
  76. package/src/poll.d.ts +55 -0
  77. package/src/poll.js +224 -0
  78. package/src/precognition.js +190 -0
  79. package/src/prefetch-cache.d.ts +46 -0
  80. package/src/prefetch-cache.js +256 -0
  81. package/src/progress.d.ts +38 -0
  82. package/src/progress.js +243 -0
  83. package/src/remember-store.d.ts +50 -0
  84. package/src/remember-store.js +486 -0
  85. package/src/rescue.d.ts +10 -0
  86. package/src/rescue.js +30 -0
  87. package/src/resumable.js +822 -0
  88. package/src/resume-store.js +364 -0
  89. package/src/route.d.ts +50 -0
  90. package/src/route.js +227 -0
  91. package/src/router-hooks.js +234 -0
  92. package/src/router.d.ts +586 -0
  93. package/src/router.js +3555 -0
  94. package/src/segment.d.ts +36 -0
  95. package/src/segment.js +116 -0
  96. package/src/server.d.ts +71 -0
  97. package/src/server.js +242 -0
  98. package/src/submit.js +333 -0
  99. package/src/telemetry.d.ts +71 -0
  100. package/src/telemetry.js +851 -0
  101. package/src/testing.d.ts +89 -0
  102. package/src/testing.js +634 -0
  103. package/src/transfer.d.ts +48 -0
  104. package/src/transfer.js +135 -0
  105. package/src/transport.js +390 -0
  106. package/src/upload.d.ts +342 -0
  107. package/src/upload.js +1240 -0
  108. package/src/use-channel.d.ts +21 -0
  109. package/src/use-channel.js +51 -0
  110. package/src/use-form.d.ts +86 -0
  111. package/src/use-form.js +432 -0
  112. package/src/use-http.d.ts +56 -0
  113. package/src/use-http.js +248 -0
  114. package/src/use-inbox.d.ts +41 -0
  115. package/src/use-inbox.js +201 -0
  116. package/src/use-remember.d.ts +10 -0
  117. package/src/use-remember.js +132 -0
  118. package/src/when-mounted.d.ts +15 -0
  119. package/src/when-mounted.js +27 -0
  120. package/README.md +0 -3
@@ -0,0 +1,586 @@
1
+ /** The client router: navigation, history, scroll and the wire protocol. */
2
+
3
+ export declare const RSC_CONTENT_TYPE: 'text/x-component';
4
+ export declare const ROUTE_TOKEN_HEADER: 'x-route-token';
5
+ /** The page's live token on a payload; handed on in the `success` event's `liveToken`. */
6
+ export declare const LIVE_TOKEN_HEADER: 'x-live-token';
7
+ /** The `Purpose` a prefetch request is sent with. */
8
+ export declare const PREFETCH_PURPOSE: 'prefetch';
9
+ /** Marks a background request -- a poll -- so the server records no visit for it. */
10
+ export declare const BACKGROUND_HEADER: 'x-background';
11
+ /** Where an action's response lists the cache tags it invalidated. */
12
+ export declare const INVALIDATED_TAGS_HEADER: 'x-invalidated-tags';
13
+ /** Where a page's payload carries its history key, when its history is encrypted (ADR 0019). */
14
+ export declare const HISTORY_KEY_HEADER: 'x-history-key';
15
+
16
+ /** The tags an action's response names in `X-Invalidated-Tags`. */
17
+ export declare function invalidatedTags(
18
+ source: Response | Headers | { headers?: Headers } | string | null | undefined,
19
+ ): string[];
20
+
21
+ /**
22
+ * Flushes, from every router on the page, the prefetched pages an action's
23
+ * response says it invalidated. Hand every action response here once; no
24
+ * form needs to name a tag. Returns the tags it named.
25
+ */
26
+ export declare function flushInvalidated(
27
+ source: Response | Headers | { headers?: Headers } | string | null | undefined,
28
+ ): string[];
29
+ /**
30
+ * Ends the session on this client, for whatever heard a 401: the router given,
31
+ * or every router that is up, revokes what it holds, and the tab's
32
+ * remembered state is wiped either way. The caller makes the full page load.
33
+ */
34
+ export declare function revokeSession(router?: { revoke(): void } | null): void;
35
+ /**
36
+ * What logging out calls: clears the history of the router given, or of
37
+ * every router that is up -- everything remembered, for every entry of the
38
+ * tab, and the history key -- and wipes the tab's remembered state either
39
+ * way. The key itself rotates with the session's id (ADR 0019).
40
+ */
41
+ export declare function clearHistory(router?: { clearHistory(): void } | null): void;
42
+ /** How many X-Redirects one visit will follow before loading the document. */
43
+ export declare const MAX_REDIRECTS: number;
44
+ /** How long restoring a scroll position keeps trying while the page is too short to reach it, in ms. */
45
+ export declare const SCROLL_RESTORE_MS: number;
46
+ /**
47
+ * The attribute that marks an inner scroller whose position is kept with
48
+ * the window's: saved per history entry, put back on back and forward, reset
49
+ * on a visit unless `preserveScroll`. Regions are matched by document order.
50
+ */
51
+ export declare const SCROLL_REGION_ATTRIBUTE: 'scroll-region';
52
+
53
+ export declare class VisitCancelled extends Error {}
54
+
55
+ /** A visit's `onError`, told the server answered a status that is not a page. */
56
+ export declare class VisitHttpError extends Error {
57
+ readonly url: string;
58
+ readonly status: number;
59
+ }
60
+
61
+ /** A visit's `onError`, told no answer came; `cause` is what the fetch threw. */
62
+ export declare class VisitNetworkError extends Error {
63
+ readonly url: string;
64
+ }
65
+
66
+ export interface VisitOptions {
67
+ method?: 'get';
68
+ /**
69
+ * The query: merged into the URL's query string, as Inertia deep-merges
70
+ * a GET's: a nested object merges into the fields the URL has under its
71
+ * key (`filter: { status }` replaces `filter[status]` and keeps
72
+ * `filter[sort]`), and any other value -- a list included -- replaces
73
+ * what the URL said under its name. The rest of the query is kept.
74
+ * Written as a form body is -- `tags[]`, `filter[status]`, booleans as 1
75
+ * and 0, null as an empty string; undefined takes the field out. A file
76
+ * throws: a visit is a GET.
77
+ */
78
+ data?: Record<string, unknown>;
79
+ replace?: boolean;
80
+ /**
81
+ * Keep the window and the `scroll-region` elements where they are rather
82
+ * than at the top. A function decides once the response is in, told what
83
+ * `preserveState`'s is.
84
+ */
85
+ preserveScroll?: boolean | ((page: PreservedPage) => boolean);
86
+ headers?: Record<string, string>;
87
+ /** A request the user did not trigger -- a poll, a prefetch. Never forces a reload. */
88
+ background?: boolean;
89
+ /**
90
+ * A partial reload of the segments these dot paths name: `'page'`,
91
+ * `'page.order'`, a layout's key such as `'shop'`, or `'shop.customer'`.
92
+ * The unit recomputed is the segment (ADR 0015).
93
+ */
94
+ only?: readonly string[];
95
+ /** A partial reload of every segment but those named whole here. */
96
+ except?: readonly string[];
97
+ /**
98
+ * Merged fields -- #[Merge] lists and Scroll pages, by dot path such as
99
+ * `'page.orders'` -- this response replaces rather than adds to: what a
100
+ * filter that changes the list asks for (X-Reset, ADR 0020).
101
+ */
102
+ reset?: readonly string[];
103
+ /**
104
+ * Fetch the URL without moving the address bar to it: no entry pushed or
105
+ * replaced. In the background, a partial payload of the page on screen
106
+ * fetched at another of its URLs -- a list's next page -- is merged into it.
107
+ */
108
+ preserveUrl?: boolean;
109
+ /** Cancels this visit, or this background request, and nothing else. */
110
+ signal?: AbortSignal;
111
+ /** False keeps the progress bar hidden for this visit. Background requests never show it. */
112
+ showProgress?: boolean;
113
+ /**
114
+ * Mount the page inside `document.startViewTransition()`, where the
115
+ * browser has it; a function is handed the ViewTransition. Without the
116
+ * API the page mounts as usual. Never for background requests. With a
117
+ * router given `prepare`, the transition holds the page for the commit
118
+ * alone, not while the payload is decoded.
119
+ */
120
+ viewTransition?: boolean | ((transition: ViewTransition) => void);
121
+ /**
122
+ * Whether the page's client components keep their state: reconciled with
123
+ * the page they replace (true), or mounted again (false), the page
124
+ * segment's -- or the segments a partial reload carries -- while layouts
125
+ * keep theirs. A function decides once the response is in. Defaults, as
126
+ * Inertia's: false for a visit that shows a whole page, true for
127
+ * reload(), a partial reload, a background request and an action's
128
+ * re-render (ADR 0045).
129
+ */
130
+ preserveState?: boolean | ((page: PreservedPage) => boolean);
131
+ /**
132
+ * Ask the server even when a prefetched copy of the page is kept. The
133
+ * visit after an action is made fresh: the action may have changed whose
134
+ * session this is.
135
+ */
136
+ fresh?: boolean;
137
+ /**
138
+ * Claim none of the #[Once] content this client keeps, so the server
139
+ * renders those fields again: for a live refresh, which says something
140
+ * the page read has changed.
141
+ */
142
+ refreshOnce?: boolean;
143
+ /**
144
+ * This visit's own `success`: the page was mounted. May return a promise,
145
+ * which the visit's `finish` -- and the promise visit() returns -- waits for.
146
+ */
147
+ onSuccess?: (page: PreservedPage) => unknown;
148
+ /**
149
+ * Each way this visit failed: the payload arrived and could not be
150
+ * rendered (handed what the mount threw), the server answered a status
151
+ * that is not a page (a VisitHttpError), or no answer came (a
152
+ * VisitNetworkError). May return a promise, waited for before the visit's
153
+ * `finish` and before the page is loaded as a document. Told, not asked:
154
+ * cancelling `error`, `httpException` or `networkError` is what stops the
155
+ * document load. A GET carries no validation errors.
156
+ */
157
+ onError?: (error: unknown) => unknown;
158
+ /**
159
+ * Show the layouts on screen, and a layout's loading boundary below them,
160
+ * while the page is fetched (ADR 0092): the boundary of the layout
161
+ * directly above the page given true, of the layout with that key given a
162
+ * string. Not for a page answered from the prefetch cache, a partial
163
+ * reload, a background request, or back and forward; a layout with no
164
+ * boundary makes it an ordinary visit.
165
+ */
166
+ instant?: boolean | string;
167
+ }
168
+
169
+ /** The page's view, on a payload; sent back as X-Page with a partial reload. */
170
+ export declare const PAGE_HEADER: 'x-page';
171
+ /** Marks a payload holding only what a partial reload recomputed. */
172
+ export declare const PARTIAL_HEADER: 'x-partial';
173
+
174
+ /**
175
+ * How long a prefetched page is used for: milliseconds, or `'30s'`, `'1m'`
176
+ * and the like; or `[fresh, stale]`, used while fresh and then, while a new
177
+ * copy is fetched behind it, until the second -- the whole lifetime.
178
+ */
179
+ export type CacheFor = number | string | readonly [number | string, number | string];
180
+
181
+ export interface PrefetchOptions {
182
+ /** 30 seconds unless given. */
183
+ cacheFor?: CacheFor;
184
+ /**
185
+ * What the page shows, as cache tags: an action whose response names one
186
+ * in `X-Invalidated-Tags` flushes it, and so does flushByCacheTags().
187
+ */
188
+ cacheTags?: string | readonly string[];
189
+ /** Only GET prefetches; any other method is ignored. */
190
+ method?: string;
191
+ }
192
+
193
+ /** Which page's history entry useRemember() writes to. */
194
+ export interface RememberScope {
195
+ readonly entry: string | null;
196
+ readonly session: string | null;
197
+ }
198
+
199
+ /** What a `preserveState` function is told of the page that came back. */
200
+ export interface PreservedPage {
201
+ url: string;
202
+ /** The page's view, as the server named it; null where it did not. */
203
+ view: string | null;
204
+ partial: boolean;
205
+ }
206
+
207
+ export interface Page {
208
+ url: string;
209
+ routeToken: string | null;
210
+ /** Aborts once a later navigation supersedes this one. */
211
+ signal: AbortSignal;
212
+ /** The payload is `{ segments }` from a partial reload, to merge into the page on screen. */
213
+ partial?: boolean;
214
+ /** False: commit it fresh, its page segment's components mounted again. See VisitOptions. */
215
+ preserveState?: boolean;
216
+ }
217
+
218
+ /** A payload decoded and ready to go on screen; see RouterOptions.prepare. */
219
+ export interface PreparedPage {
220
+ /** Shows the page. Resolve only once it is COMMITTED, or the visit aborted. */
221
+ commit: () => Promise<void>;
222
+ }
223
+
224
+ export type RouterOptions = RouterMountOptions &
225
+ (
226
+ | {
227
+ /**
228
+ * Turns a payload into React elements; must use the app's own
229
+ * client bundle. Resolve only once the page is COMMITTED: the
230
+ * router scrolls, finds anchors and reports the page right after,
231
+ * and those all read the DOM.
232
+ */
233
+ mount: (stream: ReadableStream<Uint8Array>, page: Page) => void | Promise<void>;
234
+ prepare?: undefined;
235
+ }
236
+ | {
237
+ mount?: (stream: ReadableStream<Uint8Array>, page: Page) => void | Promise<void>;
238
+ /**
239
+ * The mount in two steps, as createPageRoot() hands it: decode the
240
+ * payload, then commit it. Preferred over `mount` where both are
241
+ * given: a view transition then holds the page for the commit
242
+ * alone. Resolves null when the visit was aborted while decoding.
243
+ */
244
+ prepare: (stream: ReadableStream<Uint8Array>, page: Page) => Promise<PreparedPage | null | undefined>;
245
+ }
246
+ );
247
+
248
+ export interface RouterMountOptions {
249
+ /** This client's build, sent as X-Version. Read from the page metadata if omitted. */
250
+ version?: string;
251
+ fetch?: typeof fetch;
252
+ window?: Window;
253
+ initialRouteToken?: string | null;
254
+ /** The first page's view, sent as X-Page. Read from the page metadata if omitted. */
255
+ initialView?: string | null;
256
+ /** A full page load. Defaults to location.assign. */
257
+ hardNavigate?: (url: string) => void;
258
+ /**
259
+ * Where useRemember() keeps its values, by history entry, for one session:
260
+ * the tab's sessionStorage unless given; memory alone given null.
261
+ */
262
+ storage?: Storage | null;
263
+ /**
264
+ * Where resumable uploads are remembered, which the router purges of
265
+ * every other session's records: the page's IndexedDB store unless given.
266
+ */
267
+ resumeStore?: import('./upload.js').ResumeStore;
268
+ /**
269
+ * The first page's history key, which what it remembers is sealed with.
270
+ * Read from the page metadata if omitted; null for a page whose history
271
+ * is not encrypted (ADR 0019).
272
+ */
273
+ initialHistoryKey?: string | null;
274
+ /**
275
+ * The application's endpoints -- codegen's `endpoint` -- whose URLs are no
276
+ * page's (ADR 0074): a link to one is left to the browser, a visit to one
277
+ * is a full load, and none is fetched as a payload or prefetched.
278
+ */
279
+ endpoints?: { matches(url: URL | string): boolean };
280
+ /**
281
+ * Shows an instant visit's loading boundary and hands back what takes it
282
+ * away: createPageRoot()'s `instant`. Without it, an instant visit is an
283
+ * ordinary one.
284
+ */
285
+ instant?: (under: true | string) => (() => void) | null;
286
+ }
287
+
288
+ /**
289
+ * Cancelable events (before, location, httpException, networkError, error)
290
+ * are UI hooks, not security controls: any script on the page can cancel
291
+ * them, and the server enforces every rule regardless.
292
+ */
293
+ export type RouterEvent =
294
+ | 'before'
295
+ | 'start'
296
+ | 'success'
297
+ | 'finish'
298
+ /**
299
+ * A page is shown: the first (`initial`, once `ready` has settled, or
300
+ * before any other event that comes first), one a visit mounted, or one
301
+ * back or forward arrived at.
302
+ */
303
+ | 'navigate'
304
+ | 'location'
305
+ | 'httpException'
306
+ | 'networkError'
307
+ /** The mount threw. Cancelable; otherwise the page is loaded as a document. */
308
+ | 'error'
309
+ /** An action flashed something; see Router.flash(). */
310
+ | 'flash'
311
+ /** A prefetch was sent. */
312
+ | 'prefetching'
313
+ /** A prefetched page arrived and is kept. */
314
+ | 'prefetched'
315
+ /** The session ended on this client (a 401, or revoke()): what else holds its data drops it. */
316
+ | 'revoke'
317
+ /** clearHistory() ran: what else holds the session's data drops it. */
318
+ | 'clearHistory'
319
+ /** The router started reading a visit's RSC payload. */
320
+ | 'streamStart'
321
+ /** A chunk of the payload arrived: its size, and how much has so far. Never the bytes. */
322
+ | 'streamChunk'
323
+ /**
324
+ * The payload is all in -- after `finish`, for a page that commits at its
325
+ * shell and streams the rest -- or, `interrupted`, never will be.
326
+ */
327
+ | 'streamEnd'
328
+ /** <Form>, useForm or useHttp sent an action. */
329
+ | 'actionStart'
330
+ /** An action's files are uploading: `progress` is how far, as the form's own is. */
331
+ | 'progress'
332
+ /** An action's answer came back and was applied to the page; `type` says what it was. */
333
+ | 'actionSettle';
334
+
335
+ /** The first page, one a visit showed, or one back or forward arrived at. */
336
+ export interface NavigateDetail {
337
+ url: string;
338
+ type: 'initial' | 'visit' | 'history';
339
+ }
340
+
341
+ /** What the RSC stream events say of the request. */
342
+ export interface StreamDetail {
343
+ url: string;
344
+ /** A poll, a deferred refresh, a list's next page. */
345
+ background?: true;
346
+ }
347
+
348
+ export interface StreamChunkDetail extends StreamDetail {
349
+ /** This chunk's size in bytes. */
350
+ bytes: number;
351
+ /** Every chunk's so far, this one included. */
352
+ received: number;
353
+ }
354
+
355
+ export interface StreamEndDetail extends StreamDetail {
356
+ /** The payload's size in bytes, or as much of it as arrived. */
357
+ bytes: number;
358
+ /** It stopped before its end: superseded, cancelled, dropped, or not mounted. */
359
+ interrupted?: true;
360
+ }
361
+
362
+ export interface ActionDetail {
363
+ /** The action's name, as `@actions/*` names it. */
364
+ action: string;
365
+ }
366
+
367
+ export interface ActionProgressDetail extends ActionDetail {
368
+ progress: { loaded: number; total: number | undefined; percentage: number | undefined };
369
+ }
370
+
371
+ export interface ActionSettleDetail extends ActionDetail {
372
+ /**
373
+ * How it came back: the three error channels, a page that outlived its
374
+ * session, a cancel or a newer call, or `error` for something that threw
375
+ * on the way. A redirect is a success.
376
+ */
377
+ type: 'success' | 'validation' | 'http' | 'network' | 'expired' | 'cancelled' | 'error';
378
+ /** For `http`, the status. */
379
+ status?: number;
380
+ }
381
+
382
+ /** The detail each event carries, where it is typed. */
383
+ export interface RouterEventDetails {
384
+ navigate: NavigateDetail;
385
+ streamStart: StreamDetail;
386
+ streamChunk: StreamChunkDetail;
387
+ streamEnd: StreamEndDetail;
388
+ actionStart: ActionDetail;
389
+ progress: ActionProgressDetail;
390
+ actionSettle: ActionSettleDetail;
391
+ }
392
+
393
+ /** An event's detail: typed for those RouterEventDetails names. */
394
+ export type RouterEventDetail<E extends RouterEvent> = E extends keyof RouterEventDetails
395
+ ? RouterEventDetails[E]
396
+ : any;
397
+
398
+ export interface Router {
399
+ /**
400
+ * Resolves once the visit is over, with whether a page was mounted: false
401
+ * when it failed, was cancelled or superseded, was not sent -- a
402
+ * background request while a visit is in flight -- or was answered with
403
+ * nothing to mount here.
404
+ */
405
+ visit(href: string, options?: VisitOptions): Promise<boolean>;
406
+ get(href: string, options?: VisitOptions): Promise<boolean>;
407
+ /**
408
+ * As visit(): with `background`, whether the page on screen was refreshed.
409
+ * Given the `routeToken` an action was sent with, it is refused, as
410
+ * applyPayload() is, once another page has been mounted or while a visit
411
+ * is in flight.
412
+ */
413
+ reload(options?: VisitOptions & { routeToken?: string | null }): Promise<boolean>;
414
+ /**
415
+ * Fetches a page ahead of a visit, with `Purpose: prefetch`, and keeps it
416
+ * for `cacheFor`. A visit to it within that time is answered from the
417
+ * cache, or waits for the prefetch if it is still in flight. GET only.
418
+ */
419
+ prefetch(href: string, options?: PrefetchOptions): Promise<void>;
420
+ /**
421
+ * Mounts a re-rendered payload of the page on screen -- an action's
422
+ * revalidation -- without a request: no history, no scroll, the route
423
+ * token kept, and never while a visit is in flight. Resolves once the page
424
+ * has committed, with whether it was mounted. Of `options`,
425
+ * `viewTransition`, `preserveState`, `onSuccess` and `onError` apply.
426
+ * Given the `routeToken` the action was sent with, it is refused once
427
+ * another page has been mounted since. Given the re-render's `liveToken`,
428
+ * the `success` event hands it on.
429
+ */
430
+ applyPayload(
431
+ payload: string | Uint8Array | ReadableStream<Uint8Array>,
432
+ options?: VisitOptions & { routeToken?: string | null; liveToken?: string | null },
433
+ ): Promise<boolean>;
434
+ /** Emits the `flash` event: to listeners, and as a native `tinvar:flash` CustomEvent. */
435
+ flash(flash: Record<string, unknown>, detail?: Record<string, unknown>): void;
436
+ /**
437
+ * Emits one of the forms layer's events -- `actionStart`, `progress`,
438
+ * `actionSettle` -- to listeners and as a native `tinvar:<name>`
439
+ * CustomEvent. What <Form>, useForm and useHttp call; any other name throws.
440
+ */
441
+ announce<E extends 'actionStart' | 'progress' | 'actionSettle'>(
442
+ name: E,
443
+ detail: RouterEventDetails[E],
444
+ ): void;
445
+ /** Forgets the prefetched copy of a page. */
446
+ flush(href: string): void;
447
+ /** Forgets every prefetched page. */
448
+ flushAll(): void;
449
+ /**
450
+ * Ends the session on this client, for a 401 the router did not hear
451
+ * itself: drops the route token, every prefetched page and everything
452
+ * remembered, stops what is in flight, and sends nothing more. The caller
453
+ * makes the full page load that must follow.
454
+ */
455
+ revoke(): void;
456
+ /**
457
+ * Wipes everything remembered, for every entry of the tab, and drops the
458
+ * history key, so nothing sealed with it opens in this document again.
459
+ * Nothing more is remembered on the page it is called on. What logging
460
+ * out calls; the key itself rotates with the session's id (ADR 0019).
461
+ */
462
+ clearHistory(): void;
463
+ /**
464
+ * Settles once what the first page's entry remembered has been read back:
465
+ * at once for an entry kept in the clear, after opening it for one kept
466
+ * sealed. Await it before hydrating, so components mount with it.
467
+ */
468
+ readonly ready: Promise<void>;
469
+ /** Forgets every prefetched page carrying one of these tags; returns how many. */
470
+ flushByCacheTags(tags: string | readonly string[]): number;
471
+ /**
472
+ * Forgets the prefetched pages an action's response says it invalidated,
473
+ * from its `X-Invalidated-Tags`. Returns the tags it named.
474
+ */
475
+ flushInvalidated(source: Response | Headers | { headers?: Headers } | string | null | undefined): string[];
476
+ /**
477
+ * The page a component mounting now belongs to, for what it remembers:
478
+ * the page being mounted while a visit mounts one, otherwise the page on
479
+ * screen. Opaque; useRemember() takes it once, as it mounts.
480
+ */
481
+ rememberScope(): RememberScope;
482
+ /** The value remembered under a key for a page, or undefined -- also when it was set under another session. */
483
+ remembered(key: string, scope?: RememberScope): unknown;
484
+ /**
485
+ * Remembers a value under a key on the page's history entry, bound to the
486
+ * session in force as it is set. Without a session nothing is remembered.
487
+ */
488
+ remember(key: string, value: unknown, scope?: RememberScope): void;
489
+ /**
490
+ * What a page kept of a #[Once] field, for <OnceSlot>: only for a page of
491
+ * the session it was kept under. `scope` defaults to rememberScope().
492
+ */
493
+ heldOnce(key: string, scope?: RememberScope): { content: unknown } | undefined;
494
+ /**
495
+ * X-Have-Shared with the once-shared values' holds kept under the page on
496
+ * screen's session, for a fragment request to claim them by (ADR 0074);
497
+ * empty when there are none.
498
+ */
499
+ sharedClaims(): Record<string, string>;
500
+ /** Whether a URL is one of the application's endpoints, which the router leaves to the browser (ADR 0074). */
501
+ isEndpoint(url: URL | string): boolean;
502
+ /** Keeps what a page rendered from a #[Once] field, for the session the page came with. */
503
+ holdOnce(
504
+ key: string,
505
+ content: unknown,
506
+ ttl: number | null,
507
+ tags: readonly string[],
508
+ scope?: RememberScope,
509
+ /** A once-shared value's signed hold, which claims it in X-Have-Shared (ADR 0065). */
510
+ hold?: string | null,
511
+ ): void;
512
+ /** Stops listing these once keys, or all of them, in X-Have-Once; the next response sends them fresh. */
513
+ flushOnce(keys?: string | readonly string[]): void;
514
+ /**
515
+ * Moves the address bar to another URL of the page on screen without a
516
+ * request, replacing the entry and keeping its state. Same origin only.
517
+ */
518
+ replaceUrl(href: string): boolean;
519
+ /**
520
+ * Records where a merged list on the page on screen is read to, on its
521
+ * history entry, with the scroll position. What <InfiniteScroll> calls as
522
+ * the reader scrolls.
523
+ */
524
+ saveScrollAnchor(id: string, anchor: ScrollAnchor): void;
525
+ /**
526
+ * Where a merged list was read to on the entry a back, a forward or a
527
+ * reload arrived at -- once; undefined after any other visit. Taking one
528
+ * in the window stops the router restoring the raw position; one in the
529
+ * `container` given stops it restoring that container, as a scroll region.
530
+ */
531
+ takeScrollAnchor(id: string, container?: Element | null): ScrollAnchor | undefined;
532
+ /** Cancels the visit (`sync`), background requests (`async`) and prefetches; all three by default. */
533
+ cancelAll(options?: { sync?: boolean; async?: boolean; prefetch?: boolean }): void;
534
+ /** Subscribes to an event; returns the unsubscribe function. Each is also a native `tinvar:<name>` CustomEvent. */
535
+ on<E extends RouterEvent>(name: E, fn: (event: CustomEvent<RouterEventDetail<E>>) => void): () => void;
536
+ /** The tokens an action sends so the mounted page can be re-rendered. */
537
+ routeTokens(): string[];
538
+ /** The view of the page on screen, where the server named it; null where it did not. */
539
+ currentView(): string | null;
540
+ destroy(): void;
541
+ }
542
+
543
+ /**
544
+ * Where a merged list was read to: the item at the top of what the reader
545
+ * saw, how far down the screen (or the list's scroll container) its top
546
+ * was, and the pages that were loaded.
547
+ */
548
+ export interface ScrollAnchor {
549
+ /** The page the item came on. */
550
+ page: number;
551
+ /** The key it was rendered under, where the list could tell; null otherwise. */
552
+ key: string | null;
553
+ /** Its place among its page's items. */
554
+ index: number;
555
+ /** Its top, in pixels below the top of the window or the scroll container. */
556
+ top: number;
557
+ first: number;
558
+ last: number;
559
+ /** Whether the list scrolls with the window rather than a container of its own. */
560
+ window: boolean;
561
+ }
562
+
563
+ export declare const PAGE_METADATA_ID: 'tinvar-page';
564
+
565
+ export interface PageMetadata {
566
+ url: string;
567
+ version: string;
568
+ routeToken: string | null;
569
+ /** Null where partial reloads are off. */
570
+ view: string | null;
571
+ /**
572
+ * The session's history key, for a page whose history is encrypted (ADR 0019); otherwise null.
573
+ * The router takes it out of the block once it has imported it: read after it starts, null.
574
+ */
575
+ historyKey: string | null;
576
+ /** What the page's reports are filed under: its route's name, or its view where it has none (ADR 0129). */
577
+ route: string | null;
578
+ }
579
+
580
+ /** The session binding a route token carries -- session hash, user hash, tenant, panel -- or null. Unverified. */
581
+ export declare function bindingOf(token: string | null | undefined): string | null;
582
+
583
+ /** The initial page metadata the renderer wrote, or null if absent or malformed. */
584
+ export declare function readPageMetadata(doc?: Document): PageMetadata | null;
585
+
586
+ export declare function createRouter(options: RouterOptions): Router;