foldkit-site 0.8.0 → 0.10.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 +105 -20
- package/dist/index.d.mts +130 -40
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +55 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -21,11 +21,11 @@ application with its data rendered on the server.
|
|
|
21
21
|
|
|
22
22
|
`foldkit-site` owns **where the application is**, and nothing else:
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
`foldkit-site` answers three questions in turn, and owns only the first:
|
|
25
|
+
|
|
26
|
+
- **Site:** what location are we at, and what is around it?
|
|
27
|
+
- **Surface:** what may this location observe, and which Messages may it cause?
|
|
28
|
+
- **Remote:** what server facts do those observations require?
|
|
29
29
|
|
|
30
30
|
It owns no Model, runs no Effects, dispatches no Messages, and fetches
|
|
31
31
|
nothing. A node lowers to an ordinary Foldkit Router (which it is built
|
|
@@ -35,13 +35,9 @@ become another store, async runtime, or cache, it does not belong here.
|
|
|
35
35
|
|
|
36
36
|
## The mental model
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Site tree route value -> chain, metadata, Surfaces
|
|
42
|
-
+
|
|
43
|
-
Surface / Remote / SSR the existing consumers of those answers
|
|
44
|
-
```
|
|
38
|
+
A Foldkit Router per node turns a URL into a typed route value and back. The Site
|
|
39
|
+
tree turns a route value into a chain, metadata and Surfaces. Surface, Remote and
|
|
40
|
+
SSR are the existing consumers of those answers.
|
|
45
41
|
|
|
46
42
|
A node is a stable first-class value: mounting it in a tree never mutates
|
|
47
43
|
it, so the same node builds targets, hrefs, and inspection wherever it is
|
|
@@ -323,8 +319,8 @@ const People = Site.route(peopleRouter, AppRoute.People, {
|
|
|
323
319
|
})
|
|
324
320
|
```
|
|
325
321
|
|
|
326
|
-
`Site.sources(site, App.owner, App.model.route)` is each
|
|
327
|
-
`Surface.when`, keyed by tag, for `Data.wiring`, `Data.subscriptions`,
|
|
322
|
+
`Site.sources(site, App.owner, App.model.route)` is each node with a Surface
|
|
323
|
+
as its `Surface.when`, keyed by its tag, for `Data.wiring`, `Data.subscriptions`,
|
|
328
324
|
`Data.satisfy`, or an SSR plan's `surfaces`. A surface from another
|
|
329
325
|
application is refused here. Each entry answers its own tag only: on a
|
|
330
326
|
person page the person surface is active and the people surface is not.
|
|
@@ -677,7 +673,7 @@ policy is chosen (from Chirp, which reads a profile again sooner than the
|
|
|
677
673
|
timeline):
|
|
678
674
|
|
|
679
675
|
<!-- docs-check standalone
|
|
680
|
-
import { Schema, pipe } from 'effect'
|
|
676
|
+
import { Option, Schema, pipe } from 'effect'
|
|
681
677
|
import { defineMessageUnion } from 'foldkit/message'
|
|
682
678
|
import { defineRouteUnion, literal, mapTo, root, slash, string } from 'foldkit/route'
|
|
683
679
|
import { Remote, RemotePolicy } from 'foldkit-remote'
|
|
@@ -702,6 +698,7 @@ const AppSite = Site.make(
|
|
|
702
698
|
surface: { surface: Profile, params: ({ handle }) => ({ handle }) },
|
|
703
699
|
}),
|
|
704
700
|
)
|
|
701
|
+
const editor = Data.active('editor', () => Option.none())
|
|
705
702
|
-->
|
|
706
703
|
|
|
707
704
|
```ts
|
|
@@ -720,11 +717,32 @@ const wiring = Data.wiring(Site.sources(AppSite, App.owner, App.model.route), {
|
|
|
720
717
|
The Surfaces come from the tree (`Site.sources`), each answering its own
|
|
721
718
|
route, and the policy is the one the Model's route picks, so the two vary
|
|
722
719
|
together without either naming the other. Nothing here fetches: `Data.wiring`
|
|
723
|
-
reads the policy when it plans a read.
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
720
|
+
reads the policy when it plans a read. Retention stays the store's: a node has
|
|
721
|
+
no `retain`. See `examples/chirp/src/app.ts` (`policy`) and
|
|
722
|
+
`examples/chirp/test/site.test.ts` for the same wiring checked per route.
|
|
723
|
+
|
|
724
|
+
The policy the route picks covers every Surface active on it. When one of them
|
|
725
|
+
should read otherwise, such as an editor shown beside every page that reads
|
|
726
|
+
its draft from the server rather than from what the store holds, `policies` gives it a policy of its own by its key in
|
|
727
|
+
the active record, and the rest read under `policy`:
|
|
728
|
+
|
|
729
|
+
```ts
|
|
730
|
+
const withEditor = Data.wiring(
|
|
731
|
+
{ ...Site.sources(AppSite, App.owner, App.model.route), editor },
|
|
732
|
+
{
|
|
733
|
+
policy: (model: Model) =>
|
|
734
|
+
AppRoute.match(model.route, { Home: () => timeline, Profile: () => profile }),
|
|
735
|
+
policies: { editor: RemotePolicy.networkOnly, Profile: RemotePolicy.cacheFirst },
|
|
736
|
+
},
|
|
737
|
+
)
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
A key the record lacks is a type error. `Site.sources` is keyed by the tags of
|
|
741
|
+
the nodes with a Surface (the tree's type carries them, from `.surface` or
|
|
742
|
+
`Site.route`'s `surface`), so a node's key (`Profile`) survives the spread and
|
|
743
|
+
can be named beside `editor`, and a node with no Surface has no key to name. A list the
|
|
744
|
+
editor and the page both read is held stale once left unless both policies
|
|
745
|
+
age it.
|
|
728
746
|
|
|
729
747
|
**Reading a page ahead on intent.** Give `Site.routing` a `preload`, and a
|
|
730
748
|
link the reader means to follow is read before they follow it, so its page
|
|
@@ -756,6 +774,73 @@ cancelled. What it read is kept until retention next changes. There is no
|
|
|
756
774
|
"intended route" field in the Model and no extra Surface for it: the page's
|
|
757
775
|
own Surfaces say what it reads.
|
|
758
776
|
|
|
777
|
+
Two options and a second stream tune what counts. `pointedLinks({ rest })`
|
|
778
|
+
changes the 50 ms wait (`rest: '100 millis'`). A link marked
|
|
779
|
+
`data-preload="none"` is never read by either stream. To also read what is on
|
|
780
|
+
screen, merge `visibleLinks({ atMost })` in: it is opt-in, emits each address
|
|
781
|
+
once per page, at most `atMost` (8) per page, and nothing under Save-Data, on
|
|
782
|
+
a 2g connection or in a hidden tab.
|
|
783
|
+
|
|
784
|
+
```ts sketch
|
|
785
|
+
links: Stream.merge(pointedLinks(), visibleLinks({ atMost: 8 })),
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
**Code split by route.** Where a page's code is cut is written once, in the
|
|
789
|
+
page: a `Bundle.lazy` from `foldkit-bundle` keeps its `update` and `view`
|
|
790
|
+
behind an `import()` the bundler makes a chunk of, while its Model, Messages
|
|
791
|
+
and `init` stay in the boot chunk for the parent's Schema. The tree only says
|
|
792
|
+
*when* that chunk is asked for. Placed with `Site.placement`, the page carries
|
|
793
|
+
the bundle as its `code`; handed to `Site.routing`'s `pages`, the one list of
|
|
794
|
+
pages, it is named by the routing's `codeFor(route)`: the code of every page
|
|
795
|
+
on a route's chain (a nested page and the lazy page above it), none for eager
|
|
796
|
+
pages. It is pure; nothing loads until someone calls `load`. Five callers do,
|
|
797
|
+
each once per chunk:
|
|
798
|
+
|
|
799
|
+
```text
|
|
800
|
+
the reader points at a link -> preload's code: fetchCode loads codeFor(there)
|
|
801
|
+
the server renders a route -> SSR.entry's lazy: model => Routing.codeFor(model.route)
|
|
802
|
+
the browser boots that page -> SSR.hydrate's lazy, asked with the resumed Model
|
|
803
|
+
the route arrives unfetched -> the page's changed Message, which Bundle.lazy loads on
|
|
804
|
+
the app starts on that route -> init: () => Routing.boot(model), with no server render
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
```ts sketch
|
|
808
|
+
import { Site, fetchCode } from 'foldkit-site'
|
|
809
|
+
|
|
810
|
+
const Account = Bundle.lazy(
|
|
811
|
+
{ name: 'Account', Model: AccountModel, Message: AccountMessage, init },
|
|
812
|
+
() => import('./account.body.js').then(chunk => chunk.body),
|
|
813
|
+
)
|
|
814
|
+
const AccountPage = Site.placement(AccountNode, Account, {
|
|
815
|
+
link: Link.field<Model>()('account', Link.wrapper(Message.GotAccountMessage)),
|
|
816
|
+
changed: () => AccountMessage.Arrived(),
|
|
817
|
+
})
|
|
818
|
+
const Routing = Site.routing<Model, Message, AppRoute, RemoteClient>({
|
|
819
|
+
// ...site, route, parse, tags and completed, as above
|
|
820
|
+
pages: [AccountPage],
|
|
821
|
+
preload: { links: pointedLinks(), intended: Message.PointedAtLink, read, code: fetchCode },
|
|
822
|
+
})
|
|
823
|
+
// `lazy: codeOf` to both SSR.entry and SSR.hydrate.
|
|
824
|
+
const codeOf = (model: Model) => Routing.codeFor(model.route)
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
A lazy page must have `changed`, returning a Message (a type error, and
|
|
828
|
+
refused at run time past the types): a page reached by Back or a key press,
|
|
829
|
+
with nothing fetched ahead, would otherwise draw its placeholder until its
|
|
830
|
+
first Message. For the same reason an application that starts on a lazy
|
|
831
|
+
page's address with no server render starts through `Routing.boot`, which
|
|
832
|
+
tells the Model's route to its pages as an arrival; with a server render,
|
|
833
|
+
`lazy` loaded the bodies before boot. `fetchCode` is an import of its own, so
|
|
834
|
+
a site with no lazy page keeps none of it; a routing with a lazy page and a
|
|
835
|
+
`preload` without it is refused. A fetch that fails is forgotten, so the
|
|
836
|
+
arrival tries again and reports it. Once the bodies arrive, the page draws
|
|
837
|
+
them though its Model did not change. `examples/auth`'s `/account` is the
|
|
838
|
+
whole path, with a build test that keeps the bodies out of the entry chunk and
|
|
839
|
+
an e2e test that counts one request on hover. Measure before splitting: there
|
|
840
|
+
the bodies are 0.5 kB, so the split saves nothing, and the bundler's chunking
|
|
841
|
+
can cost more than it saves (that example's README says how much, and how its
|
|
842
|
+
build config avoids it).
|
|
843
|
+
|
|
759
844
|
## Limits / when not to use it
|
|
760
845
|
|
|
761
846
|
- A single-screen application has one node; the tree buys nothing.
|
package/dist/index.d.mts
CHANGED
|
@@ -46,6 +46,21 @@ export interface NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer> {
|
|
|
46
46
|
readonly viewer?: ((model: SRoot) => Option.Option<Viewer>) | undefined;
|
|
47
47
|
readonly params: (route: Route, viewer: Viewer) => SParams;
|
|
48
48
|
}
|
|
49
|
+
/** What `Site.route` annotates a node with, beside its Surface. */
|
|
50
|
+
export interface RouteOptions<Route extends {
|
|
51
|
+
readonly _tag: string;
|
|
52
|
+
}> {
|
|
53
|
+
readonly title?: ((route: Route) => string) | undefined;
|
|
54
|
+
readonly section?: string | undefined;
|
|
55
|
+
readonly landing?: Omit<Route, '_tag'> | undefined;
|
|
56
|
+
readonly shortcut?: KeySequence | undefined;
|
|
57
|
+
readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined;
|
|
58
|
+
readonly layout?: NodeLayout | undefined;
|
|
59
|
+
readonly view?: NodeView | undefined;
|
|
60
|
+
readonly meta?: NodeMeta<Route> | undefined;
|
|
61
|
+
readonly indexed?: boolean | undefined;
|
|
62
|
+
readonly access?: NodeAccess<never> | undefined;
|
|
63
|
+
}
|
|
49
64
|
/**
|
|
50
65
|
* A layout around everything under a node: it receives the composed child
|
|
51
66
|
* explicitly — no Outlet, no context, no hidden route state. Ancestors with
|
|
@@ -103,6 +118,8 @@ export interface RouteField<Root, Route> {
|
|
|
103
118
|
export interface SitePage<Parent, ParentMessage, R, P> {
|
|
104
119
|
readonly node: SiteNode<any>;
|
|
105
120
|
readonly placed: P;
|
|
121
|
+
/** The page's bodies when its Bundle is a `Bundle.lazy`, which the routing's `codeFor` names. */
|
|
122
|
+
readonly code: Option.Option<Bundle.Loadable>;
|
|
106
123
|
/**
|
|
107
124
|
* The child told of a route arrival: `None` for another node's route, for
|
|
108
125
|
* a page with nothing to say, or when the child says nothing is needed.
|
|
@@ -119,7 +136,7 @@ export interface SitePage<Parent, ParentMessage, R, P> {
|
|
|
119
136
|
*/
|
|
120
137
|
export interface SiteNode<Route extends {
|
|
121
138
|
readonly _tag: string;
|
|
122
|
-
}> {
|
|
139
|
+
}, Surfaced extends string = never> {
|
|
123
140
|
readonly tag: string;
|
|
124
141
|
readonly router: Router<Route>;
|
|
125
142
|
readonly case: RouteCase<Route>;
|
|
@@ -149,6 +166,7 @@ export interface SiteNode<Route extends {
|
|
|
149
166
|
readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined;
|
|
150
167
|
/** The Surface this route activates, if the node declares one. */
|
|
151
168
|
readonly bound?: BoundSurface | undefined;
|
|
169
|
+
readonly [surfaced]?: (tag: Surfaced) => void;
|
|
152
170
|
/** A layout wrapping everything under this node, if it declares one. */
|
|
153
171
|
readonly layout?: NodeLayout | undefined;
|
|
154
172
|
/** What this node draws for its own route, if it draws anything. */
|
|
@@ -193,16 +211,27 @@ export declare const Access: import("foldkit/schema").TaggedUnion<{
|
|
|
193
211
|
export type Access = typeof Access.Type;
|
|
194
212
|
/** Carries the routes a mount or tree holds, in its type only: nothing sets it. */
|
|
195
213
|
declare const routes: unique symbol;
|
|
196
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Carries the tags of the nodes with a Surface, in their types only: nothing
|
|
216
|
+
* sets it. `Site.sources` keys its entries by these.
|
|
217
|
+
*/
|
|
218
|
+
declare const surfaced: unique symbol;
|
|
219
|
+
/**
|
|
220
|
+
* A node mounted with its children: structure, not state. `Route` is every
|
|
221
|
+
* route it holds, `Surfaced` the tags of those whose node has a Surface.
|
|
222
|
+
*/
|
|
197
223
|
export interface SiteMount<Route extends {
|
|
198
224
|
readonly _tag: string;
|
|
199
|
-
} = any> {
|
|
225
|
+
} = any, Surfaced extends string = never> {
|
|
200
226
|
readonly node: SiteNode<any>;
|
|
201
227
|
readonly children: ReadonlyArray<SiteMount>;
|
|
202
228
|
readonly [routes]?: (route: Route) => void;
|
|
229
|
+
readonly [surfaced]?: (tag: Surfaced) => void;
|
|
203
230
|
}
|
|
204
231
|
/** The routes a bare node or a mount holds. */
|
|
205
232
|
export type RoutesOf<Mounted> = Mounted extends SiteNode<infer Route> ? Route : Mounted extends SiteMount<infer Route> ? Route : never;
|
|
233
|
+
/** The tags of the nodes with a Surface that a bare node or a mount holds. */
|
|
234
|
+
export type SurfacedOf<Mounted> = Mounted extends SiteNode<any, infer Tag> ? Tag : Mounted extends SiteMount<any, infer Tag> ? Tag : never;
|
|
206
235
|
/**
|
|
207
236
|
* A node under construction, from `Site.node`: each method annotates and
|
|
208
237
|
* returns the builder, so nodes compose in steps and annotation bundles are
|
|
@@ -212,9 +241,9 @@ export type RoutesOf<Mounted> = Mounted extends SiteNode<infer Route> ? Route :
|
|
|
212
241
|
*/
|
|
213
242
|
export interface NodeBuilder<Route extends {
|
|
214
243
|
readonly _tag: string;
|
|
215
|
-
}> {
|
|
244
|
+
}, Surfaced extends string = never> {
|
|
216
245
|
/** The node so far: frozen, usable for targets and hrefs at any stage. */
|
|
217
|
-
readonly node: SiteNode<Route>;
|
|
246
|
+
readonly node: SiteNode<Route, Surfaced>;
|
|
218
247
|
/**
|
|
219
248
|
* One named bundle through the builder, Effect-style: the bundle stays
|
|
220
249
|
* generic over the builder it meets, so it instantiates to this node's
|
|
@@ -230,29 +259,29 @@ export interface NodeBuilder<Route extends {
|
|
|
230
259
|
* Free `pipe(builder, bundle)` from `effect` composes the same way; this
|
|
231
260
|
* method is the same spelling without the import.
|
|
232
261
|
*/
|
|
233
|
-
pipe<A>(fn: (builder: NodeBuilder<Route>) => A): A;
|
|
262
|
+
pipe<A>(fn: (builder: NodeBuilder<Route, Surfaced>) => A): A;
|
|
234
263
|
/** The page's title for this route, once the route value is known. */
|
|
235
|
-
title(title: (route: Route) => string): NodeBuilder<Route>;
|
|
264
|
+
title(title: (route: Route) => string): NodeBuilder<Route, Surfaced>;
|
|
236
265
|
/** The navigation section this route belongs to. */
|
|
237
|
-
section(section: string): NodeBuilder<Route>;
|
|
266
|
+
section(section: string): NodeBuilder<Route, Surfaced>;
|
|
238
267
|
/** Where the section's nav item points, as this node's params. */
|
|
239
|
-
landing(landing: Omit<Route, '_tag'>): NodeBuilder<Route>;
|
|
268
|
+
landing(landing: Omit<Route, '_tag'>): NodeBuilder<Route, Surfaced>;
|
|
240
269
|
/** The keys that go to this node's landing. */
|
|
241
|
-
shortcut(shortcut: KeySequence): NodeBuilder<Route>;
|
|
270
|
+
shortcut(shortcut: KeySequence): NodeBuilder<Route, Surfaced>;
|
|
242
271
|
/** Which history step a move within this node is. */
|
|
243
|
-
history(history: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent)): NodeBuilder<Route>;
|
|
272
|
+
history(history: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent)): NodeBuilder<Route, Surfaced>;
|
|
244
273
|
/** A layout wrapping everything under this node. */
|
|
245
|
-
layout(layout: NodeLayout): NodeBuilder<Route>;
|
|
274
|
+
layout(layout: NodeLayout): NodeBuilder<Route, Surfaced>;
|
|
246
275
|
/** What this node draws for its own route. */
|
|
247
|
-
view(view: NodeView): NodeBuilder<Route>;
|
|
276
|
+
view(view: NodeView): NodeBuilder<Route, Surfaced>;
|
|
248
277
|
/** What this node says of itself in the head, from its route and the Model. */
|
|
249
|
-
meta<Model = any>(meta: NodeMeta<Route, Model>): NodeBuilder<Route>;
|
|
278
|
+
meta<Model = any>(meta: NodeMeta<Route, Model>): NodeBuilder<Route, Surfaced>;
|
|
250
279
|
/** Whether search engines index this node and the nodes below it. */
|
|
251
|
-
indexed(indexed: boolean): NodeBuilder<Route>;
|
|
280
|
+
indexed(indexed: boolean): NodeBuilder<Route, Surfaced>;
|
|
252
281
|
/** Who may be shown this node and the nodes below it, and where anyone else goes. */
|
|
253
|
-
access<Who>(access: NodeAccess<Who>): NodeBuilder<Route>;
|
|
282
|
+
access<Who>(access: NodeAccess<Who>): NodeBuilder<Route, Surfaced>;
|
|
254
283
|
/** The Surface this route activates, and the viewer its params read, if any. */
|
|
255
|
-
surface<SRoot, SModel, SMessage, SParams, Viewer = void>(config: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer>): NodeBuilder<Route>;
|
|
284
|
+
surface<SRoot, SModel, SMessage, SParams, Viewer = void>(config: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer>): NodeBuilder<Route, Route['_tag']>;
|
|
256
285
|
}
|
|
257
286
|
/**
|
|
258
287
|
* The deployed topology: roots with everything mounted under them, frozen.
|
|
@@ -261,9 +290,10 @@ export interface NodeBuilder<Route extends {
|
|
|
261
290
|
*/
|
|
262
291
|
export interface SiteTree<Route extends {
|
|
263
292
|
readonly _tag: string;
|
|
264
|
-
} = any> {
|
|
293
|
+
} = any, Surfaced extends string = never> {
|
|
265
294
|
readonly roots: ReadonlyArray<SiteMount>;
|
|
266
295
|
readonly [routes]?: (route: Route) => void;
|
|
296
|
+
readonly [surfaced]?: (tag: Surfaced) => void;
|
|
267
297
|
}
|
|
268
298
|
/** One address a node's `Site.paths` lists: the route's params, and when its content last changed. */
|
|
269
299
|
export interface SitePath<Route extends {
|
|
@@ -307,6 +337,43 @@ export interface SiteTarget<Route extends {
|
|
|
307
337
|
*/
|
|
308
338
|
/** What a navigation was: `history` for Back and Forward, `push` for a link or a Command. */
|
|
309
339
|
export type NavigationKind = 'history' | 'push';
|
|
340
|
+
/**
|
|
341
|
+
* What `Site.sources` gives: an entry per node with a Surface, keyed by its
|
|
342
|
+
* tag (`Surfaced`, which the tree's type carries). A node with none has no
|
|
343
|
+
* key, so a key named where the entries are keyed (`Data.wiring`'s
|
|
344
|
+
* `policies`) is one that reads. A literal key, unlike an index signature,
|
|
345
|
+
* survives a spread beside the application's own entries. Each is optional:
|
|
346
|
+
* `Site.sourcesFor` gives one chain's.
|
|
347
|
+
*/
|
|
348
|
+
export type SiteSources<Root, Surfaced extends string> = { readonly [Tag in Surfaced]?: ActiveSurface<Root> & SurfaceSource<Root>; };
|
|
349
|
+
/**
|
|
350
|
+
* How a placed page hears its route arrive: optional, and free to say nothing,
|
|
351
|
+
* for an eager Bundle; required, and always a Message, for a `Bundle.lazy`,
|
|
352
|
+
* whose bodies load on that Message.
|
|
353
|
+
*/
|
|
354
|
+
export type ChangedFor<Kind, Route, ChildMessage> = Kind extends Bundle.Loadable ? {
|
|
355
|
+
readonly changed: (route: Route) => ChildMessage;
|
|
356
|
+
} : {
|
|
357
|
+
readonly changed?: ((route: Route) => ChildMessage | undefined) | undefined;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* What fetches a route's code ahead of its arrival, given the routing's
|
|
361
|
+
* completion: `fetchCode`, passed as `Site.routing`'s `preload.code`.
|
|
362
|
+
*/
|
|
363
|
+
export type CodeFetch = <Message>(completed: () => Message) => (code: ReadonlyArray<Bundle.Loadable>) => {
|
|
364
|
+
readonly name: string;
|
|
365
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
366
|
+
readonly effect: Effect.Effect<Message>;
|
|
367
|
+
};
|
|
368
|
+
/**
|
|
369
|
+
* Loads the code of a route the reader points at, for `Site.routing`'s
|
|
370
|
+
* `preload.code`: one Command, `Site.LoadCode`, that completes with the
|
|
371
|
+
* routing's `completed` whether the chunks load or not. A load that fails is
|
|
372
|
+
* forgotten by `Bundle.lazy`, so the page's own arrival loads again and
|
|
373
|
+
* reports it; a guess at intent reports nothing. An import of its own, not a
|
|
374
|
+
* member of `Site`, so a site with no lazy page keeps none of it.
|
|
375
|
+
*/
|
|
376
|
+
export declare const fetchCode: CodeFetch;
|
|
310
377
|
export declare const Site: {
|
|
311
378
|
/**
|
|
312
379
|
* One deployed location from its Foldkit Router and its route case:
|
|
@@ -326,19 +393,9 @@ export declare const Site: {
|
|
|
326
393
|
*/
|
|
327
394
|
route: <Route extends {
|
|
328
395
|
readonly _tag: string;
|
|
329
|
-
}, SRoot, SModel, SMessage, SParams, Viewer = void>(router: Router<Route>, routeCase: RouteCase<Route>, options?: {
|
|
330
|
-
readonly title?: ((route: Route) => string) | undefined;
|
|
331
|
-
readonly section?: string | undefined;
|
|
332
|
-
readonly landing?: Omit<Route, '_tag'> | undefined;
|
|
333
|
-
readonly shortcut?: KeySequence | undefined;
|
|
334
|
-
readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined;
|
|
335
|
-
readonly layout?: NodeLayout | undefined;
|
|
336
|
-
readonly view?: NodeView | undefined;
|
|
337
|
-
readonly meta?: NodeMeta<Route> | undefined;
|
|
338
|
-
readonly indexed?: boolean | undefined;
|
|
339
|
-
readonly access?: NodeAccess<never> | undefined;
|
|
396
|
+
}, SRoot, SModel, SMessage, SParams, Viewer = void>(router: Router<Route>, routeCase: RouteCase<Route>, options?: RouteOptions<Route> & {
|
|
340
397
|
readonly surface?: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer> | undefined;
|
|
341
|
-
}) => SiteNode<Route>;
|
|
398
|
+
}) => SiteNode<Route, unknown extends SRoot ? never : Route['_tag']>;
|
|
342
399
|
/**
|
|
343
400
|
* One deployed location as an incremental builder, for nodes annotated in
|
|
344
401
|
* steps or annotations shared across nodes:
|
|
@@ -368,13 +425,13 @@ export declare const Site: {
|
|
|
368
425
|
*/
|
|
369
426
|
mount: <Route extends {
|
|
370
427
|
readonly _tag: string;
|
|
371
|
-
}, const Children extends ReadonlyArray<SiteNode<any> | SiteMount> = []>(node: SiteNode<Route>, children?: Children) => SiteMount<Route | RoutesOf<Children[number]>>;
|
|
428
|
+
}, const Children extends ReadonlyArray<SiteNode<any> | SiteMount> = [], Surfaced extends string = never>(node: SiteNode<Route, Surfaced>, children?: Children) => SiteMount<Route | RoutesOf<Children[number]>, Surfaced | SurfacedOf<Children[number]>>;
|
|
372
429
|
/**
|
|
373
430
|
* The deployed topology from its roots: bare nodes or mounts, frozen.
|
|
374
431
|
* Refuses two nodes sharing a tag and one node mounted twice, since both
|
|
375
432
|
* would make chain inspection ambiguous.
|
|
376
433
|
*/
|
|
377
|
-
make: <const Roots extends ReadonlyArray<SiteNode<any> | SiteMount>>(...roots: Roots) => SiteTree<RoutesOf<Roots[number]>>;
|
|
434
|
+
make: <const Roots extends ReadonlyArray<SiteNode<any> | SiteMount>>(...roots: Roots) => SiteTree<RoutesOf<Roots[number]>, SurfacedOf<Roots[number]>>;
|
|
378
435
|
/**
|
|
379
436
|
* One typed destination: the route value and the URL from the node's own
|
|
380
437
|
* declaration, so a link can never point where the parser would not go.
|
|
@@ -552,9 +609,12 @@ export declare const Site: {
|
|
|
552
609
|
* What the tree's surfaced nodes activate, keyed by tag, for `Data.wiring`,
|
|
553
610
|
* `Data.subscriptions`, `Data.satisfy`, or an SSR plan's `surfaces`: each
|
|
554
611
|
* node's `Surface.when` over the application's route place. A surface from
|
|
555
|
-
* another application is refused here, not at its reads.
|
|
612
|
+
* another application is refused here, not at its reads. The keys are the
|
|
613
|
+
* tags of the nodes with a Surface (`SiteSources`), so they survive a spread
|
|
614
|
+
* beside the application's own entries and can be named where the entries
|
|
615
|
+
* are keyed (`Data.wiring`'s `policies`); a surfaceless node's tag cannot.
|
|
556
616
|
*/
|
|
557
|
-
sources: <Root>(site: SiteTree, owner: object, place: ModelPlace<Root>) =>
|
|
617
|
+
sources: <Root, Surfaced extends string>(site: SiteTree<any, Surfaced>, owner: object, place: ModelPlace<Root>) => SiteSources<Root, Surfaced>;
|
|
558
618
|
/**
|
|
559
619
|
* The route-level Sources for one destination: the same entries as
|
|
560
620
|
* `Site.sources`, but only the target's chain. Prefetch, SSR, and DevTools
|
|
@@ -571,9 +631,9 @@ export declare const Site: {
|
|
|
571
631
|
* There is deliberately no `SitePlan` object: the chain is already
|
|
572
632
|
* `Site.chainOf`, and the head is `Site.metaOf`.
|
|
573
633
|
*/
|
|
574
|
-
sourcesFor: <Root>(site: SiteTree, owner: object, place: ModelPlace<Root>, route: {
|
|
634
|
+
sourcesFor: <Root, Surfaced extends string>(site: SiteTree<any, Surfaced>, owner: object, place: ModelPlace<Root>, route: {
|
|
575
635
|
readonly _tag: string;
|
|
576
|
-
}) =>
|
|
636
|
+
}) => SiteSources<Root, Surfaced>;
|
|
577
637
|
/**
|
|
578
638
|
* The application's link-click and URL-change lifecycle as one wiring, so
|
|
579
639
|
* `update` stops hand-writing those two branches. A click on a link the
|
|
@@ -659,7 +719,9 @@ export declare const Site: {
|
|
|
659
719
|
* reads what the Model would read there, the route already set:
|
|
660
720
|
* `there => Data.preload(there, actives)`. An address no node holds, or
|
|
661
721
|
* the route shown, reads nothing, and the Model is never changed: what
|
|
662
|
-
* was read lands as `read`'s own Messages.
|
|
722
|
+
* was read lands as `read`'s own Messages. With `code`, a `pages` entry
|
|
723
|
+
* that is a `Bundle.lazy` on that route's chain has its bodies fetched
|
|
724
|
+
* too, once.
|
|
663
725
|
*/
|
|
664
726
|
readonly preload?: {
|
|
665
727
|
readonly links: Stream.Stream<Url>;
|
|
@@ -667,10 +729,34 @@ export declare const Site: {
|
|
|
667
729
|
readonly url: Url;
|
|
668
730
|
}) => Message);
|
|
669
731
|
readonly read: (there: Root) => Command.Command<Message, never, R>;
|
|
732
|
+
/**
|
|
733
|
+
* Fetches the code of a `Bundle.lazy` page on the route pointed at,
|
|
734
|
+
* once, beside its read: `fetchCode`, an import of its own so a site
|
|
735
|
+
* with no lazy page keeps none of it. Required when `pages` holds a
|
|
736
|
+
* lazy page.
|
|
737
|
+
*/
|
|
738
|
+
readonly code?: CodeFetch | undefined;
|
|
670
739
|
} | undefined;
|
|
671
740
|
}) => Wiring<Root, Message, R> & {
|
|
672
741
|
/** Whether the routing owns a message: its click, its URL change, or its preload intent. */
|
|
673
742
|
readonly reduces: (message: Message) => boolean;
|
|
743
|
+
/**
|
|
744
|
+
* The code a route draws: each `Bundle.lazy` page of `pages` on its chain,
|
|
745
|
+
* root first, so a page nested under a node with lazy code of its own
|
|
746
|
+
* loads both; none for a route whose pages are eager. Pure: nothing loads
|
|
747
|
+
* until a caller calls `load`. The `lazy` of `SSR.entry`, `SSR.render`
|
|
748
|
+
* and `SSR.hydrate`, from the one list of pages the routing holds:
|
|
749
|
+
* `lazy: model => Routing.codeFor(model.route)`.
|
|
750
|
+
*/
|
|
751
|
+
readonly codeFor: (route: Route) => ReadonlyArray<Bundle.Loadable>;
|
|
752
|
+
/**
|
|
753
|
+
* The Model's route told to its pages as an arrival, for an `init` that
|
|
754
|
+
* starts on it with no server render: a `Bundle.lazy` page loads its
|
|
755
|
+
* bodies on that Message, so without it a page opened at its own address
|
|
756
|
+
* draws its placeholder for good. `init: () => Routing.boot(initial)`.
|
|
757
|
+
* A page the server rendered has its bodies loaded already (`lazy`).
|
|
758
|
+
*/
|
|
759
|
+
readonly boot: (model: Root) => Update.Return<Root, Message, R>;
|
|
674
760
|
};
|
|
675
761
|
/**
|
|
676
762
|
* One routed page stated once: its link (where its Model lives and how its
|
|
@@ -694,13 +780,17 @@ export declare const Site: {
|
|
|
694
780
|
* Message, or nothing when the arrival needs no answer. Without it the
|
|
695
781
|
* page is never informed. Bundles with OutMessages, and children that are
|
|
696
782
|
* not Bundles, stay on `Bundle.at` and `Link.child` directly.
|
|
783
|
+
*
|
|
784
|
+
* A `Bundle.lazy` page becomes the page's `code` (the routing's
|
|
785
|
+
* `codeFor`), and must have `changed`: its arrival is the Message that
|
|
786
|
+
* loads its bodies. A page opened at its own address with no server render
|
|
787
|
+
* has no arrival: its `init` starts through the routing's `boot`.
|
|
697
788
|
*/
|
|
698
789
|
placement: <Route extends {
|
|
699
790
|
readonly _tag: string;
|
|
700
|
-
}, Parent, LinkMessage extends AnyMessage, ChildModel, ChildMessage extends AnyMessage, Field extends string, Name extends string, Args, BundleR = never, BundleS = never, ViewInputs = void, Resources extends ResourceEntries<ChildModel, ChildMessage> = never, Helpers extends Readonly<Record<string, Helper<ChildModel, ChildMessage, never, BundleR>>> = never, ObserverR = never>(node: SiteNode<Route>, bundle: Bundle.Bundle<Name, Args, ChildModel, ChildMessage, never, BundleR, BundleS, ViewInputs, Resources, Helpers>, config: {
|
|
791
|
+
}, Parent, LinkMessage extends AnyMessage, ChildModel, ChildMessage extends AnyMessage, Field extends string, Name extends string, Args, BundleR = never, BundleS = never, ViewInputs = void, Resources extends ResourceEntries<ChildModel, ChildMessage> = never, Helpers extends Readonly<Record<string, Helper<ChildModel, ChildMessage, never, BundleR>>> = never, ObserverR = never, Kind = unknown>(node: SiteNode<Route>, bundle: Kind & Bundle.Bundle<Name, Args, ChildModel, ChildMessage, never, BundleR, BundleS, ViewInputs, Resources, Helpers>, config: {
|
|
701
792
|
readonly link: Link<Parent, LinkMessage, ChildModel, ChildMessage, Field>;
|
|
702
|
-
|
|
703
|
-
} & PlacementConfig<Args, Parent, LinkMessage, ChildMessage, never, never, ObserverR, SeedFor<Parent, Field>, ViewInputs>) => SitePage<Parent, LinkMessage, BundleR | ObserverR, Placed<Name, Parent, LinkMessage, ChildModel, ChildMessage, BundleR | ObserverR, BundleS, ViewInputs, Resources, Helpers, Field, LinkMessage extends {
|
|
793
|
+
} & NoInfer<ChangedFor<Kind, Route, ChildMessage>> & PlacementConfig<Args, Parent, LinkMessage, ChildMessage, never, never, ObserverR, SeedFor<Parent, Field>, ViewInputs>) => SitePage<Parent, LinkMessage, BundleR | ObserverR, Placed<Name, Parent, LinkMessage, ChildModel, ChildMessage, BundleR | ObserverR, BundleS, ViewInputs, Resources, Helpers, Field, LinkMessage extends {
|
|
704
794
|
readonly _tag: infer Tag extends string;
|
|
705
795
|
} ? Tag : string>>;
|
|
706
796
|
};
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["SurfaceType","UrlValue"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;YAwDY;;;;;;;iBAQK,UAAU;WAAyB;WAAwB,OAAO,OAAO;GACvF,cAAc;;;;;;;;;iBAUA;WACN,SAASA;;WAET,WAAW,eAAe,OAAO;WACjC,SAAS,YAAY;;;;;;;;;iBAUf,YAAY,OAAO,OAAO,QAAQ,UAAU,SAAS;WAC3D,SAASA,QAAY,OAAO,QAAQ,UAAU;WAC9C,WAAW,OAAO,UAAU,OAAO,OAAO;WAC1C,SAAS,OAAO,OAAO,QAAQ,WAAW;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["SurfaceType","UrlValue"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;YAwDY;;;;;;;iBAQK,UAAU;WAAyB;WAAwB,OAAO,OAAO;GACvF,cAAc;;;;;;;;;iBAUA;W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aAEQ,MAAM,KAAK,QAAQ,aAAa,YAAY,cAAc;MACjE,QAAQ,WAAW,MAAM,OAAO,iBAClC,gBACE,MACA,QACA,aACA,4BAGA,WACA,QAAQ,QAAQ,QAChB,gBAEH,SACD,QACA,aACA,UAAU,WACV,OACE,MACA,QACA,aACA,YACA,cACA,UAAU,WACV,SACA,YACA,WACA,SACA,OACA;aAA+B,YAAY;MAAuB"}
|
package/dist/index.mjs
CHANGED
|
@@ -115,12 +115,36 @@ const sourceOf = (node, owner, place) => {
|
|
|
115
115
|
}
|
|
116
116
|
}];
|
|
117
117
|
};
|
|
118
|
+
/** The surfaced entries among `nodes`, keyed by tag. */
|
|
119
|
+
const sourcesOn = (nodes, owner, place) => {
|
|
120
|
+
const out = {};
|
|
121
|
+
for (const node of nodes) {
|
|
122
|
+
const entry = sourceOf(node, owner, place);
|
|
123
|
+
if (entry !== void 0) out[entry[0]] = entry[1];
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
};
|
|
118
127
|
/** The fields a `Meta` gives, so one left `undefined` does not erase an ancestor's. */
|
|
119
128
|
const saidOf = (meta) => Object.fromEntries(Object.entries(meta).filter(([, value]) => value !== void 0));
|
|
120
129
|
const freezeMount = (mount) => Object.freeze({
|
|
121
130
|
node: mount.node,
|
|
122
131
|
children: Object.freeze(mount.children.map(freezeMount))
|
|
123
132
|
});
|
|
133
|
+
/**
|
|
134
|
+
* Loads the code of a route the reader points at, for `Site.routing`'s
|
|
135
|
+
* `preload.code`: one Command, `Site.LoadCode`, that completes with the
|
|
136
|
+
* routing's `completed` whether the chunks load or not. A load that fails is
|
|
137
|
+
* forgotten by `Bundle.lazy`, so the page's own arrival loads again and
|
|
138
|
+
* reports it; a guess at intent reports nothing. An import of its own, not a
|
|
139
|
+
* member of `Site`, so a site with no lazy page keeps none of it.
|
|
140
|
+
*/
|
|
141
|
+
const fetchCode = (completed) => (code) => ({
|
|
142
|
+
name: "Site.LoadCode",
|
|
143
|
+
args: { code: code.map((each) => each.name).join(", ") },
|
|
144
|
+
effect: Effect.promise(() => Promise.allSettled(code.map((each) => each.load()))).pipe(Effect.as(completed()))
|
|
145
|
+
});
|
|
146
|
+
/** Whether a Bundle is a `Bundle.lazy`, whose bodies load on demand. */
|
|
147
|
+
const isLoadable = (bundle) => "load" in bundle && typeof bundle.load === "function" && "isLoaded" in bundle && typeof bundle.isLoaded === "function";
|
|
124
148
|
/** A bare node: its tag from its route case, nothing annotated. */
|
|
125
149
|
const baseNode = (router, routeCase) => Object.freeze({
|
|
126
150
|
tag: tagOfConstructor(routeCase, "Site.route: expected a route case from defineRouteUnion"),
|
|
@@ -530,16 +554,12 @@ const Site = {
|
|
|
530
554
|
* What the tree's surfaced nodes activate, keyed by tag, for `Data.wiring`,
|
|
531
555
|
* `Data.subscriptions`, `Data.satisfy`, or an SSR plan's `surfaces`: each
|
|
532
556
|
* node's `Surface.when` over the application's route place. A surface from
|
|
533
|
-
* another application is refused here, not at its reads.
|
|
557
|
+
* another application is refused here, not at its reads. The keys are the
|
|
558
|
+
* tags of the nodes with a Surface (`SiteSources`), so they survive a spread
|
|
559
|
+
* beside the application's own entries and can be named where the entries
|
|
560
|
+
* are keyed (`Data.wiring`'s `policies`); a surfaceless node's tag cannot.
|
|
534
561
|
*/
|
|
535
|
-
sources: (site, owner, place) =>
|
|
536
|
-
const out = {};
|
|
537
|
-
for (const node of Site.nodesOf(site)) {
|
|
538
|
-
const entry = sourceOf(node, owner, place);
|
|
539
|
-
if (entry !== void 0) out[entry[0]] = entry[1];
|
|
540
|
-
}
|
|
541
|
-
return out;
|
|
542
|
-
},
|
|
562
|
+
sources: (site, owner, place) => sourcesOn(Site.nodesOf(site), owner, place),
|
|
543
563
|
/**
|
|
544
564
|
* The route-level Sources for one destination: the same entries as
|
|
545
565
|
* `Site.sources`, but only the target's chain. Prefetch, SSR, and DevTools
|
|
@@ -556,14 +576,7 @@ const Site = {
|
|
|
556
576
|
* There is deliberately no `SitePlan` object: the chain is already
|
|
557
577
|
* `Site.chainOf`, and the head is `Site.metaOf`.
|
|
558
578
|
*/
|
|
559
|
-
sourcesFor: (site, owner, place, route) =>
|
|
560
|
-
const out = {};
|
|
561
|
-
for (const node of Site.chainOf(site, route)) {
|
|
562
|
-
const entry = sourceOf(node, owner, place);
|
|
563
|
-
if (entry !== void 0) out[entry[0]] = entry[1];
|
|
564
|
-
}
|
|
565
|
-
return out;
|
|
566
|
-
},
|
|
579
|
+
sourcesFor: (site, owner, place, route) => sourcesOn(Site.chainOf(site, route), owner, place),
|
|
567
580
|
/**
|
|
568
581
|
* The application's link-click and URL-change lifecycle as one wiring, so
|
|
569
582
|
* `update` stops hand-writing those two branches. A click on a link the
|
|
@@ -616,6 +629,11 @@ const Site = {
|
|
|
616
629
|
messages: [config.completed],
|
|
617
630
|
execute: ({ href }) => Navigation.load(href).pipe(Effect.as(config.completed()))
|
|
618
631
|
});
|
|
632
|
+
const pages = config.pages ?? [];
|
|
633
|
+
const codeFor = (route) => Site.chainOf(config.site, route).flatMap((node) => pages.flatMap((page) => page.node === node ? Option.toArray(page.code) : []));
|
|
634
|
+
const fetch = preload?.code?.(config.completed);
|
|
635
|
+
if (preload !== void 0 && fetch === void 0 && pages.some((page) => Option.isSome(page.code))) throw new Error("Site.routing: a Bundle.lazy page needs preload.code (fetchCode), or nothing fetches it ahead");
|
|
636
|
+
const informed = (route) => pages.map((page) => (model) => Option.getOrElse(page.inform(model, route), () => ({ model })));
|
|
619
637
|
const sameRoute = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
620
638
|
const setRoute = (model, next) => {
|
|
621
639
|
const current = config.route.get(model);
|
|
@@ -644,9 +662,13 @@ const Site = {
|
|
|
644
662
|
const url = message.url;
|
|
645
663
|
return Option.some(Option.match(Site.routeAt(config.site, url), {
|
|
646
664
|
onNone: () => ({ model }),
|
|
647
|
-
onSome: (next) =>
|
|
648
|
-
model,
|
|
649
|
-
|
|
665
|
+
onSome: (next) => {
|
|
666
|
+
if (sameRoute(config.route.get(model), next)) return { model };
|
|
667
|
+
const unloaded = fetch === void 0 ? [] : codeFor(next).filter((code) => !code.isLoaded());
|
|
668
|
+
return {
|
|
669
|
+
model,
|
|
670
|
+
commands: [preload.read(config.route.set(model, next)), ...fetch === void 0 || unloaded.length === 0 ? [] : [fetch(unloaded)]]
|
|
671
|
+
};
|
|
650
672
|
}
|
|
651
673
|
}));
|
|
652
674
|
}
|
|
@@ -687,7 +709,7 @@ const Site = {
|
|
|
687
709
|
const steps = [
|
|
688
710
|
...navigated === void 0 ? [] : [(model) => ({ model: navigated(model, navigationKind()) })],
|
|
689
711
|
(model) => ({ model: setRoute(model, next) }),
|
|
690
|
-
...(
|
|
712
|
+
...informed(next),
|
|
691
713
|
...arrived === void 0 ? [] : [(model) => arrived(model, next)]
|
|
692
714
|
];
|
|
693
715
|
return Option.some(Update.combine(model, steps));
|
|
@@ -704,7 +726,9 @@ const Site = {
|
|
|
704
726
|
messages: [completedTag, ...intendedTag === void 0 ? [] : [intendedTag]],
|
|
705
727
|
metadata: []
|
|
706
728
|
},
|
|
707
|
-
reduces
|
|
729
|
+
reduces,
|
|
730
|
+
codeFor,
|
|
731
|
+
boot: (model) => Update.combine(model, informed(config.route.get(model)))
|
|
708
732
|
};
|
|
709
733
|
},
|
|
710
734
|
/**
|
|
@@ -729,13 +753,21 @@ const Site = {
|
|
|
729
753
|
* Message, or nothing when the arrival needs no answer. Without it the
|
|
730
754
|
* page is never informed. Bundles with OutMessages, and children that are
|
|
731
755
|
* not Bundles, stay on `Bundle.at` and `Link.child` directly.
|
|
756
|
+
*
|
|
757
|
+
* A `Bundle.lazy` page becomes the page's `code` (the routing's
|
|
758
|
+
* `codeFor`), and must have `changed`: its arrival is the Message that
|
|
759
|
+
* loads its bodies. A page opened at its own address with no server render
|
|
760
|
+
* has no arrival: its `init` starts through the routing's `boot`.
|
|
732
761
|
*/
|
|
733
762
|
placement: (node, bundle, config) => {
|
|
734
763
|
const { link, changed } = config;
|
|
764
|
+
const code = isLoadable(bundle) ? Option.some(bundle) : Option.none();
|
|
765
|
+
if (Option.isSome(code) && changed === void 0) throw new Error(`Site.placement: "${bundle.name}" is a Bundle.lazy, so its route's arrival must tell it (changed), which loads its bodies (an init on its route: the routing's boot)`);
|
|
735
766
|
const placed = bundle.at(link, config);
|
|
736
767
|
return {
|
|
737
768
|
node,
|
|
738
769
|
placed,
|
|
770
|
+
code,
|
|
739
771
|
inform: (model, route) => {
|
|
740
772
|
if (!Predicate.isTagged(route, node.tag) || changed === void 0) return Option.none();
|
|
741
773
|
const child = changed(route);
|
|
@@ -745,6 +777,6 @@ const Site = {
|
|
|
745
777
|
};
|
|
746
778
|
}
|
|
747
779
|
};
|
|
748
|
-
export { Access, Site };
|
|
780
|
+
export { Access, Site, fetchCode };
|
|
749
781
|
|
|
750
782
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Url"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-site` — the deployed route topology of a Foldkit application.\n *\n * A Site says where the application is: stable route nodes in a hierarchy,\n * each with its Foldkit Router, its metadata, and the Surfaces it activates.\n * Everything else — fetching, caching, rendering, navigation effects — stays\n * where it already is: the node compiles down to the primitives the runtime\n * already runs (`Route` biparsers, `Surface.when`, Bundle placements), so the\n * Site never becomes a second router, loader, or store.\n *\n * The rule, from the design:\n *\n * > Router says where the application is. Surface says what that state makes\n * > observable and capable. Remote says what server facts those observations\n * > require.\n *\n * Nothing here runs: nodes, mounts, trees, and targets are data. A `SiteTree`\n * is frozen at `Site.make`. `Site.routing` is the one runtime piece: the\n * link-click and URL-change lifecycle as a wiring, so applications stop\n * hand-writing those two update branches.\n */\nimport { Effect, Option, Predicate, Schema, Stream } from 'effect'\nimport {\n Bundle,\n Link,\n type AnyMessage,\n type Helper,\n type Placed,\n type PlacementConfig,\n type ResourceEntries,\n type SeedFor,\n} from 'foldkit-bundle'\nimport * as Command from 'foldkit/command'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport * as Navigation from 'foldkit/navigation'\nimport * as Subscription from 'foldkit/subscription'\nimport type { KeyBinding, KeySequence } from 'foldkit/dom'\nimport { UrlRequest } from 'foldkit/navigation'\nimport { oneOf, parseUrlWithFallback, type Router } from 'foldkit/route'\nimport type { Meta } from 'foldkit-ssr/client'\nimport * as Update from 'foldkit/update'\nimport * as Url from 'foldkit/url'\nimport type { Url as UrlValue } from 'foldkit/url'\nimport {\n ModelRef,\n Surface,\n type ActiveSurface,\n type Contract,\n type ModelPlace,\n type Surface as SurfaceType,\n type SurfaceSource,\n type Wiring,\n} from 'foldkit-surface'\n\n/** Whether moving to a target adds a history step (`push`) or replaces the current one. */\nexport type HistoryIntent = 'push' | 'replace'\n\n/**\n * A route-case constructor: the Schema for `Surface.when`, called to build\n * route values for targets. The `any` is deliberate and quarantined here:\n * every constructor of a `defineRouteUnion` case is callable with its fields,\n * and `Site.target` types the params from the route value instead.\n */\nexport interface RouteCase<Route extends { readonly _tag: string }> extends Schema.Schema<Route> {\n (params: any): Route\n}\n\n/**\n * A Surface a node activates, with the route's params made into its own: the\n * `Surface.when` a node lowers to, once the application says where its route\n * lives. The surface's own types are checked where the node is declared\n * (`Site.route` infers them); by the time sources resolve, only the owner\n * check can still fail, and it does, loudly.\n */\nexport interface BoundSurface {\n readonly surface: SurfaceType<any, any, any, any>\n /** Who is signed in, read from the Model; the Surface waits for one when given. */\n readonly viewer?: ((model: any) => Option.Option<any>) | undefined\n readonly params: (route: any, viewer: any) => any\n}\n\n/**\n * The Surface a node activates, as `Site.route` and `.surface` take it.\n * `params` reads the node's route; with `viewer`, it reads the signed-in\n * viewer too, and the Surface is active only once `viewer` gives one.\n * Without `viewer`, `Viewer` is `void`, so a `params` reading a viewer it was\n * never given does not compile.\n */\nexport interface NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer> {\n readonly surface: SurfaceType<SRoot, SModel, SMessage, SParams>\n readonly viewer?: ((model: SRoot) => Option.Option<Viewer>) | undefined\n readonly params: (route: Route, viewer: Viewer) => SParams\n}\n\n/**\n * A layout around everything under a node: it receives the composed child\n * explicitly — no Outlet, no context, no hidden route state. Ancestors with\n * layouts wrap the leaf's view root-first; ancestors without one pass\n * through. The `any` positions are deliberate and quarantined, as with\n * `BoundSurface`: annotate the function where it is declared and it checks\n * there.\n */\nexport interface NodeLayout {\n readonly render: (child: Html, model: any, h: any) => Html\n}\n\n/**\n * What a node draws for its own route: only the deepest node of the active\n * chain draws (its ancestors contribute layouts, never their views — a\n * person page shows no people list). Same `any` quarantine as `NodeLayout`.\n */\nexport interface NodeView {\n readonly render: (model: any, h: any) => Html\n}\n\n/**\n * What a node says of itself in the document's head, from its route value and\n * the Model (a post's excerpt is in the Model, not the route). The node keeps\n * it with the Model as `any`, quarantined as `NodeLayout`'s is: name the Model\n * where it is declared (`.meta<Model>(...)`) and it checks there.\n */\nexport type NodeMeta<Route, Model = any> = (page: {\n readonly route: Route\n readonly model: Model\n}) => Meta\n\n/**\n * The route's place in the Model, read and written. A field holding a tagged\n * union is a *union of* `FieldRef`s, one per case, which no single\n * `ModelRef<Root, Route>` accepts — so this is structural:\n *\n * ```ts\n * route: {\n * dependency: ModelRef.focus(App.model.route).dependency,\n * get: (model) => model.route,\n * set: (model, route) => modifyFields(model, { route: () => route }),\n * },\n * ```\n */\nexport interface RouteField<Root, Route> {\n readonly dependency: readonly string[]\n readonly get: (root: Root) => Route\n readonly set: (root: Root, route: Route) => Root\n}\n\n/**\n * One routed page: its node, its Bundle placement, and how a route arrival\n * reaches the child. The placement drives both folds from one declaration —\n * `placed.update` for Messages, `placed.view` for drawing — and `inform`\n * tells the child when its route arrives, through its own Message. The\n * placement's full type rides along, so assemblies keep inferring services.\n */\nexport interface SitePage<Parent, ParentMessage, R, P> {\n readonly node: SiteNode<any>\n readonly placed: P\n /**\n * The child told of a route arrival: `None` for another node's route, for\n * a page with nothing to say, or when the child says nothing is needed.\n */\n readonly inform: (\n model: Parent,\n route: { readonly _tag: string },\n ) => Option.Option<Update.Return<Parent, ParentMessage, R>>\n}\n\n/**\n * One deployed location: its Router (which owns URL semantics), its route\n * case, and its metadata. A stable first-class value: mounting it in a tree\n * never mutates it, so the same node serves targets, hrefs, and inspection\n * wherever it is mounted.\n */\nexport interface SiteNode<Route extends { readonly _tag: string }> {\n readonly tag: string\n readonly router: Router<Route>\n readonly case: RouteCase<Route>\n /** The page's title for this route, once the route value is known. */\n readonly title?: ((route: Route) => string) | undefined\n /** The navigation section this route belongs to, for menus and breadcrumbs. */\n readonly section?: string | undefined\n /**\n * Where the section's nav item points: this node's params for its landing\n * address (a people list with no search, say). Nodes a section never lands\n * on — a person, a file — leave it absent; `Site.landing` reads the first\n * node of a section that declares one.\n */\n readonly landing?: Omit<Route, '_tag'> | undefined\n /**\n * The keys that go to this node's `landing`, as Foldkit's key bindings name\n * them: one press (`'/'`, `'Mod+K'`) or a sequence (`['G', 'H']`).\n * `Site.shortcuts` makes the bindings.\n */\n readonly shortcut?: KeySequence | undefined\n /**\n * Which history step a move within this node is: a string, or a function\n * for nodes where some param changes are entries of their own (another\n * person) and others are views of one entry (another search). A move to\n * another node — or from an unknown location — is always a step.\n */\n readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined\n /** The Surface this route activates, if the node declares one. */\n readonly bound?: BoundSurface | undefined\n /** A layout wrapping everything under this node, if it declares one. */\n readonly layout?: NodeLayout | undefined\n /** What this node draws for its own route, if it draws anything. */\n readonly view?: NodeView | undefined\n /** What this node says of itself in the head; nodes below override it per field. */\n readonly meta?: NodeMeta<Route> | undefined\n /**\n * Whether search engines index this node and, unless they say otherwise,\n * the nodes below it. Undeclared up the whole chain, a node is indexed.\n */\n readonly indexed?: boolean | undefined\n /**\n * Who may be shown this node and the nodes below it: see `Site.accessOf`.\n * Held as `never` for its reader, so a rule given in the options must\n * name the reader it reads (`allow: (me: Me) => …`).\n */\n readonly access?: NodeAccess<never> | undefined\n}\n\n/**\n * Who may be shown a node, and where anyone else is sent. Presentation, not\n * authorization: the server guards what the page reads whatever this says.\n * `Who` is what the application knows of the reader (its `Me` row, say).\n */\nexport interface NodeAccess<Who> {\n readonly allow: (who: Who) => boolean\n /** Where a reader `allow` refuses goes, given the address they asked for (a sign-in page returning to it). */\n readonly otherwise: (requested: string) => SiteTarget<any>\n}\n\n/**\n * Whether the reader may be shown a route: `Allowed`; `Pending` while the\n * application does not know who they are yet, to draw a loading state rather\n * than flash the sign-in page at someone signed in; `Denied` with the address\n * to send them to.\n */\nexport const Access = defineTaggedUnion({\n Allowed: {},\n Pending: {},\n Denied: { url: Schema.String },\n})\nexport type Access = typeof Access.Type\n\n/** Carries the routes a mount or tree holds, in its type only: nothing sets it. */\ndeclare const routes: unique symbol\n\n/** A node mounted with its children: structure, not state. `Route` is every route it holds. */\nexport interface SiteMount<Route extends { readonly _tag: string } = any> {\n readonly node: SiteNode<any>\n readonly children: ReadonlyArray<SiteMount>\n readonly [routes]?: (route: Route) => void\n}\n\n/** The routes a bare node or a mount holds. */\nexport type RoutesOf<Mounted> =\n Mounted extends SiteNode<infer Route>\n ? Route\n : Mounted extends SiteMount<infer Route>\n ? Route\n : never\n\n/**\n * A node under construction, from `Site.node`: each method annotates and\n * returns the builder, so nodes compose in steps and annotation bundles are\n * ordinary values. Methods — not pipeable fragments — because each stage of\n * a pipe is a separate generic call and could not infer the route. Read\n * `.node` at any stage for the frozen node so far.\n */\nexport interface NodeBuilder<Route extends { readonly _tag: string }> {\n /** The node so far: frozen, usable for targets and hrefs at any stage. */\n readonly node: SiteNode<Route>\n /**\n * One named bundle through the builder, Effect-style: the bundle stays\n * generic over the builder it meets, so it instantiates to this node's\n * route with no annotation. Chain for more than one.\n *\n * ```ts\n * const inSection = <R extends { readonly _tag: string }>(b: NodeBuilder<R>) =>\n * b.section('People').shortcut(['G', 'P'])\n *\n * const Person = Site.node(personRouter, AppRoute.Person).pipe(inSection).node\n * ```\n *\n * Free `pipe(builder, bundle)` from `effect` composes the same way; this\n * method is the same spelling without the import.\n */\n pipe<A>(fn: (builder: NodeBuilder<Route>) => A): A\n /** The page's title for this route, once the route value is known. */\n title(title: (route: Route) => string): NodeBuilder<Route>\n /** The navigation section this route belongs to. */\n section(section: string): NodeBuilder<Route>\n /** Where the section's nav item points, as this node's params. */\n landing(landing: Omit<Route, '_tag'>): NodeBuilder<Route>\n /** The keys that go to this node's landing. */\n shortcut(shortcut: KeySequence): NodeBuilder<Route>\n /** Which history step a move within this node is. */\n history(\n history: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent),\n ): NodeBuilder<Route>\n /** A layout wrapping everything under this node. */\n layout(layout: NodeLayout): NodeBuilder<Route>\n /** What this node draws for its own route. */\n view(view: NodeView): NodeBuilder<Route>\n /** What this node says of itself in the head, from its route and the Model. */\n meta<Model = any>(meta: NodeMeta<Route, Model>): NodeBuilder<Route>\n /** Whether search engines index this node and the nodes below it. */\n indexed(indexed: boolean): NodeBuilder<Route>\n /** Who may be shown this node and the nodes below it, and where anyone else goes. */\n access<Who>(access: NodeAccess<Who>): NodeBuilder<Route>\n /** The Surface this route activates, and the viewer its params read, if any. */\n surface<SRoot, SModel, SMessage, SParams, Viewer = void>(\n config: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer>,\n ): NodeBuilder<Route>\n}\n\n/**\n * The deployed topology: roots with everything mounted under them, frozen.\n * `Route` is the union of every node's route, so the tree parses an address\n * to it (`Site.parse`) and builds one back (`Site.hrefOf`).\n */\nexport interface SiteTree<Route extends { readonly _tag: string } = any> {\n readonly roots: ReadonlyArray<SiteMount>\n readonly [routes]?: (route: Route) => void\n}\n\n/** One address a node's `Site.paths` lists: the route's params, and when its content last changed. */\nexport interface SitePath<Route extends { readonly _tag: string }> {\n readonly params: Omit<Route, '_tag'>\n /** When what the page shows last changed, as ISO 8601 text, for a sitemap. */\n readonly modified?: string | undefined\n}\n\n/** A node's addresses, listed by an Effect the build runs: from `Site.paths`. */\nexport interface SitePaths<E, R> {\n readonly node: SiteNode<any>\n readonly list: Effect.Effect<ReadonlyArray<SitePath<any>>, E, R>\n}\n\n/** How a listing of `SitePaths` can fail: each one's error, and none for no paths. */\nexport type PathsError<Paths> = Paths extends SitePaths<infer E, any> ? E : never\n/** What a listing of `SitePaths` needs: each one's services, and none for no paths. */\nexport type PathsServices<Paths> = Paths extends SitePaths<any, infer R> ? R : never\n\n/** One address of the whole site, from `Site.targets`: a target, and when it last changed. */\nexport interface SiteListed<Route extends { readonly _tag: string }> extends SiteTarget<Route> {\n readonly modified?: string | undefined\n}\n\n/**\n * One typed destination: the node, the route value, and the URL, all from one\n * declaration. Links, prefetch, and route analysis share this instead of each\n * rebuilding it.\n */\nexport interface SiteTarget<Route extends { readonly _tag: string }> {\n readonly node: SiteNode<Route>\n readonly route: Route\n readonly url: string\n}\n\n/**\n * The tag a tagged constructor names, read the way `Surface.when` reads it\n * off a route case. Anything else is a definition-time error, not a silent\n * mismatch.\n */\n/** What a navigation was: `history` for Back and Forward, `push` for a link or a Command. */\nexport type NavigationKind = 'history' | 'push'\n\n/**\n * The kind of the URL change being reduced. Foldkit reduces its Message on\n * the stack of the event that caused it: the browser's `popstate` for Back\n * and Forward, `foldkit:urlchange` for a URL a Command wrote. A change\n * reduced off that stack (a drain deferred past Foldkit's budget) reads as\n * `push`, which only refetches what a history navigation would have shown\n * as it was.\n */\nconst navigationKind = (): NavigationKind =>\n typeof window !== 'undefined' && window.event?.type === 'popstate' ? 'history' : 'push'\n\nconst tagOfConstructor = (constructor: unknown, what: string): string => {\n const literal = (constructor as { fields?: { _tag?: { ast?: { literal?: unknown } } } }).fields\n ?._tag?.ast?.literal\n if (typeof literal !== 'string') throw new Error(`${what} must be a tagged constructor`)\n return literal\n}\n\ninterface SiteIndex {\n readonly parent: ReadonlyMap<SiteNode<any>, SiteNode<any> | undefined>\n readonly byTag: ReadonlyMap<string, SiteNode<any>>\n /** The route the first node in tree order reads at an address, or nothing. */\n readonly read: (url: UrlValue) => Option.Option<any>\n}\n\nconst indexes = new WeakMap<SiteTree, SiteIndex>()\n\n/** The parent and tag maps and the parser of a tree, computed once per tree value. */\nconst indexOf = (site: SiteTree): SiteIndex => {\n const known = indexes.get(site)\n if (known !== undefined) return known\n const parent = new Map<SiteNode<any>, SiteNode<any> | undefined>()\n const byTag = new Map<string, SiteNode<any>>()\n const visit = (mount: SiteMount, above: SiteNode<any> | undefined): void => {\n if (parent.has(mount.node))\n throw new Error(\n `Site.make: \"${mount.node.tag}\" is mounted twice; a node has one place in a tree`,\n )\n const knownTag = byTag.get(mount.node.tag)\n if (knownTag !== undefined && knownTag !== mount.node)\n throw new Error(\n `Site.make: two nodes share the tag \"${mount.node.tag}\"; one route case is one node`,\n )\n parent.set(mount.node, above)\n byTag.set(mount.node.tag, mount.node)\n for (const child of mount.children) visit(child, mount.node)\n }\n for (const root of site.roots) visit(root, undefined)\n // Foldkit's parser takes only a fallback, so no match falls back to `None`.\n const parser = parseUrlWithFallback<any, Option.Option<any>>(\n oneOf(...[...parent.keys()].map(node => node.router)),\n { make: () => Option.none() },\n )\n const read = (url: UrlValue): Option.Option<any> => {\n const parsed = parser(url)\n return Option.isOption(parsed) ? parsed : Option.some(parsed)\n }\n const index = { parent, byTag, read }\n indexes.set(site, index)\n return index\n}\n\n/** Whether a node's route has params beyond its tag, so its addresses must be listed. */\nconst takesParams = (node: SiteNode<any>): boolean =>\n Object.keys((node.case as { fields?: object }).fields ?? {}).some(field => field !== '_tag')\n\nconst asMount = (node: SiteNode<any> | SiteMount): SiteMount =>\n 'children' in node ? node : { node, children: [] }\n\n/**\n * One surfaced node's `Surface.when` over the route place, or nothing\n * surfaceless. A node reading the viewer is active on its route only while\n * the viewer is known, and keeps the route's tag as its activation.\n */\nconst sourceOf = <Root>(\n node: SiteNode<any>,\n owner: object,\n place: ModelPlace<Root>,\n): [string, ActiveSurface<Root> & SurfaceSource<Root>] | undefined => {\n const bound = node.bound\n if (bound === undefined) return undefined\n const { surface, viewer, params } = bound\n if (surface.owner !== owner)\n throw new Error(`Site: \"${surface.name}\" belongs to another application than the site`)\n if (viewer === undefined)\n return [node.tag, Surface.when(surface, place, node.case, route => params(route, undefined))]\n const focus = ModelRef.focus(place)\n const gated = Surface.at(surface, (model: Root) => {\n const route = focus.get(model)\n return Predicate.isTagged(route, node.tag)\n ? Option.map(viewer(model), who => params(route, who))\n : Option.none()\n })\n return [node.tag, { ...gated, activation: { path: focus.dependency, tag: node.tag } }]\n}\n\n/** The fields a `Meta` gives, so one left `undefined` does not erase an ancestor's. */\nconst saidOf = (meta: Meta): Meta =>\n Object.fromEntries(Object.entries(meta).filter(([, value]) => value !== undefined))\n\nconst freezeMount = (mount: SiteMount): SiteMount =>\n Object.freeze({\n node: mount.node,\n children: Object.freeze(mount.children.map(freezeMount)),\n })\n\n/** A bare node: its tag from its route case, nothing annotated. */\nconst baseNode = <Route extends { readonly _tag: string }>(\n router: Router<Route>,\n routeCase: RouteCase<Route>,\n): SiteNode<Route> =>\n Object.freeze({\n tag: tagOfConstructor(routeCase, 'Site.route: expected a route case from defineRouteUnion'),\n router,\n case: routeCase,\n })\n\nexport const Site = {\n /**\n * One deployed location from its Foldkit Router and its route case:\n *\n * ```ts\n * const Person = Site.route(personRouter, AppRoute.Person, {\n * title: ({ personId }) => `Person ${personId} | Routing`,\n * section: 'People',\n * })\n * ```\n *\n * The router stays the whole URL story (parse and build); the case names\n * the tag and builds route values. Metadata is annotated once here, and\n * navigation, titles, and history derive from it. To share annotations\n * across nodes, or to build incrementally, use the `Site.node` builder\n * instead — these options are sugar over it.\n */\n route: <Route extends { readonly _tag: string }, SRoot, SModel, SMessage, SParams, Viewer = void>(\n router: Router<Route>,\n routeCase: RouteCase<Route>,\n options?: {\n readonly title?: ((route: Route) => string) | undefined\n readonly section?: string | undefined\n readonly landing?: Omit<Route, '_tag'> | undefined\n readonly shortcut?: KeySequence | undefined\n readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined\n readonly layout?: NodeLayout | undefined\n readonly view?: NodeView | undefined\n readonly meta?: NodeMeta<Route> | undefined\n readonly indexed?: boolean | undefined\n readonly access?: NodeAccess<never> | undefined\n readonly surface?: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer> | undefined\n },\n ): SiteNode<Route> => {\n let built = Site.node(router, routeCase)\n if (options?.title !== undefined) built = built.title(options.title)\n if (options?.section !== undefined) built = built.section(options.section)\n if (options?.landing !== undefined) built = built.landing(options.landing)\n if (options?.shortcut !== undefined) built = built.shortcut(options.shortcut)\n if (options?.history !== undefined) built = built.history(options.history)\n if (options?.layout !== undefined) built = built.layout(options.layout)\n if (options?.view !== undefined) built = built.view(options.view)\n if (options?.meta !== undefined) built = built.meta(options.meta)\n if (options?.indexed !== undefined) built = built.indexed(options.indexed)\n if (options?.access !== undefined) built = built.access(options.access)\n if (options?.surface !== undefined)\n built = built.surface<SRoot, SModel, SMessage, SParams, Viewer>(options.surface)\n return built.node\n },\n\n /**\n * One deployed location as an incremental builder, for nodes annotated in\n * steps or annotations shared across nodes:\n *\n * ```ts\n * const Person = Site.node(personRouter, AppRoute.Person)\n * .title(({ personId }) => `Person ${personId} | Routing`)\n * .section('People')\n * .node\n * ```\n *\n * Methods — not pipeable fragments — because a pipeable fragment cannot\n * infer the route: each stage is a separate generic call, so its type\n * parameter falls back to the constraint and a typed callback no longer\n * matches. A method already knows its node's route, so inline lambdas\n * infer with no annotation. Read `.node` at any stage: every step freezes,\n * so intermediates are usable nodes too (targets, hrefs), never drafts.\n * `Site.route`'s options are sugar over this builder — one implementation.\n */\n node: <Route extends { readonly _tag: string }>(\n router: Router<Route>,\n routeCase: RouteCase<Route>,\n ): NodeBuilder<Route> => {\n const at = (built: SiteNode<Route>): NodeBuilder<Route> => ({\n node: built,\n pipe: <A>(fn: (builder: NodeBuilder<Route>) => A): A => fn(at(built)),\n title: title => at(Object.freeze({ ...built, title })),\n section: section => at(Object.freeze({ ...built, section })),\n landing: landing => at(Object.freeze({ ...built, landing })),\n shortcut: shortcut => at(Object.freeze({ ...built, shortcut })),\n history: history => at(Object.freeze({ ...built, history })),\n layout: layout => at(Object.freeze({ ...built, layout })),\n view: view => at(Object.freeze({ ...built, view })),\n meta: meta => at(Object.freeze({ ...built, meta })),\n indexed: indexed => at(Object.freeze({ ...built, indexed })),\n access: access => at(Object.freeze({ ...built, access })),\n surface: config => at(Object.freeze({ ...built, bound: config as BoundSurface })),\n })\n return at(baseNode(router, routeCase))\n },\n\n /**\n * A node with its children. Returns a mount; the node itself is untouched,\n * so it stays usable bare for targets and hrefs. Children may be bare\n * nodes (childless) or mounts.\n */\n mount: <\n Route extends { readonly _tag: string },\n const Children extends ReadonlyArray<SiteNode<any> | SiteMount> = [],\n >(\n node: SiteNode<Route>,\n children?: Children,\n ): SiteMount<Route | RoutesOf<Children[number]>> =>\n Object.freeze({ node, children: Object.freeze((children ?? []).map(asMount)) }),\n\n /**\n * The deployed topology from its roots: bare nodes or mounts, frozen.\n * Refuses two nodes sharing a tag and one node mounted twice, since both\n * would make chain inspection ambiguous.\n */\n make: <const Roots extends ReadonlyArray<SiteNode<any> | SiteMount>>(\n ...roots: Roots\n ): SiteTree<RoutesOf<Roots[number]>> => {\n const tree: SiteTree<RoutesOf<Roots[number]>> = Object.freeze({\n roots: Object.freeze(roots.map(asMount).map(freezeMount)),\n })\n // Fail at definition time, not at the first inspection.\n indexOf(tree)\n return tree\n },\n\n /**\n * One typed destination: the route value and the URL from the node's own\n * declaration, so a link can never point where the parser would not go.\n */\n target: <Route extends { readonly _tag: string }>(\n node: SiteNode<Route>,\n params: Omit<Route, '_tag'>,\n ): SiteTarget<Route> => ({\n node,\n route: node.case(params),\n url: node.router.build(params),\n }),\n\n /** The URL of a target, or of a node with params directly. */\n href: (<Route extends { readonly _tag: string }>(\n targetOrNode: SiteTarget<Route> | SiteNode<Route>,\n params?: Omit<Route, '_tag'>,\n ): string => {\n if ('url' in targetOrNode) return targetOrNode.url\n if (params === undefined)\n throw new Error(`Site.href: \"${targetOrNode.tag}\" needs params to build its URL`)\n return Site.target(targetOrNode, params).url\n }) as {\n <Route extends { readonly _tag: string }>(target: SiteTarget<Route>): string\n <Route extends { readonly _tag: string }>(\n node: SiteNode<Route>,\n params: Omit<Route, '_tag'>,\n ): string\n },\n\n /**\n * The tree's parser: an address to the route of the first node, in tree\n * order (depth-first, parents first), whose router takes all of it, or the\n * fallback. A router that takes any segment (`/:slug`) belongs after the\n * nodes whose literal it would take too. With `Site.hrefOf`, the tree is\n * the one declaration of both directions.\n */\n parse: <Route extends { readonly _tag: string }, Fallback>(\n site: SiteTree<Route>,\n fallback: { readonly make: (data: { readonly path: string }) => Fallback },\n ): ((url: UrlValue) => Route | Fallback) => {\n const { read } = indexOf(site)\n return (url): Route | Fallback =>\n Option.getOrElse(read(url), () => fallback.make({ path: url.pathname }))\n },\n\n /**\n * The route the tree reads at an address, as `Site.parse` does, or nothing\n * when no node takes it: an address the tree does not hold is another\n * document's, which a link reaches with a full load.\n */\n routeAt: <Route extends { readonly _tag: string }>(\n site: SiteTree<Route>,\n url: UrlValue,\n ): Option.Option<Route> => indexOf(site).read(url),\n\n /**\n * The address of a route the tree holds, built by its node's router, so it\n * parses back to the same route (`Site.parse`).\n */\n hrefOf: <Route extends { readonly _tag: string }>(\n site: SiteTree<Route>,\n route: Route,\n ): string => {\n const node = indexOf(site).byTag.get(route._tag)\n if (node === undefined) throw new Error(`Site.hrefOf: no node holds the tag \"${route._tag}\"`)\n const { _tag, ...params } = route\n return node.router.build(params)\n },\n\n /**\n * A node's addresses, from data: every published post is one. `list` is an\n * Effect the build runs, such as a Remote query read through\n * `Data.satisfy`, so it lists what a visitor may see.\n *\n * ```ts\n * const posts = Site.paths(PostNode, listPosts.pipe(\n * Effect.map(rows => rows.map(row => ({ params: { slug: row.slug }, modified: row.at }))),\n * ))\n * ```\n */\n paths: <Route extends { readonly _tag: string }, E, R>(\n node: SiteNode<Route>,\n list: Effect.Effect<ReadonlyArray<SitePath<Route>>, E, R>,\n ): SitePaths<E, R> => ({ node, list }),\n\n /**\n * Every address of the site, in tree order: one for each node whose route\n * has no params, and what `paths` lists for each node whose route has\n * them. What a build renders, a sitemap lists (with `Site.indexedOf`), and\n * a prefetch warms. A node with params and no `paths` is refused, as are\n * `paths` for a node the tree does not hold or twice for one node, so no\n * page is left out unsaid; `Site.paths(node, Effect.succeed([]))` lists none.\n */\n targets: <const Paths extends ReadonlyArray<SitePaths<any, any>>>(\n site: SiteTree,\n paths: Paths,\n ): Effect.Effect<\n ReadonlyArray<SiteListed<any>>,\n PathsError<Paths[number]>,\n PathsServices<Paths[number]>\n > => {\n const nodes = Site.nodesOf(site)\n const listed = new Map<SiteNode<any>, SitePaths<any, any>>()\n for (const each of paths) {\n if (!nodes.includes(each.node))\n throw new Error(`Site.targets: \"${each.node.tag}\" has paths but is not in the tree`)\n if (listed.has(each.node)) throw new Error(`Site.targets: \"${each.node.tag}\" has paths twice`)\n listed.set(each.node, each)\n }\n const unlisted = nodes.filter(node => takesParams(node) && !listed.has(node))\n if (unlisted.length > 0)\n throw new Error(\n `Site.targets: ${unlisted.map(node => `\"${node.tag}\"`).join(', ')} take params and have no paths`,\n )\n return Effect.map(\n Effect.forEach(\n nodes,\n node => {\n const source = listed.get(node)\n if (source === undefined) return Effect.succeed([Site.target(node, {})])\n return Effect.map(source.list, found =>\n found.map(({ params, modified }) => ({\n ...Site.target(node, params),\n ...(modified === undefined ? {} : { modified }),\n })),\n )\n },\n { concurrency: 'unbounded' },\n ),\n perNode => perNode.flat(),\n )\n },\n\n /** Every node in the tree, depth-first, parents before children. */\n nodesOf: (site: SiteTree): ReadonlyArray<SiteNode<any>> => {\n const out: Array<SiteNode<any>> = []\n const visit = (mount: SiteMount): void => {\n out.push(mount.node)\n for (const child of mount.children) visit(child)\n }\n for (const root of site.roots) visit(root)\n return out\n },\n\n /** The node a route value is on, or nothing for a tag the tree does not hold. */\n nodeOf: (site: SiteTree, route: { readonly _tag: string }): SiteNode<any> | undefined =>\n indexOf(site).byTag.get(route._tag),\n\n /** The chain a route value is on, root first; none for an unknown tag. */\n chainOf: (site: SiteTree, route: { readonly _tag: string }): ReadonlyArray<SiteNode<any>> => {\n const { parent, byTag } = indexOf(site)\n const node = byTag.get(route._tag)\n if (node === undefined) return []\n const chain: Array<SiteNode<any>> = [node]\n let above = parent.get(node)\n while (above !== undefined) {\n chain.unshift(above)\n above = parent.get(above)\n }\n return chain\n },\n\n /** The node above this one in the tree, or nothing at a root. */\n parentOf: (site: SiteTree, node: SiteNode<any>): SiteNode<any> | undefined =>\n indexOf(site).parent.get(node),\n\n /** Every node above this one, root first. */\n ancestorsOf: (site: SiteTree, node: SiteNode<any>): ReadonlyArray<SiteNode<any>> => {\n const { parent } = indexOf(site)\n const out: Array<SiteNode<any>> = []\n let above = parent.get(node)\n while (above !== undefined) {\n out.unshift(above)\n above = parent.get(above)\n }\n return out\n },\n\n /** How deep the node sits: a root is 0, its children 1. */\n depthOf: (site: SiteTree, node: SiteNode<any>): number => Site.ancestorsOf(site, node).length,\n\n /** The title the tree annotates for a route value, or nothing. */\n titleOf: (site: SiteTree, route: { readonly _tag: string }): string | undefined => {\n const node = indexOf(site).byTag.get(route._tag)\n return node?.title?.(route)\n },\n\n /**\n * Whether search engines index a route: the nearest declaration up its\n * chain, so a `noindex` studio covers every node below it. A route the tree\n * does not hold is indexed, as a page with no declaration is.\n */\n indexedOf: (site: SiteTree, route: { readonly _tag: string }): boolean => {\n const chain = Site.chainOf(site, route)\n for (let at = chain.length - 1; at >= 0; at--) {\n const indexed = chain[at]!.indexed\n if (indexed !== undefined) return indexed\n }\n return true\n },\n\n /**\n * Whether the reader may be shown a route: every `access` up its chain,\n * root first, must allow `who`, and the first that refuses sends them to\n * its `otherwise`, given the route's address. `who` is `Option.none()`\n * while the application does not know yet (its `Me` loading): `Pending`\n * wherever a rule would need it. A route no rule covers is `Allowed`.\n *\n * ```ts\n * Access.match(Site.accessOf(AppSite, model.route, me), {\n * Allowed: () => page,\n * Pending: () => loading,\n * Denied: ({ url }) => redirecting, // and `update` replaces the URL with `url`\n * })\n * ```\n *\n * A server answers `Denied` with a 303 to `url` before rendering. It is\n * presentation: what the page reads is guarded on the server regardless.\n */\n accessOf: <Route extends { readonly _tag: string }, Who>(\n site: SiteTree<Route>,\n route: Route,\n who: Option.Option<Who>,\n ): Access => {\n for (const node of Site.chainOf(site, route)) {\n const { access } = node\n if (access === undefined) continue\n if (Option.isNone(who)) return Access.Pending()\n // The tree holds its rules' readers as `never`: `who` is the reader they read.\n if ((access as NodeAccess<Who>).allow(who.value)) continue\n const target = access.otherwise(Site.hrefOf(site, route))\n // A target this same rule covers refuses the reader again, for ever.\n if (Site.chainOf(site, target.route).includes(node))\n throw new Error(\n `foldkit-site: ${node.tag}'s access sends a refused reader to ${target.url}, which it also covers`,\n )\n return Access.Denied({ url: target.url })\n }\n return Access.Allowed()\n },\n\n /**\n * What a route says of itself in the head, for an SSR plan's `meta`:\n *\n * ```ts\n * SSR.plan(App, { id: 'site', state, meta: model => Site.metaOf(AppSite, model.route, model) })\n * ```\n *\n * Each node of the chain's `meta`, root first, with a deeper node's field\n * replacing its ancestor's and a field it leaves out keeping the ancestor's.\n * The preview title falls back to the route's `title`. An unindexed route\n * (`Site.indexedOf`) is `noindex` whatever its `meta` says.\n */\n metaOf: <Root>(site: SiteTree, route: { readonly _tag: string }, model: Root): Meta => {\n let meta: Meta = {}\n for (const node of Site.chainOf(site, route))\n if (node.meta !== undefined) meta = { ...meta, ...saidOf(node.meta({ route, model })) }\n const title = meta.title ?? Site.titleOf(site, route)\n return {\n ...meta,\n ...(title === undefined ? {} : { title }),\n ...(Site.indexedOf(site, route) ? {} : { robots: 'noindex' }),\n }\n },\n\n /** The navigation section the tree annotates for a route value, or nothing. */\n sectionOf: (site: SiteTree, route: { readonly _tag: string }): string | undefined =>\n indexOf(site).byTag.get(route._tag)?.section,\n\n /**\n * Where a section's nav item points: the first node of the section with a\n * landing, as a target. Nothing when no node of the section declares one —\n * every section shown needs a landing, so navigation asserts it.\n */\n landing: (site: SiteTree, section: string): SiteTarget<any> | undefined => {\n for (const candidate of Site.nodesOf(site)) {\n if (candidate.section !== section) continue\n const landing = candidate.landing\n if (landing === undefined) continue\n return Site.target(candidate, landing)\n }\n return undefined\n },\n\n /**\n * The tree's shortcuts as key bindings, each sending the Message\n * `toMessage` makes of its node's landing:\n *\n * ```ts\n * Dom.streamFromKeyBindings({\n * bindings: Site.shortcuts(AppSite, target => Message.PressedShortcut({ url: target.url })),\n * })\n * ```\n *\n * A shortcut on a node with no `landing` goes nowhere, and one used twice\n * goes to two places; both are refused.\n */\n shortcuts: <Message>(\n site: SiteTree,\n toMessage: (target: SiteTarget<any>) => Message,\n ): ReadonlyArray<KeyBinding<Message>> => {\n const taken = new Map<string, string>()\n return Site.nodesOf(site).flatMap((node): ReadonlyArray<KeyBinding<Message>> => {\n const keys = node.shortcut\n if (keys === undefined) return []\n if (node.landing === undefined)\n throw new Error(`Site.shortcuts: \"${node.tag}\" has a shortcut and no landing to go to`)\n const named = typeof keys === 'string' ? keys : keys.join(' ')\n const other = taken.get(named)\n if (other !== undefined)\n throw new Error(`Site.shortcuts: \"${named}\" goes to both \"${other}\" and \"${node.tag}\"`)\n taken.set(named, node.tag)\n const message = toMessage(Site.target(node, node.landing))\n const mapEvent = () => message\n // The binding's two shapes are told apart by `keys`, so each is made whole.\n return [typeof keys === 'string' ? { keys, mapEvent } : { keys, mapEvent }]\n })\n },\n\n /**\n * Which history step a move is: to another node, a step; within a node, its\n * declaration (a string, or a function for nodes where some param changes\n * are entries of their own); with no previous target — the current location\n * is unknown to the site — a step too, so Back can still return to it.\n */\n historyOf: (prev: SiteTarget<any> | undefined, next: SiteTarget<any>): HistoryIntent => {\n if (prev === undefined || prev.node !== next.node) return 'push'\n const rule = next.node.history ?? 'replace'\n return typeof rule === 'function' ? rule(prev.route, next.route) : rule\n },\n\n /**\n * What the route draws: the deepest node's view, wrapped by every\n * ancestor's layout root-first. Ancestors contribute layouts only — never\n * their views. Pure function composition over ordinary Foldkit rendering;\n * unknown tags and viewless leaves fail loudly, since rendering one would\n * guess.\n */\n view: <Root, Message>(\n site: SiteTree,\n route: { readonly _tag: string },\n model: Root,\n h: HtmlBuilder<Message>,\n ): Html => {\n const chain = Site.chainOf(site, route)\n if (chain.length === 0) throw new Error(`Site.view: no node holds the tag \"${route._tag}\"`)\n // A lookup, so the non-null assertion is the documented one.\n const leaf = chain[chain.length - 1]!\n if (leaf.view === undefined)\n throw new Error(`Site.view: \"${leaf.tag}\" draws nothing; give the leaf a view`)\n let child = leaf.view.render(model, h)\n for (let at = chain.length - 2; at >= 0; at--) {\n const layout = chain[at]!.layout\n if (layout !== undefined) child = layout.render(child, model, h)\n }\n return child\n },\n\n /**\n * What the tree's surfaced nodes activate, keyed by tag, for `Data.wiring`,\n * `Data.subscriptions`, `Data.satisfy`, or an SSR plan's `surfaces`: each\n * node's `Surface.when` over the application's route place. A surface from\n * another application is refused here, not at its reads.\n */\n sources: <Root>(\n site: SiteTree,\n owner: object,\n place: ModelPlace<Root>,\n ): Record<string, ActiveSurface<Root> & SurfaceSource<Root>> => {\n const out: Record<string, ActiveSurface<Root> & SurfaceSource<Root>> = {}\n for (const node of Site.nodesOf(site)) {\n const entry = sourceOf(node, owner, place)\n if (entry !== undefined) out[entry[0]] = entry[1]\n }\n return out\n },\n\n /**\n * The route-level Sources for one destination: the same entries as\n * `Site.sources`, but only the target's chain. Prefetch, SSR, and DevTools\n * read what a route will activate without building its Model first; the\n * preparation itself stays caller-composed (`Data.satisfy` over these, with\n * the route set to the target's). A tag the tree does not hold resolves to\n * no Sources, the way an inactive Surface resolves to nothing.\n *\n * ```ts\n * const active = Site.sourcesFor(AppSite, App.owner, App.model.route, target.route)\n * const prepared = yield* Data.satisfy({ ...model, route: target.route }, active)\n * ```\n *\n * There is deliberately no `SitePlan` object: the chain is already\n * `Site.chainOf`, and the head is `Site.metaOf`.\n */\n sourcesFor: <Root>(\n site: SiteTree,\n owner: object,\n place: ModelPlace<Root>,\n route: { readonly _tag: string },\n ): Record<string, ActiveSurface<Root> & SurfaceSource<Root>> => {\n const out: Record<string, ActiveSurface<Root> & SurfaceSource<Root>> = {}\n for (const node of Site.chainOf(site, route)) {\n const entry = sourceOf(node, owner, place)\n if (entry !== undefined) out[entry[0]] = entry[1]\n }\n return out\n },\n\n /**\n * The application's link-click and URL-change lifecycle as one wiring, so\n * `update` stops hand-writing those two branches. A click on a link the\n * tree holds navigates (pushing or replacing per `Site.historyOf`); on any\n * other, on this origin or not, it loads, since another document serves\n * it (`Site.routeAt`); a URL change sets the route field — or touches\n * nothing when the address parses to the route already shown, so an echo\n * of our own write never re-renders or clears pending state. The\n * application's own update answers nothing for either message; `reduces`\n * names them for its guard, the way `Remote.reduces` does.\n *\n * ```ts\n * const Routing = Site.routing<Model, Message, AppRoute>({\n * site: AppSite,\n * owner: App.owner,\n * route: {\n * dependency: ModelRef.focus(App.model.route).dependency,\n * get: (model) => model.route,\n * set: (model, route) => modifyFields(model, { route: () => route }),\n * },\n * parse: urlToAppRoute,\n * tags: { clicked: 'ClickedLink', changed: 'ChangedUrl' },\n * completed: Message.CompletedNavigation,\n * })\n * const assembly = Bundle.assemble([Routing, ...pages])\n * const update = assembly.update((model, message) =>\n * Routing.reduces(message) ? { model } : updateOwn(model, message),\n * )\n * ```\n *\n * One routing per application: it claims the click tag and shares the\n * change tag with URL mirrors, which read their slices first. With `pages`,\n * a route change sets the field and then informs each page whose route\n * arrived, through the page's own `changed` Message.\n */\n routing: <\n Root,\n Message extends { readonly _tag: string },\n Route extends { readonly _tag: string },\n R = never,\n >(config: {\n readonly site: SiteTree\n /**\n * The application's identity token, for the Module contract. Raw Foldkit\n * applications have none; omit it and the contract claims no owner.\n */\n readonly owner?: object | undefined\n /** The route field, read and written (a `RouteField`, struct). */\n readonly route: RouteField<Root, Route>\n /** The application's URL parser, with its NotFound fallback. */\n readonly parse: (url: UrlValue) => Route\n /** The application's own link-click and URL-change tags. */\n readonly tags: { readonly clicked: string; readonly changed: string }\n /** One completion for the navigation commands to dispatch. */\n readonly completed: Schema.Schema<Message> & (() => Message)\n /**\n * Routed pages, informed when their route arrives. With service-needing\n * pages, name the services fourth:\n * `Site.routing<Model, Message, AppRoute, RemoteClient>`.\n */\n readonly pages?: ReadonlyArray<SitePage<Root, Message, R, any>> | undefined\n /**\n * What the application does once a new route is set and its pages are\n * told: moving focus to what it drew, say. An echo of the shown address\n * arrives nowhere, so it runs nothing.\n */\n readonly arrived?: ((model: Root, route: Route) => Update.Return<Root, Message, R>) | undefined\n /**\n * Told what kind each navigation is, before its route is set: `history`\n * for Back and Forward (`popstate`), `push` for a link or a Command that\n * wrote the URL. Remote holds a list left for a history navigation back\n * to it: `(model, kind) => Data.reduce(model, { _tag: 'Navigated', kind })`.\n * An echo of the shown address is no navigation, and tells nothing.\n */\n readonly navigated?: ((model: Root, kind: NavigationKind) => Root) | undefined\n /**\n * Reads a page ahead when the reader means to follow a link to it, so it\n * draws at once when they do. `links` says where they mean to go\n * (`pointedLinks()` from `foldkit-primitives/dom`), `intended` is the\n * application's Message carrying it, which the routing claims, and `read`\n * reads what the Model would read there, the route already set:\n * `there => Data.preload(there, actives)`. An address no node holds, or\n * the route shown, reads nothing, and the Model is never changed: what\n * was read lands as `read`'s own Messages.\n */\n readonly preload?:\n | {\n readonly links: Stream.Stream<UrlValue>\n readonly intended: Schema.Schema<Message> &\n ((fields: { readonly url: UrlValue }) => Message)\n readonly read: (there: Root) => Command.Command<Message, never, R>\n }\n | undefined\n }): Wiring<Root, Message, R> & {\n /** Whether the routing owns a message: its click, its URL change, or its preload intent. */\n readonly reduces: (message: Message) => boolean\n } => {\n const completedTag = tagOfConstructor(\n config.completed,\n 'Site.routing: completed must be a message constructor',\n )\n const Navigate = Command.define('Site.Navigate', {\n args: { url: Schema.String, history: Schema.Literals(['push', 'replace']) },\n messages: [config.completed],\n execute: ({ url, history }) =>\n (history === 'push' ? Navigation.pushUrl(url) : Navigation.replaceUrl(url)).pipe(\n Effect.as(config.completed()),\n ),\n })\n const { arrived, navigated, preload } = config\n const intendedTag =\n preload === undefined\n ? undefined\n : tagOfConstructor(\n preload.intended,\n 'Site.routing: preload.intended must be a message constructor',\n )\n const Load = Command.define('Site.Load', {\n args: { href: Schema.String },\n messages: [config.completed],\n execute: ({ href }) => Navigation.load(href).pipe(Effect.as(config.completed())),\n })\n // Route values are plain data from the same constructors, so equal\n // addresses compare equal. Checked before every write, so an echo of our\n // own navigation touches nothing: same Model back, no re-render.\n const sameRoute = (a: Route, b: Route): boolean => JSON.stringify(a) === JSON.stringify(b)\n const setRoute = (model: Root, next: Route): Root => {\n const current = config.route.get(model)\n return sameRoute(current, next) ? model : config.route.set(model, next)\n }\n const currentTarget = (model: Root): SiteTarget<Route> | undefined => {\n const current = config.route.get(model)\n const node = Site.nodeOf(config.site, current) as SiteNode<Route> | undefined\n if (node === undefined) return undefined\n // The tag rides along for matching only; params are everything else.\n const { _tag, ...params } = current\n return Site.target(node, params)\n }\n const handles = [\n config.tags.clicked,\n config.tags.changed,\n ...(intendedTag === undefined ? [] : [intendedTag]),\n ]\n const reduces = (message: Message): boolean =>\n // tag-check: open — the tags are the application's own variants, named in config\n handles.includes(message._tag)\n const wiring: Wiring<Root, Message, R> = {\n key: 'site',\n handles,\n shared: [config.tags.changed],\n ...(preload === undefined\n ? {}\n : {\n subscriptions: Subscription.make<Root, Message, R>()(() => ({\n 'site.intent': Subscription.persistentEntry(\n Stream.map(preload.links, url => preload.intended({ url })),\n ),\n })),\n }),\n route: (model, message) => {\n // tag-check: open — same ownership as reduces\n if (preload !== undefined && message._tag === intendedTag) {\n const url = (message as unknown as { readonly url: UrlValue }).url\n return Option.some(\n Option.match(Site.routeAt(config.site, url), {\n // Another document's page, which this application cannot read ahead.\n onNone: () => ({ model }),\n onSome: next =>\n sameRoute(config.route.get(model), next)\n ? { model }\n : { model, commands: [preload.read(config.route.set(model, next))] },\n }),\n )\n }\n // tag-check: open — same ownership as reduces\n if (message._tag === config.tags.clicked) {\n const request = (message as unknown as { readonly request: UrlRequest }).request\n return Option.some(\n UrlRequest.match(request, {\n Internal: ({ url }) =>\n Option.match(Site.routeAt(config.site, url), {\n // No node takes it, so another document serves it.\n onNone: () => ({ model, commands: [Load({ href: Url.toString(url) })] }),\n onSome: next => {\n // A lookup: the route came from one of the tree's nodes.\n const node = Site.nodeOf(config.site, next)!\n const history = Site.historyOf(currentTarget(model), {\n node,\n route: next,\n url: Url.toString(url),\n })\n return {\n model,\n commands: [Navigate({ url: Url.toString(url), history })],\n }\n },\n }),\n External: ({ href }) => ({ model, commands: [Load({ href })] }),\n }),\n )\n }\n // tag-check: open — same ownership as reduces\n if (message._tag === config.tags.changed) {\n const url = (message as unknown as { readonly url: UrlValue }).url\n const next = config.parse(url)\n // An echo of the shown address touches nothing: same Model back,\n // and no page is informed of a route it already has.\n if (sameRoute(config.route.get(model), next)) return Option.some({ model })\n const steps: Array<Update.Step<Root, Message, R>> = [\n ...(navigated === undefined\n ? []\n : [(model: Root) => ({ model: navigated(model, navigationKind()) })]),\n model => ({ model: setRoute(model, next) }),\n ...(config.pages ?? []).map(\n page => (model: Root) =>\n Option.getOrElse(page.inform(model, next), () => ({ model })),\n ),\n ...(arrived === undefined ? [] : [(model: Root) => arrived(model, next)]),\n ]\n return Option.some(Update.combine(model, steps))\n }\n return Option.none()\n },\n onUrl: (model, url) => setRoute(model, config.parse(url)),\n contract: {\n kind: 'site',\n name: 'site',\n owner: config.owner,\n owns: [],\n observes: [config.route.dependency],\n messages: [completedTag, ...(intendedTag === undefined ? [] : [intendedTag])],\n metadata: [],\n } satisfies Contract,\n }\n return { ...wiring, reduces }\n },\n\n /**\n * One routed page stated once: its link (where its Model lives and how its\n * Messages wrap), what starts it, and what its route arrival tells it. The\n * link carries the field and the wrapper together; `placed.update` folds\n * the child's Messages and `placed.view` draws it, and `Site.routing`\n * informs it through `changed` when its route arrives.\n *\n * ```ts\n * const PeoplePage = Site.placement(People, PeopleBundle, {\n * link: Link.field<Model>()('peoplePage', Link.wrapper(Message.GotPeopleMessage)),\n * args: parent => ({\n * searchText: parent.route._tag === 'People' ? parent.route.searchText : Option.none(),\n * }),\n * changed: route => People.Message.ChangedRoute({ route }),\n * })\n * const assembly = Bundle.assemble([PeoplePage.placed, Routing])\n * ```\n *\n * `changed` receives the node's own case value and returns the child's\n * Message, or nothing when the arrival needs no answer. Without it the\n * page is never informed. Bundles with OutMessages, and children that are\n * not Bundles, stay on `Bundle.at` and `Link.child` directly.\n */\n placement: <\n Route extends { readonly _tag: string },\n Parent,\n LinkMessage extends AnyMessage,\n ChildModel,\n ChildMessage extends AnyMessage,\n Field extends string,\n Name extends string,\n Args,\n BundleR = never,\n BundleS = never,\n ViewInputs = void,\n Resources extends ResourceEntries<ChildModel, ChildMessage> = never,\n Helpers extends Readonly<Record<string, Helper<ChildModel, ChildMessage, never, BundleR>>> =\n never,\n ObserverR = never,\n >(\n node: SiteNode<Route>,\n bundle: Bundle.Bundle<\n Name,\n Args,\n ChildModel,\n ChildMessage,\n never,\n BundleR,\n BundleS,\n ViewInputs,\n Resources,\n Helpers\n >,\n config: {\n readonly link: Link<Parent, LinkMessage, ChildModel, ChildMessage, Field>\n readonly changed?: (route: Route) => ChildMessage | undefined\n } & PlacementConfig<\n Args,\n Parent,\n LinkMessage,\n ChildMessage,\n never,\n never,\n ObserverR,\n SeedFor<Parent, Field>,\n ViewInputs\n >,\n ): SitePage<\n Parent,\n LinkMessage,\n BundleR | ObserverR,\n Placed<\n Name,\n Parent,\n LinkMessage,\n ChildModel,\n ChildMessage,\n BundleR | ObserverR,\n BundleS,\n ViewInputs,\n Resources,\n Helpers,\n Field,\n LinkMessage extends { readonly _tag: infer Tag extends string } ? Tag : string\n >\n > => {\n const { link, changed } = config\n // `link` and `changed` are this helper's own: `Bundle.at` reads its\n // known keys, and a non-literal tolerates the extra properties.\n const placed = bundle.at(link, config)\n return {\n node,\n placed,\n inform: (model, route) => {\n if (!Predicate.isTagged(route, node.tag) || changed === undefined) return Option.none()\n // Guarded by the tag the node was built from, which `Site.make`\n // keeps unique: this is the node's own case value.\n const child = changed(route as Route)\n if (child === undefined) return Option.none()\n return placed.update(model, link.toParentMessage(child))\n },\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8OA,MAAa,SAAS,kBAAkB;CACtC,SAAS,CAAC;CACV,SAAS,CAAC;CACV,QAAQ,EAAE,KAAK,OAAO,OAAO;AAC/B,CAAC;;;;;;;;;AAuID,MAAM,uBACJ,OAAO,WAAW,eAAe,OAAO,OAAO,SAAS,aAAa,YAAY;AAEnF,MAAM,oBAAoB,aAAsB,SAAyB;CACvE,MAAM,UAAW,YAAwE,QACrF,MAAM,KAAK;CACf,IAAI,OAAO,YAAY,UAAU,MAAM,IAAI,MAAM,GAAG,KAAK,8BAA8B;CACvF,OAAO;AACT;AASA,MAAM,0BAAU,IAAI,QAA6B;;AAGjD,MAAM,WAAW,SAA8B;CAC7C,MAAM,QAAQ,QAAQ,IAAI,IAAI;CAC9B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,yBAAS,IAAI,IAA8C;CACjE,MAAM,wBAAQ,IAAI,IAA2B;CAC7C,MAAM,SAAS,OAAkB,UAA2C;EAC1E,IAAI,OAAO,IAAI,MAAM,IAAI,GACvB,MAAM,IAAI,MACR,eAAe,MAAM,KAAK,IAAI,mDAChC;EACF,MAAM,WAAW,MAAM,IAAI,MAAM,KAAK,GAAG;EACzC,IAAI,aAAa,KAAA,KAAa,aAAa,MAAM,MAC/C,MAAM,IAAI,MACR,uCAAuC,MAAM,KAAK,IAAI,8BACxD;EACF,OAAO,IAAI,MAAM,MAAM,KAAK;EAC5B,MAAM,IAAI,MAAM,KAAK,KAAK,MAAM,IAAI;EACpC,KAAK,MAAM,SAAS,MAAM,UAAU,MAAM,OAAO,MAAM,IAAI;CAC7D;CACA,KAAK,MAAM,QAAQ,KAAK,OAAO,MAAM,MAAM,K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IAAI,CAAC;KACzE;KACA,OAAO,OAAO,KAAK,OAAO,QAAQ,OAAO,KAAK,CAAC;IACjD;IACA,OAAO,OAAO,KAAK;GACrB;GACA,QAAQ,OAAO,QAAQ,SAAS,OAAO,OAAO,MAAM,GAAG,CAAC;GACxD,UAAU;IACR,MAAM;IACN,MAAM;IACN,OAAO,OAAO;IACd,MAAM,CAAC;IACP,UAAU,CAAC,OAAO,MAAM,UAAU;IAClC,UAAU,CAAC,cAAc,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,CAAC,WAAW,CAAE;IAC5E,UAAU,CAAC;GACb;GAEkB;EAAQ;CAC9B;;;;;;;;;;;;;;;;;;;;;;;;CAyBA,YAiBE,MACA,QAYA,WAgCG;EACH,MAAM,EAAE,MAAM,YAAY;EAG1B,MAAM,SAAS,OAAO,GAAG,MAAM,MAAM;EACrC,OAAO;GACL;GACA;GACA,SAAS,OAAO,UAAU;IACxB,IAAI,CAAC,UAAU,SAAS,OAAO,KAAK,GAAG,KAAK,YAAY,KAAA,GAAW,OAAO,OAAO,KAAK;IAGtF,MAAM,QAAQ,QAAQ,KAAc;IACpC,IAAI,UAAU,KAAA,GAAW,OAAO,OAAO,KAAK;IAC5C,OAAO,OAAO,OAAO,OAAO,KAAK,gBAAgB,KAAK,CAAC;GACzD;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Url"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-site` — the deployed route topology of a Foldkit application.\n *\n * A Site says where the application is: stable route nodes in a hierarchy,\n * each with its Foldkit Router, its metadata, and the Surfaces it activates.\n * Everything else — fetching, caching, rendering, navigation effects — stays\n * where it already is: the node compiles down to the primitives the runtime\n * already runs (`Route` biparsers, `Surface.when`, Bundle placements), so the\n * Site never becomes a second router, loader, or store.\n *\n * The rule, from the design:\n *\n * > Router says where the application is. Surface says what that state makes\n * > observable and capable. Remote says what server facts those observations\n * > require.\n *\n * Nothing here runs: nodes, mounts, trees, and targets are data. A `SiteTree`\n * is frozen at `Site.make`. `Site.routing` is the one runtime piece: the\n * link-click and URL-change lifecycle as a wiring, so applications stop\n * hand-writing those two update branches.\n */\nimport { Effect, Option, Predicate, Schema, Stream } from 'effect'\nimport {\n Bundle,\n Link,\n type AnyMessage,\n type Helper,\n type Placed,\n type PlacementConfig,\n type ResourceEntries,\n type SeedFor,\n} from 'foldkit-bundle'\nimport * as Command from 'foldkit/command'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport * as Navigation from 'foldkit/navigation'\nimport * as Subscription from 'foldkit/subscription'\nimport type { KeyBinding, KeySequence } from 'foldkit/dom'\nimport { UrlRequest } from 'foldkit/navigation'\nimport { oneOf, parseUrlWithFallback, type Router } from 'foldkit/route'\nimport type { Meta } from 'foldkit-ssr/client'\nimport * as Update from 'foldkit/update'\nimport * as Url from 'foldkit/url'\nimport type { Url as UrlValue } from 'foldkit/url'\nimport {\n ModelRef,\n Surface,\n type ActiveSurface,\n type Contract,\n type ModelPlace,\n type Surface as SurfaceType,\n type SurfaceSource,\n type Wiring,\n} from 'foldkit-surface'\n\n/** Whether moving to a target adds a history step (`push`) or replaces the current one. */\nexport type HistoryIntent = 'push' | 'replace'\n\n/**\n * A route-case constructor: the Schema for `Surface.when`, called to build\n * route values for targets. The `any` is deliberate and quarantined here:\n * every constructor of a `defineRouteUnion` case is callable with its fields,\n * and `Site.target` types the params from the route value instead.\n */\nexport interface RouteCase<Route extends { readonly _tag: string }> extends Schema.Schema<Route> {\n (params: any): Route\n}\n\n/**\n * A Surface a node activates, with the route's params made into its own: the\n * `Surface.when` a node lowers to, once the application says where its route\n * lives. The surface's own types are checked where the node is declared\n * (`Site.route` infers them); by the time sources resolve, only the owner\n * check can still fail, and it does, loudly.\n */\nexport interface BoundSurface {\n readonly surface: SurfaceType<any, any, any, any>\n /** Who is signed in, read from the Model; the Surface waits for one when given. */\n readonly viewer?: ((model: any) => Option.Option<any>) | undefined\n readonly params: (route: any, viewer: any) => any\n}\n\n/**\n * The Surface a node activates, as `Site.route` and `.surface` take it.\n * `params` reads the node's route; with `viewer`, it reads the signed-in\n * viewer too, and the Surface is active only once `viewer` gives one.\n * Without `viewer`, `Viewer` is `void`, so a `params` reading a viewer it was\n * never given does not compile.\n */\nexport interface NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer> {\n readonly surface: SurfaceType<SRoot, SModel, SMessage, SParams>\n readonly viewer?: ((model: SRoot) => Option.Option<Viewer>) | undefined\n readonly params: (route: Route, viewer: Viewer) => SParams\n}\n\n/** What `Site.route` annotates a node with, beside its Surface. */\nexport interface RouteOptions<Route extends { readonly _tag: string }> {\n readonly title?: ((route: Route) => string) | undefined\n readonly section?: string | undefined\n readonly landing?: Omit<Route, '_tag'> | undefined\n readonly shortcut?: KeySequence | undefined\n readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined\n readonly layout?: NodeLayout | undefined\n readonly view?: NodeView | undefined\n readonly meta?: NodeMeta<Route> | undefined\n readonly indexed?: boolean | undefined\n readonly access?: NodeAccess<never> | undefined\n}\n\n/**\n * A layout around everything under a node: it receives the composed child\n * explicitly — no Outlet, no context, no hidden route state. Ancestors with\n * layouts wrap the leaf's view root-first; ancestors without one pass\n * through. The `any` positions are deliberate and quarantined, as with\n * `BoundSurface`: annotate the function where it is declared and it checks\n * there.\n */\nexport interface NodeLayout {\n readonly render: (child: Html, model: any, h: any) => Html\n}\n\n/**\n * What a node draws for its own route: only the deepest node of the active\n * chain draws (its ancestors contribute layouts, never their views — a\n * person page shows no people list). Same `any` quarantine as `NodeLayout`.\n */\nexport interface NodeView {\n readonly render: (model: any, h: any) => Html\n}\n\n/**\n * What a node says of itself in the document's head, from its route value and\n * the Model (a post's excerpt is in the Model, not the route). The node keeps\n * it with the Model as `any`, quarantined as `NodeLayout`'s is: name the Model\n * where it is declared (`.meta<Model>(...)`) and it checks there.\n */\nexport type NodeMeta<Route, Model = any> = (page: {\n readonly route: Route\n readonly model: Model\n}) => Meta\n\n/**\n * The route's place in the Model, read and written. A field holding a tagged\n * union is a *union of* `FieldRef`s, one per case, which no single\n * `ModelRef<Root, Route>` accepts — so this is structural:\n *\n * ```ts\n * route: {\n * dependency: ModelRef.focus(App.model.route).dependency,\n * get: (model) => model.route,\n * set: (model, route) => modifyFields(model, { route: () => route }),\n * },\n * ```\n */\nexport interface RouteField<Root, Route> {\n readonly dependency: readonly string[]\n readonly get: (root: Root) => Route\n readonly set: (root: Root, route: Route) => Root\n}\n\n/**\n * One routed page: its node, its Bundle placement, and how a route arrival\n * reaches the child. The placement drives both folds from one declaration —\n * `placed.update` for Messages, `placed.view` for drawing — and `inform`\n * tells the child when its route arrives, through its own Message. The\n * placement's full type rides along, so assemblies keep inferring services.\n */\nexport interface SitePage<Parent, ParentMessage, R, P> {\n readonly node: SiteNode<any>\n readonly placed: P\n /** The page's bodies when its Bundle is a `Bundle.lazy`, which the routing's `codeFor` names. */\n readonly code: Option.Option<Bundle.Loadable>\n /**\n * The child told of a route arrival: `None` for another node's route, for\n * a page with nothing to say, or when the child says nothing is needed.\n */\n readonly inform: (\n model: Parent,\n route: { readonly _tag: string },\n ) => Option.Option<Update.Return<Parent, ParentMessage, R>>\n}\n\n/**\n * One deployed location: its Router (which owns URL semantics), its route\n * case, and its metadata. A stable first-class value: mounting it in a tree\n * never mutates it, so the same node serves targets, hrefs, and inspection\n * wherever it is mounted.\n */\nexport interface SiteNode<\n Route extends { readonly _tag: string },\n Surfaced extends string = never,\n> {\n readonly tag: string\n readonly router: Router<Route>\n readonly case: RouteCase<Route>\n /** The page's title for this route, once the route value is known. */\n readonly title?: ((route: Route) => string) | undefined\n /** The navigation section this route belongs to, for menus and breadcrumbs. */\n readonly section?: string | undefined\n /**\n * Where the section's nav item points: this node's params for its landing\n * address (a people list with no search, say). Nodes a section never lands\n * on — a person, a file — leave it absent; `Site.landing` reads the first\n * node of a section that declares one.\n */\n readonly landing?: Omit<Route, '_tag'> | undefined\n /**\n * The keys that go to this node's `landing`, as Foldkit's key bindings name\n * them: one press (`'/'`, `'Mod+K'`) or a sequence (`['G', 'H']`).\n * `Site.shortcuts` makes the bindings.\n */\n readonly shortcut?: KeySequence | undefined\n /**\n * Which history step a move within this node is: a string, or a function\n * for nodes where some param changes are entries of their own (another\n * person) and others are views of one entry (another search). A move to\n * another node — or from an unknown location — is always a step.\n */\n readonly history?: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent) | undefined\n /** The Surface this route activates, if the node declares one. */\n readonly bound?: BoundSurface | undefined\n readonly [surfaced]?: (tag: Surfaced) => void\n /** A layout wrapping everything under this node, if it declares one. */\n readonly layout?: NodeLayout | undefined\n /** What this node draws for its own route, if it draws anything. */\n readonly view?: NodeView | undefined\n /** What this node says of itself in the head; nodes below override it per field. */\n readonly meta?: NodeMeta<Route> | undefined\n /**\n * Whether search engines index this node and, unless they say otherwise,\n * the nodes below it. Undeclared up the whole chain, a node is indexed.\n */\n readonly indexed?: boolean | undefined\n /**\n * Who may be shown this node and the nodes below it: see `Site.accessOf`.\n * Held as `never` for its reader, so a rule given in the options must\n * name the reader it reads (`allow: (me: Me) => …`).\n */\n readonly access?: NodeAccess<never> | undefined\n}\n\n/**\n * Who may be shown a node, and where anyone else is sent. Presentation, not\n * authorization: the server guards what the page reads whatever this says.\n * `Who` is what the application knows of the reader (its `Me` row, say).\n */\nexport interface NodeAccess<Who> {\n readonly allow: (who: Who) => boolean\n /** Where a reader `allow` refuses goes, given the address they asked for (a sign-in page returning to it). */\n readonly otherwise: (requested: string) => SiteTarget<any>\n}\n\n/**\n * Whether the reader may be shown a route: `Allowed`; `Pending` while the\n * application does not know who they are yet, to draw a loading state rather\n * than flash the sign-in page at someone signed in; `Denied` with the address\n * to send them to.\n */\nexport const Access = defineTaggedUnion({\n Allowed: {},\n Pending: {},\n Denied: { url: Schema.String },\n})\nexport type Access = typeof Access.Type\n\n/** Carries the routes a mount or tree holds, in its type only: nothing sets it. */\ndeclare const routes: unique symbol\n\n/**\n * Carries the tags of the nodes with a Surface, in their types only: nothing\n * sets it. `Site.sources` keys its entries by these.\n */\ndeclare const surfaced: unique symbol\n\n/**\n * A node mounted with its children: structure, not state. `Route` is every\n * route it holds, `Surfaced` the tags of those whose node has a Surface.\n */\nexport interface SiteMount<\n Route extends { readonly _tag: string } = any,\n Surfaced extends string = never,\n> {\n readonly node: SiteNode<any>\n readonly children: ReadonlyArray<SiteMount>\n readonly [routes]?: (route: Route) => void\n readonly [surfaced]?: (tag: Surfaced) => void\n}\n\n/** The routes a bare node or a mount holds. */\nexport type RoutesOf<Mounted> =\n Mounted extends SiteNode<infer Route>\n ? Route\n : Mounted extends SiteMount<infer Route>\n ? Route\n : never\n\n/** The tags of the nodes with a Surface that a bare node or a mount holds. */\nexport type SurfacedOf<Mounted> =\n Mounted extends SiteNode<any, infer Tag>\n ? Tag\n : Mounted extends SiteMount<any, infer Tag>\n ? Tag\n : never\n\n/**\n * A node under construction, from `Site.node`: each method annotates and\n * returns the builder, so nodes compose in steps and annotation bundles are\n * ordinary values. Methods — not pipeable fragments — because each stage of\n * a pipe is a separate generic call and could not infer the route. Read\n * `.node` at any stage for the frozen node so far.\n */\nexport interface NodeBuilder<\n Route extends { readonly _tag: string },\n Surfaced extends string = never,\n> {\n /** The node so far: frozen, usable for targets and hrefs at any stage. */\n readonly node: SiteNode<Route, Surfaced>\n /**\n * One named bundle through the builder, Effect-style: the bundle stays\n * generic over the builder it meets, so it instantiates to this node's\n * route with no annotation. Chain for more than one.\n *\n * ```ts\n * const inSection = <R extends { readonly _tag: string }>(b: NodeBuilder<R>) =>\n * b.section('People').shortcut(['G', 'P'])\n *\n * const Person = Site.node(personRouter, AppRoute.Person).pipe(inSection).node\n * ```\n *\n * Free `pipe(builder, bundle)` from `effect` composes the same way; this\n * method is the same spelling without the import.\n */\n pipe<A>(fn: (builder: NodeBuilder<Route, Surfaced>) => A): A\n /** The page's title for this route, once the route value is known. */\n title(title: (route: Route) => string): NodeBuilder<Route, Surfaced>\n /** The navigation section this route belongs to. */\n section(section: string): NodeBuilder<Route, Surfaced>\n /** Where the section's nav item points, as this node's params. */\n landing(landing: Omit<Route, '_tag'>): NodeBuilder<Route, Surfaced>\n /** The keys that go to this node's landing. */\n shortcut(shortcut: KeySequence): NodeBuilder<Route, Surfaced>\n /** Which history step a move within this node is. */\n history(\n history: HistoryIntent | ((prev: Route, next: Route) => HistoryIntent),\n ): NodeBuilder<Route, Surfaced>\n /** A layout wrapping everything under this node. */\n layout(layout: NodeLayout): NodeBuilder<Route, Surfaced>\n /** What this node draws for its own route. */\n view(view: NodeView): NodeBuilder<Route, Surfaced>\n /** What this node says of itself in the head, from its route and the Model. */\n meta<Model = any>(meta: NodeMeta<Route, Model>): NodeBuilder<Route, Surfaced>\n /** Whether search engines index this node and the nodes below it. */\n indexed(indexed: boolean): NodeBuilder<Route, Surfaced>\n /** Who may be shown this node and the nodes below it, and where anyone else goes. */\n access<Who>(access: NodeAccess<Who>): NodeBuilder<Route, Surfaced>\n /** The Surface this route activates, and the viewer its params read, if any. */\n surface<SRoot, SModel, SMessage, SParams, Viewer = void>(\n config: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer>,\n ): NodeBuilder<Route, Route['_tag']>\n}\n\n/**\n * The deployed topology: roots with everything mounted under them, frozen.\n * `Route` is the union of every node's route, so the tree parses an address\n * to it (`Site.parse`) and builds one back (`Site.hrefOf`).\n */\nexport interface SiteTree<\n Route extends { readonly _tag: string } = any,\n Surfaced extends string = never,\n> {\n readonly roots: ReadonlyArray<SiteMount>\n readonly [routes]?: (route: Route) => void\n readonly [surfaced]?: (tag: Surfaced) => void\n}\n\n/** One address a node's `Site.paths` lists: the route's params, and when its content last changed. */\nexport interface SitePath<Route extends { readonly _tag: string }> {\n readonly params: Omit<Route, '_tag'>\n /** When what the page shows last changed, as ISO 8601 text, for a sitemap. */\n readonly modified?: string | undefined\n}\n\n/** A node's addresses, listed by an Effect the build runs: from `Site.paths`. */\nexport interface SitePaths<E, R> {\n readonly node: SiteNode<any>\n readonly list: Effect.Effect<ReadonlyArray<SitePath<any>>, E, R>\n}\n\n/** How a listing of `SitePaths` can fail: each one's error, and none for no paths. */\nexport type PathsError<Paths> = Paths extends SitePaths<infer E, any> ? E : never\n/** What a listing of `SitePaths` needs: each one's services, and none for no paths. */\nexport type PathsServices<Paths> = Paths extends SitePaths<any, infer R> ? R : never\n\n/** One address of the whole site, from `Site.targets`: a target, and when it last changed. */\nexport interface SiteListed<Route extends { readonly _tag: string }> extends SiteTarget<Route> {\n readonly modified?: string | undefined\n}\n\n/**\n * One typed destination: the node, the route value, and the URL, all from one\n * declaration. Links, prefetch, and route analysis share this instead of each\n * rebuilding it.\n */\nexport interface SiteTarget<Route extends { readonly _tag: string }> {\n readonly node: SiteNode<Route>\n readonly route: Route\n readonly url: string\n}\n\n/**\n * The tag a tagged constructor names, read the way `Surface.when` reads it\n * off a route case. Anything else is a definition-time error, not a silent\n * mismatch.\n */\n/** What a navigation was: `history` for Back and Forward, `push` for a link or a Command. */\nexport type NavigationKind = 'history' | 'push'\n\n/**\n * The kind of the URL change being reduced. Foldkit reduces its Message on\n * the stack of the event that caused it: the browser's `popstate` for Back\n * and Forward, `foldkit:urlchange` for a URL a Command wrote. A change\n * reduced off that stack (a drain deferred past Foldkit's budget) reads as\n * `push`, which only refetches what a history navigation would have shown\n * as it was.\n */\nconst navigationKind = (): NavigationKind =>\n typeof window !== 'undefined' && window.event?.type === 'popstate' ? 'history' : 'push'\n\nconst tagOfConstructor = (constructor: unknown, what: string): string => {\n const literal = (constructor as { fields?: { _tag?: { ast?: { literal?: unknown } } } }).fields\n ?._tag?.ast?.literal\n if (typeof literal !== 'string') throw new Error(`${what} must be a tagged constructor`)\n return literal\n}\n\ninterface SiteIndex {\n readonly parent: ReadonlyMap<SiteNode<any>, SiteNode<any> | undefined>\n readonly byTag: ReadonlyMap<string, SiteNode<any>>\n /** The route the first node in tree order reads at an address, or nothing. */\n readonly read: (url: UrlValue) => Option.Option<any>\n}\n\nconst indexes = new WeakMap<SiteTree, SiteIndex>()\n\n/** The parent and tag maps and the parser of a tree, computed once per tree value. */\nconst indexOf = (site: SiteTree): SiteIndex => {\n const known = indexes.get(site)\n if (known !== undefined) return known\n const parent = new Map<SiteNode<any>, SiteNode<any> | undefined>()\n const byTag = new Map<string, SiteNode<any>>()\n const visit = (mount: SiteMount, above: SiteNode<any> | undefined): void => {\n if (parent.has(mount.node))\n throw new Error(\n `Site.make: \"${mount.node.tag}\" is mounted twice; a node has one place in a tree`,\n )\n const knownTag = byTag.get(mount.node.tag)\n if (knownTag !== undefined && knownTag !== mount.node)\n throw new Error(\n `Site.make: two nodes share the tag \"${mount.node.tag}\"; one route case is one node`,\n )\n parent.set(mount.node, above)\n byTag.set(mount.node.tag, mount.node)\n for (const child of mount.children) visit(child, mount.node)\n }\n for (const root of site.roots) visit(root, undefined)\n // Foldkit's parser takes only a fallback, so no match falls back to `None`.\n const parser = parseUrlWithFallback<any, Option.Option<any>>(\n oneOf(...[...parent.keys()].map(node => node.router)),\n { make: () => Option.none() },\n )\n const read = (url: UrlValue): Option.Option<any> => {\n const parsed = parser(url)\n return Option.isOption(parsed) ? parsed : Option.some(parsed)\n }\n const index = { parent, byTag, read }\n indexes.set(site, index)\n return index\n}\n\n/** Whether a node's route has params beyond its tag, so its addresses must be listed. */\nconst takesParams = (node: SiteNode<any>): boolean =>\n Object.keys((node.case as { fields?: object }).fields ?? {}).some(field => field !== '_tag')\n\nconst asMount = (node: SiteNode<any> | SiteMount): SiteMount =>\n 'children' in node ? node : { node, children: [] }\n\n/**\n * One surfaced node's `Surface.when` over the route place, or nothing\n * surfaceless. A node reading the viewer is active on its route only while\n * the viewer is known, and keeps the route's tag as its activation.\n */\nconst sourceOf = <Root>(\n node: SiteNode<any>,\n owner: object,\n place: ModelPlace<Root>,\n): [string, ActiveSurface<Root> & SurfaceSource<Root>] | undefined => {\n const bound = node.bound\n if (bound === undefined) return undefined\n const { surface, viewer, params } = bound\n if (surface.owner !== owner)\n throw new Error(`Site: \"${surface.name}\" belongs to another application than the site`)\n if (viewer === undefined)\n return [node.tag, Surface.when(surface, place, node.case, route => params(route, undefined))]\n const focus = ModelRef.focus(place)\n const gated = Surface.at(surface, (model: Root) => {\n const route = focus.get(model)\n return Predicate.isTagged(route, node.tag)\n ? Option.map(viewer(model), who => params(route, who))\n : Option.none()\n })\n return [node.tag, { ...gated, activation: { path: focus.dependency, tag: node.tag } }]\n}\n\n/**\n * What `Site.sources` gives: an entry per node with a Surface, keyed by its\n * tag (`Surfaced`, which the tree's type carries). A node with none has no\n * key, so a key named where the entries are keyed (`Data.wiring`'s\n * `policies`) is one that reads. A literal key, unlike an index signature,\n * survives a spread beside the application's own entries. Each is optional:\n * `Site.sourcesFor` gives one chain's.\n */\nexport type SiteSources<Root, Surfaced extends string> = {\n readonly [Tag in Surfaced]?: ActiveSurface<Root> & SurfaceSource<Root>\n}\n\n/** The surfaced entries among `nodes`, keyed by tag. */\nconst sourcesOn = <Root, Surfaced extends string>(\n nodes: ReadonlyArray<SiteNode<any>>,\n owner: object,\n place: ModelPlace<Root>,\n): SiteSources<Root, Surfaced> => {\n const out: Record<string, ActiveSurface<Root> & SurfaceSource<Root>> = {}\n for (const node of nodes) {\n const entry = sourceOf(node, owner, place)\n if (entry !== undefined) out[entry[0]] = entry[1]\n }\n // Keyed by the tag of each node with a Surface, which the tree's type carries.\n return out as SiteSources<Root, Surfaced>\n}\n\n/** The fields a `Meta` gives, so one left `undefined` does not erase an ancestor's. */\nconst saidOf = (meta: Meta): Meta =>\n Object.fromEntries(Object.entries(meta).filter(([, value]) => value !== undefined))\n\nconst freezeMount = (mount: SiteMount): SiteMount =>\n Object.freeze({\n node: mount.node,\n children: Object.freeze(mount.children.map(freezeMount)),\n })\n\n/**\n * How a placed page hears its route arrive: optional, and free to say nothing,\n * for an eager Bundle; required, and always a Message, for a `Bundle.lazy`,\n * whose bodies load on that Message.\n */\nexport type ChangedFor<Kind, Route, ChildMessage> = Kind extends Bundle.Loadable\n ? { readonly changed: (route: Route) => ChildMessage }\n : { readonly changed?: ((route: Route) => ChildMessage | undefined) | undefined }\n\n/**\n * What fetches a route's code ahead of its arrival, given the routing's\n * completion: `fetchCode`, passed as `Site.routing`'s `preload.code`.\n */\nexport type CodeFetch = <Message>(completed: () => Message) => (\n code: ReadonlyArray<Bundle.Loadable>,\n) => {\n readonly name: string\n readonly args: Readonly<Record<string, unknown>>\n readonly effect: Effect.Effect<Message>\n}\n\n/**\n * Loads the code of a route the reader points at, for `Site.routing`'s\n * `preload.code`: one Command, `Site.LoadCode`, that completes with the\n * routing's `completed` whether the chunks load or not. A load that fails is\n * forgotten by `Bundle.lazy`, so the page's own arrival loads again and\n * reports it; a guess at intent reports nothing. An import of its own, not a\n * member of `Site`, so a site with no lazy page keeps none of it.\n */\nexport const fetchCode: CodeFetch = completed => code => ({\n name: 'Site.LoadCode',\n args: { code: code.map(each => each.name).join(', ') },\n effect: Effect.promise(() => Promise.allSettled(code.map(each => each.load()))).pipe(\n Effect.as(completed()),\n ),\n})\n\n/** Whether a Bundle is a `Bundle.lazy`, whose bodies load on demand. */\nconst isLoadable = (bundle: object): bundle is Bundle.Loadable =>\n 'load' in bundle &&\n typeof bundle.load === 'function' &&\n 'isLoaded' in bundle &&\n typeof bundle.isLoaded === 'function'\n\n/** A bare node: its tag from its route case, nothing annotated. */\nconst baseNode = <Route extends { readonly _tag: string }>(\n router: Router<Route>,\n routeCase: RouteCase<Route>,\n): SiteNode<Route> =>\n Object.freeze({\n tag: tagOfConstructor(routeCase, 'Site.route: expected a route case from defineRouteUnion'),\n router,\n case: routeCase,\n })\n\nexport const Site = {\n /**\n * One deployed location from its Foldkit Router and its route case:\n *\n * ```ts\n * const Person = Site.route(personRouter, AppRoute.Person, {\n * title: ({ personId }) => `Person ${personId} | Routing`,\n * section: 'People',\n * })\n * ```\n *\n * The router stays the whole URL story (parse and build); the case names\n * the tag and builds route values. Metadata is annotated once here, and\n * navigation, titles, and history derive from it. To share annotations\n * across nodes, or to build incrementally, use the `Site.node` builder\n * instead — these options are sugar over it.\n */\n route: <Route extends { readonly _tag: string }, SRoot, SModel, SMessage, SParams, Viewer = void>(\n router: Router<Route>,\n routeCase: RouteCase<Route>,\n options?: RouteOptions<Route> & {\n readonly surface?: NodeSurface<Route, SRoot, SModel, SMessage, SParams, Viewer> | undefined\n },\n // With no `surface`, nothing infers the Surface's root, which stays `unknown`.\n ): SiteNode<Route, unknown extends SRoot ? never : Route['_tag']> => {\n let built = Site.node(router, routeCase)\n if (options?.title !== undefined) built = built.title(options.title)\n if (options?.section !== undefined) built = built.section(options.section)\n if (options?.landing !== undefined) built = built.landing(options.landing)\n if (options?.shortcut !== undefined) built = built.shortcut(options.shortcut)\n if (options?.history !== undefined) built = built.history(options.history)\n if (options?.layout !== undefined) built = built.layout(options.layout)\n if (options?.view !== undefined) built = built.view(options.view)\n if (options?.meta !== undefined) built = built.meta(options.meta)\n if (options?.indexed !== undefined) built = built.indexed(options.indexed)\n if (options?.access !== undefined) built = built.access(options.access)\n if (options?.surface !== undefined)\n built = built.surface<SRoot, SModel, SMessage, SParams, Viewer>(options.surface)\n // The builder's type forgets the Surface across the `if`; the return type\n // says it again, from whether `surface` was given.\n return built.node as SiteNode<Route, unknown extends SRoot ? never : Route['_tag']>\n },\n\n /**\n * One deployed location as an incremental builder, for nodes annotated in\n * steps or annotations shared across nodes:\n *\n * ```ts\n * const Person = Site.node(personRouter, AppRoute.Person)\n * .title(({ personId }) => `Person ${personId} | Routing`)\n * .section('People')\n * .node\n * ```\n *\n * Methods — not pipeable fragments — because a pipeable fragment cannot\n * infer the route: each stage is a separate generic call, so its type\n * parameter falls back to the constraint and a typed callback no longer\n * matches. A method already knows its node's route, so inline lambdas\n * infer with no annotation. Read `.node` at any stage: every step freezes,\n * so intermediates are usable nodes too (targets, hrefs), never drafts.\n * `Site.route`'s options are sugar over this builder — one implementation.\n */\n node: <Route extends { readonly _tag: string }>(\n router: Router<Route>,\n routeCase: RouteCase<Route>,\n ): NodeBuilder<Route> => {\n const at = <Surfaced extends string>(\n built: SiteNode<Route, Surfaced>,\n ): NodeBuilder<Route, Surfaced> => ({\n node: built,\n pipe: <A>(fn: (builder: NodeBuilder<Route, Surfaced>) => A): A => fn(at(built)),\n title: title => at(Object.freeze({ ...built, title })),\n section: section => at(Object.freeze({ ...built, section })),\n landing: landing => at(Object.freeze({ ...built, landing })),\n shortcut: shortcut => at(Object.freeze({ ...built, shortcut })),\n history: history => at(Object.freeze({ ...built, history })),\n layout: layout => at(Object.freeze({ ...built, layout })),\n view: view => at(Object.freeze({ ...built, view })),\n meta: meta => at(Object.freeze({ ...built, meta })),\n indexed: indexed => at(Object.freeze({ ...built, indexed })),\n access: access => at(Object.freeze({ ...built, access })),\n // The node now has a Surface, which its type says by its tag.\n surface: config =>\n at(\n Object.freeze({ ...built, bound: config as BoundSurface }) as SiteNode<\n Route,\n Route['_tag']\n >,\n ),\n })\n return at(baseNode(router, routeCase))\n },\n\n /**\n * A node with its children. Returns a mount; the node itself is untouched,\n * so it stays usable bare for targets and hrefs. Children may be bare\n * nodes (childless) or mounts.\n */\n mount: <\n Route extends { readonly _tag: string },\n const Children extends ReadonlyArray<SiteNode<any> | SiteMount> = [],\n Surfaced extends string = never,\n >(\n node: SiteNode<Route, Surfaced>,\n children?: Children,\n ): SiteMount<Route | RoutesOf<Children[number]>, Surfaced | SurfacedOf<Children[number]>> =>\n Object.freeze({ node, children: Object.freeze((children ?? []).map(asMount)) }),\n\n /**\n * The deployed topology from its roots: bare nodes or mounts, frozen.\n * Refuses two nodes sharing a tag and one node mounted twice, since both\n * would make chain inspection ambiguous.\n */\n make: <const Roots extends ReadonlyArray<SiteNode<any> | SiteMount>>(\n ...roots: Roots\n ): SiteTree<RoutesOf<Roots[number]>, SurfacedOf<Roots[number]>> => {\n const tree: SiteTree<RoutesOf<Roots[number]>, SurfacedOf<Roots[number]>> = Object.freeze({\n roots: Object.freeze(roots.map(asMount).map(freezeMount)),\n })\n // Fail at definition time, not at the first inspection.\n indexOf(tree)\n return tree\n },\n\n /**\n * One typed destination: the route value and the URL from the node's own\n * declaration, so a link can never point where the parser would not go.\n */\n target: <Route extends { readonly _tag: string }>(\n node: SiteNode<Route>,\n params: Omit<Route, '_tag'>,\n ): SiteTarget<Route> => ({\n node,\n route: node.case(params),\n url: node.router.build(params),\n }),\n\n /** The URL of a target, or of a node with params directly. */\n href: (<Route extends { readonly _tag: string }>(\n targetOrNode: SiteTarget<Route> | SiteNode<Route>,\n params?: Omit<Route, '_tag'>,\n ): string => {\n if ('url' in targetOrNode) return targetOrNode.url\n if (params === undefined)\n throw new Error(`Site.href: \"${targetOrNode.tag}\" needs params to build its URL`)\n return Site.target(targetOrNode, params).url\n }) as {\n <Route extends { readonly _tag: string }>(target: SiteTarget<Route>): string\n <Route extends { readonly _tag: string }>(\n node: SiteNode<Route>,\n params: Omit<Route, '_tag'>,\n ): string\n },\n\n /**\n * The tree's parser: an address to the route of the first node, in tree\n * order (depth-first, parents first), whose router takes all of it, or the\n * fallback. A router that takes any segment (`/:slug`) belongs after the\n * nodes whose literal it would take too. With `Site.hrefOf`, the tree is\n * the one declaration of both directions.\n */\n parse: <Route extends { readonly _tag: string }, Fallback>(\n site: SiteTree<Route>,\n fallback: { readonly make: (data: { readonly path: string }) => Fallback },\n ): ((url: UrlValue) => Route | Fallback) => {\n const { read } = indexOf(site)\n return (url): Route | Fallback =>\n Option.getOrElse(read(url), () => fallback.make({ path: url.pathname }))\n },\n\n /**\n * The route the tree reads at an address, as `Site.parse` does, or nothing\n * when no node takes it: an address the tree does not hold is another\n * document's, which a link reaches with a full load.\n */\n routeAt: <Route extends { readonly _tag: string }>(\n site: SiteTree<Route>,\n url: UrlValue,\n ): Option.Option<Route> => indexOf(site).read(url),\n\n /**\n * The address of a route the tree holds, built by its node's router, so it\n * parses back to the same route (`Site.parse`).\n */\n hrefOf: <Route extends { readonly _tag: string }>(\n site: SiteTree<Route>,\n route: Route,\n ): string => {\n const node = indexOf(site).byTag.get(route._tag)\n if (node === undefined) throw new Error(`Site.hrefOf: no node holds the tag \"${route._tag}\"`)\n const { _tag, ...params } = route\n return node.router.build(params)\n },\n\n /**\n * A node's addresses, from data: every published post is one. `list` is an\n * Effect the build runs, such as a Remote query read through\n * `Data.satisfy`, so it lists what a visitor may see.\n *\n * ```ts\n * const posts = Site.paths(PostNode, listPosts.pipe(\n * Effect.map(rows => rows.map(row => ({ params: { slug: row.slug }, modified: row.at }))),\n * ))\n * ```\n */\n paths: <Route extends { readonly _tag: string }, E, R>(\n node: SiteNode<Route>,\n list: Effect.Effect<ReadonlyArray<SitePath<Route>>, E, R>,\n ): SitePaths<E, R> => ({ node, list }),\n\n /**\n * Every address of the site, in tree order: one for each node whose route\n * has no params, and what `paths` lists for each node whose route has\n * them. What a build renders, a sitemap lists (with `Site.indexedOf`), and\n * a prefetch warms. A node with params and no `paths` is refused, as are\n * `paths` for a node the tree does not hold or twice for one node, so no\n * page is left out unsaid; `Site.paths(node, Effect.succeed([]))` lists none.\n */\n targets: <const Paths extends ReadonlyArray<SitePaths<any, any>>>(\n site: SiteTree,\n paths: Paths,\n ): Effect.Effect<\n ReadonlyArray<SiteListed<any>>,\n PathsError<Paths[number]>,\n PathsServices<Paths[number]>\n > => {\n const nodes = Site.nodesOf(site)\n const listed = new Map<SiteNode<any>, SitePaths<any, any>>()\n for (const each of paths) {\n if (!nodes.includes(each.node))\n throw new Error(`Site.targets: \"${each.node.tag}\" has paths but is not in the tree`)\n if (listed.has(each.node)) throw new Error(`Site.targets: \"${each.node.tag}\" has paths twice`)\n listed.set(each.node, each)\n }\n const unlisted = nodes.filter(node => takesParams(node) && !listed.has(node))\n if (unlisted.length > 0)\n throw new Error(\n `Site.targets: ${unlisted.map(node => `\"${node.tag}\"`).join(', ')} take params and have no paths`,\n )\n return Effect.map(\n Effect.forEach(\n nodes,\n node => {\n const source = listed.get(node)\n if (source === undefined) return Effect.succeed([Site.target(node, {})])\n return Effect.map(source.list, found =>\n found.map(({ params, modified }) => ({\n ...Site.target(node, params),\n ...(modified === undefined ? {} : { modified }),\n })),\n )\n },\n { concurrency: 'unbounded' },\n ),\n perNode => perNode.flat(),\n )\n },\n\n /** Every node in the tree, depth-first, parents before children. */\n nodesOf: (site: SiteTree): ReadonlyArray<SiteNode<any>> => {\n const out: Array<SiteNode<any>> = []\n const visit = (mount: SiteMount): void => {\n out.push(mount.node)\n for (const child of mount.children) visit(child)\n }\n for (const root of site.roots) visit(root)\n return out\n },\n\n /** The node a route value is on, or nothing for a tag the tree does not hold. */\n nodeOf: (site: SiteTree, route: { readonly _tag: string }): SiteNode<any> | undefined =>\n indexOf(site).byTag.get(route._tag),\n\n /** The chain a route value is on, root first; none for an unknown tag. */\n chainOf: (site: SiteTree, route: { readonly _tag: string }): ReadonlyArray<SiteNode<any>> => {\n const { parent, byTag } = indexOf(site)\n const node = byTag.get(route._tag)\n if (node === undefined) return []\n const chain: Array<SiteNode<any>> = [node]\n let above = parent.get(node)\n while (above !== undefined) {\n chain.unshift(above)\n above = parent.get(above)\n }\n return chain\n },\n\n /** The node above this one in the tree, or nothing at a root. */\n parentOf: (site: SiteTree, node: SiteNode<any>): SiteNode<any> | undefined =>\n indexOf(site).parent.get(node),\n\n /** Every node above this one, root first. */\n ancestorsOf: (site: SiteTree, node: SiteNode<any>): ReadonlyArray<SiteNode<any>> => {\n const { parent } = indexOf(site)\n const out: Array<SiteNode<any>> = []\n let above = parent.get(node)\n while (above !== undefined) {\n out.unshift(above)\n above = parent.get(above)\n }\n return out\n },\n\n /** How deep the node sits: a root is 0, its children 1. */\n depthOf: (site: SiteTree, node: SiteNode<any>): number => Site.ancestorsOf(site, node).length,\n\n /** The title the tree annotates for a route value, or nothing. */\n titleOf: (site: SiteTree, route: { readonly _tag: string }): string | undefined => {\n const node = indexOf(site).byTag.get(route._tag)\n return node?.title?.(route)\n },\n\n /**\n * Whether search engines index a route: the nearest declaration up its\n * chain, so a `noindex` studio covers every node below it. A route the tree\n * does not hold is indexed, as a page with no declaration is.\n */\n indexedOf: (site: SiteTree, route: { readonly _tag: string }): boolean => {\n const chain = Site.chainOf(site, route)\n for (let at = chain.length - 1; at >= 0; at--) {\n const indexed = chain[at]!.indexed\n if (indexed !== undefined) return indexed\n }\n return true\n },\n\n /**\n * Whether the reader may be shown a route: every `access` up its chain,\n * root first, must allow `who`, and the first that refuses sends them to\n * its `otherwise`, given the route's address. `who` is `Option.none()`\n * while the application does not know yet (its `Me` loading): `Pending`\n * wherever a rule would need it. A route no rule covers is `Allowed`.\n *\n * ```ts\n * Access.match(Site.accessOf(AppSite, model.route, me), {\n * Allowed: () => page,\n * Pending: () => loading,\n * Denied: ({ url }) => redirecting, // and `update` replaces the URL with `url`\n * })\n * ```\n *\n * A server answers `Denied` with a 303 to `url` before rendering. It is\n * presentation: what the page reads is guarded on the server regardless.\n */\n accessOf: <Route extends { readonly _tag: string }, Who>(\n site: SiteTree<Route>,\n route: Route,\n who: Option.Option<Who>,\n ): Access => {\n for (const node of Site.chainOf(site, route)) {\n const { access } = node\n if (access === undefined) continue\n if (Option.isNone(who)) return Access.Pending()\n // The tree holds its rules' readers as `never`: `who` is the reader they read.\n if ((access as NodeAccess<Who>).allow(who.value)) continue\n const target = access.otherwise(Site.hrefOf(site, route))\n // A target this same rule covers refuses the reader again, for ever.\n if (Site.chainOf(site, target.route).includes(node))\n throw new Error(\n `foldkit-site: ${node.tag}'s access sends a refused reader to ${target.url}, which it also covers`,\n )\n return Access.Denied({ url: target.url })\n }\n return Access.Allowed()\n },\n\n /**\n * What a route says of itself in the head, for an SSR plan's `meta`:\n *\n * ```ts\n * SSR.plan(App, { id: 'site', state, meta: model => Site.metaOf(AppSite, model.route, model) })\n * ```\n *\n * Each node of the chain's `meta`, root first, with a deeper node's field\n * replacing its ancestor's and a field it leaves out keeping the ancestor's.\n * The preview title falls back to the route's `title`. An unindexed route\n * (`Site.indexedOf`) is `noindex` whatever its `meta` says.\n */\n metaOf: <Root>(site: SiteTree, route: { readonly _tag: string }, model: Root): Meta => {\n let meta: Meta = {}\n for (const node of Site.chainOf(site, route))\n if (node.meta !== undefined) meta = { ...meta, ...saidOf(node.meta({ route, model })) }\n const title = meta.title ?? Site.titleOf(site, route)\n return {\n ...meta,\n ...(title === undefined ? {} : { title }),\n ...(Site.indexedOf(site, route) ? {} : { robots: 'noindex' }),\n }\n },\n\n /** The navigation section the tree annotates for a route value, or nothing. */\n sectionOf: (site: SiteTree, route: { readonly _tag: string }): string | undefined =>\n indexOf(site).byTag.get(route._tag)?.section,\n\n /**\n * Where a section's nav item points: the first node of the section with a\n * landing, as a target. Nothing when no node of the section declares one —\n * every section shown needs a landing, so navigation asserts it.\n */\n landing: (site: SiteTree, section: string): SiteTarget<any> | undefined => {\n for (const candidate of Site.nodesOf(site)) {\n if (candidate.section !== section) continue\n const landing = candidate.landing\n if (landing === undefined) continue\n return Site.target(candidate, landing)\n }\n return undefined\n },\n\n /**\n * The tree's shortcuts as key bindings, each sending the Message\n * `toMessage` makes of its node's landing:\n *\n * ```ts\n * Dom.streamFromKeyBindings({\n * bindings: Site.shortcuts(AppSite, target => Message.PressedShortcut({ url: target.url })),\n * })\n * ```\n *\n * A shortcut on a node with no `landing` goes nowhere, and one used twice\n * goes to two places; both are refused.\n */\n shortcuts: <Message>(\n site: SiteTree,\n toMessage: (target: SiteTarget<any>) => Message,\n ): ReadonlyArray<KeyBinding<Message>> => {\n const taken = new Map<string, string>()\n return Site.nodesOf(site).flatMap((node): ReadonlyArray<KeyBinding<Message>> => {\n const keys = node.shortcut\n if (keys === undefined) return []\n if (node.landing === undefined)\n throw new Error(`Site.shortcuts: \"${node.tag}\" has a shortcut and no landing to go to`)\n const named = typeof keys === 'string' ? keys : keys.join(' ')\n const other = taken.get(named)\n if (other !== undefined)\n throw new Error(`Site.shortcuts: \"${named}\" goes to both \"${other}\" and \"${node.tag}\"`)\n taken.set(named, node.tag)\n const message = toMessage(Site.target(node, node.landing))\n const mapEvent = () => message\n // The binding's two shapes are told apart by `keys`, so each is made whole.\n return [typeof keys === 'string' ? { keys, mapEvent } : { keys, mapEvent }]\n })\n },\n\n /**\n * Which history step a move is: to another node, a step; within a node, its\n * declaration (a string, or a function for nodes where some param changes\n * are entries of their own); with no previous target — the current location\n * is unknown to the site — a step too, so Back can still return to it.\n */\n historyOf: (prev: SiteTarget<any> | undefined, next: SiteTarget<any>): HistoryIntent => {\n if (prev === undefined || prev.node !== next.node) return 'push'\n const rule = next.node.history ?? 'replace'\n return typeof rule === 'function' ? rule(prev.route, next.route) : rule\n },\n\n /**\n * What the route draws: the deepest node's view, wrapped by every\n * ancestor's layout root-first. Ancestors contribute layouts only — never\n * their views. Pure function composition over ordinary Foldkit rendering;\n * unknown tags and viewless leaves fail loudly, since rendering one would\n * guess.\n */\n view: <Root, Message>(\n site: SiteTree,\n route: { readonly _tag: string },\n model: Root,\n h: HtmlBuilder<Message>,\n ): Html => {\n const chain = Site.chainOf(site, route)\n if (chain.length === 0) throw new Error(`Site.view: no node holds the tag \"${route._tag}\"`)\n // A lookup, so the non-null assertion is the documented one.\n const leaf = chain[chain.length - 1]!\n if (leaf.view === undefined)\n throw new Error(`Site.view: \"${leaf.tag}\" draws nothing; give the leaf a view`)\n let child = leaf.view.render(model, h)\n for (let at = chain.length - 2; at >= 0; at--) {\n const layout = chain[at]!.layout\n if (layout !== undefined) child = layout.render(child, model, h)\n }\n return child\n },\n\n /**\n * What the tree's surfaced nodes activate, keyed by tag, for `Data.wiring`,\n * `Data.subscriptions`, `Data.satisfy`, or an SSR plan's `surfaces`: each\n * node's `Surface.when` over the application's route place. A surface from\n * another application is refused here, not at its reads. The keys are the\n * tags of the nodes with a Surface (`SiteSources`), so they survive a spread\n * beside the application's own entries and can be named where the entries\n * are keyed (`Data.wiring`'s `policies`); a surfaceless node's tag cannot.\n */\n sources: <Root, Surfaced extends string>(\n site: SiteTree<any, Surfaced>,\n owner: object,\n place: ModelPlace<Root>,\n ): SiteSources<Root, Surfaced> => sourcesOn(Site.nodesOf(site), owner, place),\n\n /**\n * The route-level Sources for one destination: the same entries as\n * `Site.sources`, but only the target's chain. Prefetch, SSR, and DevTools\n * read what a route will activate without building its Model first; the\n * preparation itself stays caller-composed (`Data.satisfy` over these, with\n * the route set to the target's). A tag the tree does not hold resolves to\n * no Sources, the way an inactive Surface resolves to nothing.\n *\n * ```ts\n * const active = Site.sourcesFor(AppSite, App.owner, App.model.route, target.route)\n * const prepared = yield* Data.satisfy({ ...model, route: target.route }, active)\n * ```\n *\n * There is deliberately no `SitePlan` object: the chain is already\n * `Site.chainOf`, and the head is `Site.metaOf`.\n */\n sourcesFor: <Root, Surfaced extends string>(\n site: SiteTree<any, Surfaced>,\n owner: object,\n place: ModelPlace<Root>,\n route: { readonly _tag: string },\n ): SiteSources<Root, Surfaced> => sourcesOn(Site.chainOf(site, route), owner, place),\n\n /**\n * The application's link-click and URL-change lifecycle as one wiring, so\n * `update` stops hand-writing those two branches. A click on a link the\n * tree holds navigates (pushing or replacing per `Site.historyOf`); on any\n * other, on this origin or not, it loads, since another document serves\n * it (`Site.routeAt`); a URL change sets the route field — or touches\n * nothing when the address parses to the route already shown, so an echo\n * of our own write never re-renders or clears pending state. The\n * application's own update answers nothing for either message; `reduces`\n * names them for its guard, the way `Remote.reduces` does.\n *\n * ```ts\n * const Routing = Site.routing<Model, Message, AppRoute>({\n * site: AppSite,\n * owner: App.owner,\n * route: {\n * dependency: ModelRef.focus(App.model.route).dependency,\n * get: (model) => model.route,\n * set: (model, route) => modifyFields(model, { route: () => route }),\n * },\n * parse: urlToAppRoute,\n * tags: { clicked: 'ClickedLink', changed: 'ChangedUrl' },\n * completed: Message.CompletedNavigation,\n * })\n * const assembly = Bundle.assemble([Routing, ...pages])\n * const update = assembly.update((model, message) =>\n * Routing.reduces(message) ? { model } : updateOwn(model, message),\n * )\n * ```\n *\n * One routing per application: it claims the click tag and shares the\n * change tag with URL mirrors, which read their slices first. With `pages`,\n * a route change sets the field and then informs each page whose route\n * arrived, through the page's own `changed` Message.\n */\n routing: <\n Root,\n Message extends { readonly _tag: string },\n Route extends { readonly _tag: string },\n R = never,\n >(config: {\n readonly site: SiteTree\n /**\n * The application's identity token, for the Module contract. Raw Foldkit\n * applications have none; omit it and the contract claims no owner.\n */\n readonly owner?: object | undefined\n /** The route field, read and written (a `RouteField`, struct). */\n readonly route: RouteField<Root, Route>\n /** The application's URL parser, with its NotFound fallback. */\n readonly parse: (url: UrlValue) => Route\n /** The application's own link-click and URL-change tags. */\n readonly tags: { readonly clicked: string; readonly changed: string }\n /** One completion for the navigation commands to dispatch. */\n readonly completed: Schema.Schema<Message> & (() => Message)\n /**\n * Routed pages, informed when their route arrives. With service-needing\n * pages, name the services fourth:\n * `Site.routing<Model, Message, AppRoute, RemoteClient>`.\n */\n readonly pages?: ReadonlyArray<SitePage<Root, Message, R, any>> | undefined\n /**\n * What the application does once a new route is set and its pages are\n * told: moving focus to what it drew, say. An echo of the shown address\n * arrives nowhere, so it runs nothing.\n */\n readonly arrived?: ((model: Root, route: Route) => Update.Return<Root, Message, R>) | undefined\n /**\n * Told what kind each navigation is, before its route is set: `history`\n * for Back and Forward (`popstate`), `push` for a link or a Command that\n * wrote the URL. Remote holds a list left for a history navigation back\n * to it: `(model, kind) => Data.reduce(model, { _tag: 'Navigated', kind })`.\n * An echo of the shown address is no navigation, and tells nothing.\n */\n readonly navigated?: ((model: Root, kind: NavigationKind) => Root) | undefined\n /**\n * Reads a page ahead when the reader means to follow a link to it, so it\n * draws at once when they do. `links` says where they mean to go\n * (`pointedLinks()` from `foldkit-primitives/dom`), `intended` is the\n * application's Message carrying it, which the routing claims, and `read`\n * reads what the Model would read there, the route already set:\n * `there => Data.preload(there, actives)`. An address no node holds, or\n * the route shown, reads nothing, and the Model is never changed: what\n * was read lands as `read`'s own Messages. With `code`, a `pages` entry\n * that is a `Bundle.lazy` on that route's chain has its bodies fetched\n * too, once.\n */\n readonly preload?:\n | {\n readonly links: Stream.Stream<UrlValue>\n readonly intended: Schema.Schema<Message> &\n ((fields: { readonly url: UrlValue }) => Message)\n readonly read: (there: Root) => Command.Command<Message, never, R>\n /**\n * Fetches the code of a `Bundle.lazy` page on the route pointed at,\n * once, beside its read: `fetchCode`, an import of its own so a site\n * with no lazy page keeps none of it. Required when `pages` holds a\n * lazy page.\n */\n readonly code?: CodeFetch | undefined\n }\n | undefined\n }): Wiring<Root, Message, R> & {\n /** Whether the routing owns a message: its click, its URL change, or its preload intent. */\n readonly reduces: (message: Message) => boolean\n /**\n * The code a route draws: each `Bundle.lazy` page of `pages` on its chain,\n * root first, so a page nested under a node with lazy code of its own\n * loads both; none for a route whose pages are eager. Pure: nothing loads\n * until a caller calls `load`. The `lazy` of `SSR.entry`, `SSR.render`\n * and `SSR.hydrate`, from the one list of pages the routing holds:\n * `lazy: model => Routing.codeFor(model.route)`.\n */\n readonly codeFor: (route: Route) => ReadonlyArray<Bundle.Loadable>\n /**\n * The Model's route told to its pages as an arrival, for an `init` that\n * starts on it with no server render: a `Bundle.lazy` page loads its\n * bodies on that Message, so without it a page opened at its own address\n * draws its placeholder for good. `init: () => Routing.boot(initial)`.\n * A page the server rendered has its bodies loaded already (`lazy`).\n */\n readonly boot: (model: Root) => Update.Return<Root, Message, R>\n } => {\n const completedTag = tagOfConstructor(\n config.completed,\n 'Site.routing: completed must be a message constructor',\n )\n const Navigate = Command.define('Site.Navigate', {\n args: { url: Schema.String, history: Schema.Literals(['push', 'replace']) },\n messages: [config.completed],\n execute: ({ url, history }) =>\n (history === 'push' ? Navigation.pushUrl(url) : Navigation.replaceUrl(url)).pipe(\n Effect.as(config.completed()),\n ),\n })\n const { arrived, navigated, preload } = config\n const intendedTag =\n preload === undefined\n ? undefined\n : tagOfConstructor(\n preload.intended,\n 'Site.routing: preload.intended must be a message constructor',\n )\n const Load = Command.define('Site.Load', {\n args: { href: Schema.String },\n messages: [config.completed],\n execute: ({ href }) => Navigation.load(href).pipe(Effect.as(config.completed())),\n })\n const pages = config.pages ?? []\n const codeFor = (route: { readonly _tag: string }): ReadonlyArray<Bundle.Loadable> =>\n Site.chainOf(config.site, route).flatMap(node =>\n pages.flatMap(page => (page.node === node ? Option.toArray(page.code) : [])),\n )\n const fetch = preload?.code?.(config.completed)\n if (\n preload !== undefined &&\n fetch === undefined &&\n pages.some(page => Option.isSome(page.code))\n )\n throw new Error(\n 'Site.routing: a Bundle.lazy page needs preload.code (fetchCode), or nothing fetches it ahead',\n )\n // Each page on the route told of its arrival, through its own `changed`.\n const informed = (route: Route): Array<Update.Step<Root, Message, R>> =>\n pages.map(\n page => (model: Root) => Option.getOrElse(page.inform(model, route), () => ({ model })),\n )\n // Route values are plain data from the same constructors, so equal\n // addresses compare equal. Checked before every write, so an echo of our\n // own navigation touches nothing: same Model back, no re-render.\n const sameRoute = (a: Route, b: Route): boolean => JSON.stringify(a) === JSON.stringify(b)\n const setRoute = (model: Root, next: Route): Root => {\n const current = config.route.get(model)\n return sameRoute(current, next) ? model : config.route.set(model, next)\n }\n const currentTarget = (model: Root): SiteTarget<Route> | undefined => {\n const current = config.route.get(model)\n const node = Site.nodeOf(config.site, current) as SiteNode<Route> | undefined\n if (node === undefined) return undefined\n // The tag rides along for matching only; params are everything else.\n const { _tag, ...params } = current\n return Site.target(node, params)\n }\n const handles = [\n config.tags.clicked,\n config.tags.changed,\n ...(intendedTag === undefined ? [] : [intendedTag]),\n ]\n const reduces = (message: Message): boolean =>\n // tag-check: open — the tags are the application's own variants, named in config\n handles.includes(message._tag)\n const wiring: Wiring<Root, Message, R> = {\n key: 'site',\n handles,\n shared: [config.tags.changed],\n ...(preload === undefined\n ? {}\n : {\n subscriptions: Subscription.make<Root, Message, R>()(() => ({\n 'site.intent': Subscription.persistentEntry(\n Stream.map(preload.links, url => preload.intended({ url })),\n ),\n })),\n }),\n route: (model, message) => {\n // tag-check: open — same ownership as reduces\n if (preload !== undefined && message._tag === intendedTag) {\n const url = (message as unknown as { readonly url: UrlValue }).url\n return Option.some(\n Option.match(Site.routeAt(config.site, url), {\n // Another document's page, which this application cannot read ahead.\n onNone: () => ({ model }),\n onSome: next => {\n if (sameRoute(config.route.get(model), next)) return { model }\n // Its page's chunk too, once: a loaded one asks for nothing.\n const unloaded =\n fetch === undefined ? [] : codeFor(next).filter(code => !code.isLoaded())\n return {\n model,\n commands: [\n preload.read(config.route.set(model, next)),\n ...(fetch === undefined || unloaded.length === 0 ? [] : [fetch(unloaded)]),\n ],\n }\n },\n }),\n )\n }\n // tag-check: open — same ownership as reduces\n if (message._tag === config.tags.clicked) {\n const request = (message as unknown as { readonly request: UrlRequest }).request\n return Option.some(\n UrlRequest.match(request, {\n Internal: ({ url }) =>\n Option.match(Site.routeAt(config.site, url), {\n // No node takes it, so another document serves it.\n onNone: () => ({ model, commands: [Load({ href: Url.toString(url) })] }),\n onSome: next => {\n // A lookup: the route came from one of the tree's nodes.\n const node = Site.nodeOf(config.site, next)!\n const history = Site.historyOf(currentTarget(model), {\n node,\n route: next,\n url: Url.toString(url),\n })\n return {\n model,\n commands: [Navigate({ url: Url.toString(url), history })],\n }\n },\n }),\n External: ({ href }) => ({ model, commands: [Load({ href })] }),\n }),\n )\n }\n // tag-check: open — same ownership as reduces\n if (message._tag === config.tags.changed) {\n const url = (message as unknown as { readonly url: UrlValue }).url\n const next = config.parse(url)\n // An echo of the shown address touches nothing: same Model back,\n // and no page is informed of a route it already has.\n if (sameRoute(config.route.get(model), next)) return Option.some({ model })\n const steps: Array<Update.Step<Root, Message, R>> = [\n ...(navigated === undefined\n ? []\n : [(model: Root) => ({ model: navigated(model, navigationKind()) })]),\n model => ({ model: setRoute(model, next) }),\n ...informed(next),\n ...(arrived === undefined ? [] : [(model: Root) => arrived(model, next)]),\n ]\n return Option.some(Update.combine(model, steps))\n }\n return Option.none()\n },\n onUrl: (model, url) => setRoute(model, config.parse(url)),\n contract: {\n kind: 'site',\n name: 'site',\n owner: config.owner,\n owns: [],\n observes: [config.route.dependency],\n messages: [completedTag, ...(intendedTag === undefined ? [] : [intendedTag])],\n metadata: [],\n } satisfies Contract,\n }\n return {\n ...wiring,\n reduces,\n codeFor,\n boot: model => Update.combine(model, informed(config.route.get(model))),\n }\n },\n\n /**\n * One routed page stated once: its link (where its Model lives and how its\n * Messages wrap), what starts it, and what its route arrival tells it. The\n * link carries the field and the wrapper together; `placed.update` folds\n * the child's Messages and `placed.view` draws it, and `Site.routing`\n * informs it through `changed` when its route arrives.\n *\n * ```ts\n * const PeoplePage = Site.placement(People, PeopleBundle, {\n * link: Link.field<Model>()('peoplePage', Link.wrapper(Message.GotPeopleMessage)),\n * args: parent => ({\n * searchText: parent.route._tag === 'People' ? parent.route.searchText : Option.none(),\n * }),\n * changed: route => People.Message.ChangedRoute({ route }),\n * })\n * const assembly = Bundle.assemble([PeoplePage.placed, Routing])\n * ```\n *\n * `changed` receives the node's own case value and returns the child's\n * Message, or nothing when the arrival needs no answer. Without it the\n * page is never informed. Bundles with OutMessages, and children that are\n * not Bundles, stay on `Bundle.at` and `Link.child` directly.\n *\n * A `Bundle.lazy` page becomes the page's `code` (the routing's\n * `codeFor`), and must have `changed`: its arrival is the Message that\n * loads its bodies. A page opened at its own address with no server render\n * has no arrival: its `init` starts through the routing's `boot`.\n */\n placement: <\n Route extends { readonly _tag: string },\n Parent,\n LinkMessage extends AnyMessage,\n ChildModel,\n ChildMessage extends AnyMessage,\n Field extends string,\n Name extends string,\n Args,\n BundleR = never,\n BundleS = never,\n ViewInputs = void,\n Resources extends ResourceEntries<ChildModel, ChildMessage> = never,\n Helpers extends Readonly<Record<string, Helper<ChildModel, ChildMessage, never, BundleR>>> =\n never,\n ObserverR = never,\n Kind = unknown,\n >(\n node: SiteNode<Route>,\n bundle: Kind &\n Bundle.Bundle<\n Name,\n Args,\n ChildModel,\n ChildMessage,\n never,\n BundleR,\n BundleS,\n ViewInputs,\n Resources,\n Helpers\n >,\n config: {\n readonly link: Link<Parent, LinkMessage, ChildModel, ChildMessage, Field>\n } & NoInfer<ChangedFor<Kind, Route, ChildMessage>> &\n PlacementConfig<\n Args,\n Parent,\n LinkMessage,\n ChildMessage,\n never,\n never,\n ObserverR,\n SeedFor<Parent, Field>,\n ViewInputs\n >,\n ): SitePage<\n Parent,\n LinkMessage,\n BundleR | ObserverR,\n Placed<\n Name,\n Parent,\n LinkMessage,\n ChildModel,\n ChildMessage,\n BundleR | ObserverR,\n BundleS,\n ViewInputs,\n Resources,\n Helpers,\n Field,\n LinkMessage extends { readonly _tag: infer Tag extends string } ? Tag : string\n >\n > => {\n const { link, changed } = config\n const code = isLoadable(bundle) ? Option.some(bundle) : Option.none()\n // A lazy page loads on its first Message: with none on arrival, a page\n // reached by Back or a key press would draw its placeholder for good.\n if (Option.isSome(code) && changed === undefined)\n throw new Error(\n `Site.placement: \"${bundle.name}\" is a Bundle.lazy, so its route's arrival must tell it (changed), which loads its bodies (an init on its route: the routing's boot)`,\n )\n // `link` and `changed` are this helper's own: `Bundle.at` reads its\n // known keys, and a non-literal tolerates the extra properties.\n const placed = bundle.at(link, config)\n return {\n node,\n placed,\n code,\n inform: (model, route) => {\n if (!Predicate.isTagged(route, node.tag) || changed === undefined) return Option.none()\n // Guarded by the tag the node was built from, which `Site.make`\n // keeps unique: this is the node's own case value.\n const child = changed(route as Route)\n if (child === undefined) return Option.none()\n return placed.update(model, link.toParentMessage(child))\n },\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkQA,MAAa,SAAS,kBAAkB;CACtC,SAAS,CAAC;CACV,SAAS,CAAC;CACV,QAAQ,EAAE,KAAK,OAAO,OAAO;AAC/B,CAAC;;;;;;;;;AAmKD,MAAM,uBACJ,OAAO,WAAW,eAAe,OAAO,OAAO,SAAS,aAAa,YAAY;AAEnF,MAAM,oBAAoB,aAAsB,SAAyB;CACvE,MAAM,UAAW,YAAwE,QACrF,MAAM,KAAK;CACf,IAAI,OAAO,YAAY,UAAU,MAAM,IAAI,MAAM,GAAG,KAAK,8BAA8B;CACvF,OAAO;AACT;AASA,MAAM,0BAAU,IA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O,KAAK;IAGtF,MAAM,QAAQ,QAAQ,KAAc;IACpC,IAAI,UAAU,KAAA,GAAW,OAAO,OAAO,KAAK;IAC5C,OAAO,OAAO,OAAO,OAAO,KAAK,gBAAgB,KAAK,CAAC;GACzD;EACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-site",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The deployed route topology of a Foldkit application: stable route nodes, their hierarchy, typed targets, and per-node metadata, compiled to the Foldkit Router, Surface, and Bundle primitives the runtime already runs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -38,25 +38,25 @@
|
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"foldkit-
|
|
42
|
-
"foldkit-
|
|
43
|
-
"foldkit-
|
|
41
|
+
"foldkit-ssr": "0.13.0",
|
|
42
|
+
"foldkit-surface": "0.15.0",
|
|
43
|
+
"foldkit-bundle": "0.14.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"effect": "^4.1.0",
|
|
47
47
|
"foldkit": "^0.170.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"effect": "
|
|
50
|
+
"effect": "4.1.4",
|
|
51
51
|
"foldkit": "0.170.0",
|
|
52
52
|
"tsdown": "^0.23.1",
|
|
53
53
|
"typescript": "7.0.2",
|
|
54
|
-
"foldkit-
|
|
55
|
-
"foldkit-entity": "0.
|
|
56
|
-
"foldkit-
|
|
57
|
-
"foldkit-
|
|
58
|
-
"foldkit-surface": "0.
|
|
59
|
-
"foldkit-ssr": "0.
|
|
54
|
+
"foldkit-bundle": "0.14.0",
|
|
55
|
+
"foldkit-entity": "0.18.0",
|
|
56
|
+
"foldkit-primitives": "0.21.0",
|
|
57
|
+
"foldkit-remote": "0.27.0",
|
|
58
|
+
"foldkit-surface": "0.15.0",
|
|
59
|
+
"foldkit-ssr": "0.13.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|