foldkit-ssr 0.8.2 → 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.
Files changed (54) hide show
  1. package/README.md +496 -83
  2. package/dist/client-XnpTQZHw.d.ts +85 -0
  3. package/dist/client-XnpTQZHw.d.ts.map +1 -0
  4. package/dist/client.d.ts +5 -0
  5. package/dist/client.js +343 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/context.d.ts +2 -0
  8. package/dist/context.js +33 -0
  9. package/dist/context.js.map +1 -0
  10. package/dist/diagnostics.d.ts +2 -0
  11. package/dist/diagnostics.js +59 -0
  12. package/dist/diagnostics.js.map +1 -0
  13. package/dist/{index.d.mts → index.d.ts} +96 -25
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/{index.mjs → index.js} +247 -108
  16. package/dist/index.js.map +1 -0
  17. package/dist/keep.d.ts +34 -0
  18. package/dist/keep.d.ts.map +1 -0
  19. package/dist/keep.js +80 -0
  20. package/dist/keep.js.map +1 -0
  21. package/dist/listen-DaUPRKVR.d.ts +71 -0
  22. package/dist/listen-DaUPRKVR.d.ts.map +1 -0
  23. package/dist/listen.d.ts +2 -0
  24. package/dist/listen.js +187 -0
  25. package/dist/listen.js.map +1 -0
  26. package/dist/requestContext-D9nsbGSJ.d.ts +21 -0
  27. package/dist/requestContext-D9nsbGSJ.d.ts.map +1 -0
  28. package/dist/requestContext.d.ts +2 -0
  29. package/dist/requestContext.js +48 -0
  30. package/dist/requestContext.js.map +1 -0
  31. package/dist/resumable-BPN_qQHU.d.ts +107 -0
  32. package/dist/resumable-BPN_qQHU.d.ts.map +1 -0
  33. package/dist/resumable.d.ts +2 -0
  34. package/dist/resumable.js +401 -0
  35. package/dist/resumable.js.map +1 -0
  36. package/dist/{client-DkwAniQQ.d.mts → shared-DbupL3vO.d.ts} +233 -194
  37. package/dist/shared-DbupL3vO.d.ts.map +1 -0
  38. package/dist/shared.d.ts +2 -0
  39. package/dist/shared.js +347 -0
  40. package/dist/shared.js.map +1 -0
  41. package/dist/{vite.d.mts → vite.d.ts} +3 -5
  42. package/dist/vite.d.ts.map +1 -0
  43. package/dist/{vite.mjs → vite.js} +3 -4
  44. package/dist/vite.js.map +1 -0
  45. package/package.json +18 -18
  46. package/dist/client-DVG9_3rL.mjs +0 -1113
  47. package/dist/client-DVG9_3rL.mjs.map +0 -1
  48. package/dist/client-DkwAniQQ.d.mts.map +0 -1
  49. package/dist/client.d.mts +0 -2
  50. package/dist/client.mjs +0 -1
  51. package/dist/index.d.mts.map +0 -1
  52. package/dist/index.mjs.map +0 -1
  53. package/dist/vite.d.mts.map +0 -1
  54. package/dist/vite.mjs.map +0 -1
@@ -1,144 +1,121 @@
1
- import { Layer, Option, Result, Schema, Stream } from "effect";
2
- import { ActiveSurface, Metadata, SurfaceSource, WritableProjection } from "foldkit-surface";
3
- import { Attribute, Html, HtmlBuilder, KeyboardModifiers } from "foldkit/html";
1
+ import { n as DecodedBinding } from "./listen-DaUPRKVR.js";
2
+ import { Cause, Effect, Layer, Option, Result, Schema, Stream } from "effect";
3
+ import { ActiveSurface, Diagnostic, Metadata, ModelPlace, ReportDiagnostic, SurfaceSource, WritableProjection } from "foldkit-surface";
4
+ import { Html, HtmlBuilder } from "foldkit/html";
4
5
  import { Runtime } from "foldkit";
5
6
  import { Ports } from "foldkit/port";
6
- //#region src/listen.d.ts
7
- /**
8
- * A binding as the envelope carries it: Foldkit's attribute (`OnSubmit`,
9
- * `OnBlur`), whose tag says what its handler does beside dispatching; the
10
- * Message, encoded through the application's Message Schema (for a hole, with
11
- * the hole filled by a placeholder); the fields the event fills, `depth`
12
- * placement wrappers down; and the attribute's options. Its ordinal is its
13
- * index.
14
- */
15
- interface EncodedBinding {
16
- readonly attribute: string;
17
- readonly message: unknown;
18
- readonly hole?: ReadonlyArray<string>;
19
- readonly depth?: number;
20
- readonly options?: unknown;
21
- }
22
- /** A binding decoded from the page: its Message is one of the application's. */
23
- interface DecodedBinding {
24
- readonly attribute: string;
25
- readonly event: string;
26
- readonly message: unknown;
27
- readonly hole?: ReadonlyArray<string> | undefined;
28
- readonly depth?: number | undefined;
29
- readonly options?: unknown;
30
- }
31
- /**
32
- * What the markers make of one event: the Messages its bindings dispatch, in
33
- * the order the live page would, and, when the walk met a handler the page
34
- * could not name, that element. An answer with `unnamed` is incomplete: the
35
- * live page would do more than its Messages say.
36
- */
37
- interface Answer {
38
- readonly event: Event;
39
- readonly messages: ReadonlyArray<unknown>;
40
- readonly unnamed?: Element | undefined;
41
- }
42
- interface ListenOptions {
43
- readonly bindings: ReadonlyArray<DecodedBinding>;
44
- readonly onAnswer: (answer: Answer) => void;
7
+ /** A served page the browser contained instead of resuming: it stays in view, inert, and no runtime starts. */
8
+ interface PageContained extends Diagnostic {
9
+ readonly _tag: 'PageContained';
45
10
  /**
46
- * Every event the page's markers name, as the envelope lists them. Given,
47
- * `listen` needs no pass over the page to find the events a marker names
48
- * with `*` alone; without it, it reads every element's attributes, which on
49
- * a large page is most of its cost.
11
+ * `NoBuildId` when `SSR.hydrate` was given none, `OtherBuild` when the page
12
+ * names another deployment; otherwise why the envelope was refused.
50
13
  */
51
- readonly events?: Iterable<string> | undefined;
14
+ readonly reason: 'NoBuildId' | 'OtherBuild' | ResumeRefused['reason'];
52
15
  }
53
- /**
54
- * Listens at `root` for every event the bindings name, and answers each from
55
- * the markers. Returns what removes the listeners.
56
- */
57
- declare const listen: (root: Element, options: ListenOptions) => (() => void);
58
- //#endregion
59
- //#region src/resumable.d.ts
60
- /** The attribute prefix of an element's binding marker. */
61
- declare const BINDING_ATTRIBUTE = "data-foldkit-plus-on-";
62
- /** The posted field that carries a form's encoded Message, for the server fallback. */
63
- declare const FALLBACK_FIELD = "foldkit-plus-message";
64
- /** The attribute on a placement's root naming its slot, while the server renders. */
65
- declare const SLOT_ATTRIBUTE = "data-foldkit-plus-slot";
66
- declare const invalid: unique symbol;
67
- /** A compile-time failure that names its cause. */
68
- interface Invalid<Message extends string> {
69
- readonly [invalid]: Message;
16
+ /** A static region the browser asked for that the server's page did not hold, rendered in the browser. */
17
+ interface StaticRegionMissing extends Diagnostic {
18
+ readonly _tag: 'StaticRegionMissing';
19
+ readonly region: string;
70
20
  }
71
- type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
72
- /** A Message constructor from `defineMessageUnion`: a tagged Schema that can be called. */
73
- type AnyMemberSchema = Schema.Top & {
74
- readonly fields: Schema.Struct.Fields;
75
- };
76
- /** The Message a member makes. */
77
- type Made<M> = M extends {
78
- readonly Type: infer T;
79
- } ? T : never;
80
- /** The fields a member's event may be given fixed: all but `_tag`. */
81
- type Fixable<M> = Partial<Omit<Made<M>, '_tag'>>;
82
- /** The fields of a member the event fills: those neither `_tag` nor fixed. */
83
- type Rest<M, Fixed> = Omit<Made<M>, '_tag' | keyof Fixed>;
84
- type ProducesMessage<M, Message> = [Made<M>] extends [Message] ? unknown : Invalid<"the member is not one of this view's Messages">;
85
- type TextHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends [never] ? Invalid<'the member has no field left for the event to fill'> : true extends IsUnion<keyof Rest<M, Fixed>> ? Invalid<'the member leaves more than one field for the event to fill: fix the others'> : Rest<M, Fixed>[keyof Rest<M, Fixed>] extends string ? string extends Rest<M, Fixed>[keyof Rest<M, Fixed>] ? unknown : Invalid<'the field the event fills must be a string'> : Invalid<'the field the event fills must be a string'>;
86
- type KeyHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends ['key' | 'modifiers'] ? ['key' | 'modifiers'] extends [keyof Rest<M, Fixed>] ? unknown : Invalid<'the member must leave exactly key and modifiers for the event to fill'> : Invalid<'the member must leave exactly key and modifiers for the event to fill'>;
87
- /** `OnInput` and `OnChange`: a closure, or a member whose one string field the event fills. */
88
- interface TextHole<Message> {
89
- (toMessage: (value: string) => Message): Attribute<Message>;
90
- <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(member: M & ProducesMessage<M, Message> & TextHoleCheck<M, Fixed>, fixed?: Fixed): Attribute<Message>;
21
+ /** A lazy bundle whose bodies did not load; the runtime boots without them. */
22
+ interface BundleUnloaded extends Diagnostic {
23
+ readonly _tag: 'BundleUnloaded';
24
+ readonly error: unknown;
91
25
  }
92
- /** `OnKeyDown` and `OnKeyUp`: a closure, or a member whose `key` and `modifiers` the event fills. */
93
- interface KeyHole<Message> {
94
- (toMessage: (key: string, modifiers: KeyboardModifiers) => Message): Attribute<Message>;
95
- <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(member: M & ProducesMessage<M, Message> & KeyHoleCheck<M, Fixed>, fixed?: Fixed): Attribute<Message>;
26
+ /** A request answered 500: its `headers` threw, or its page could not be rendered. */
27
+ interface PageFailed extends Diagnostic {
28
+ readonly _tag: 'PageFailed';
29
+ readonly url: string;
30
+ readonly cause: Cause.Cause<unknown>;
96
31
  }
97
- /**
98
- * A builder a view is given: Foldkit's `HtmlBuilder`, or a Surface renderer's,
99
- * which leaves out Foldkit's phantom key. Its Message is what `OnClick` takes.
100
- */
101
- type AnyBuilder = {
102
- readonly OnClick: (message: never, ...rest: ReadonlyArray<never>) => unknown;
103
- };
104
- /** The Message a builder's handlers make. */
105
- type MessageOf<Builder> = Builder extends {
106
- readonly OnClick: (message: infer Message, ...rest: ReadonlyArray<never>) => unknown;
107
- } ? Message : never;
108
- /**
109
- * The resumable builder for a view whose Messages are `Message`: its elements
110
- * and attributes, and the hole forms of the four value events. One shape
111
- * whether it wraps a view's `HtmlBuilder` or a Surface renderer's builder, so a
112
- * helper typed with it takes either. It keeps Foldkit's phantom Message key,
113
- * so a placement's view accepts it as the parent's builder.
114
- */
115
- type ResumableBuilder<Message> = Omit<HtmlBuilder<Message>, 'OnInput' | 'OnChange' | 'OnKeyDown' | 'OnKeyUp'> & {
116
- readonly OnInput: TextHole<Message>;
117
- readonly OnChange: TextHole<Message>;
118
- readonly OnKeyDown: KeyHole<Message>;
119
- readonly OnKeyUp: KeyHole<Message>;
120
- };
121
- /**
122
- * The resumable builder for a view's `h`. Use it in place of `h`; it has the
123
- * same elements and attributes, and the hole forms of the four value events.
124
- */
125
- declare const builder: <Builder extends AnyBuilder>(h: Builder) => ResumableBuilder<MessageOf<Builder>>;
126
- /**
127
- * A view or renderer written against the resumable builder, as one that takes
128
- * the builder it is given: `Surface.rootView(Page, params, Resume.view(render))`,
129
- * `SurfaceView.define`, or an application's own view.
130
- */
131
- declare const view: <Model, Builder extends AnyBuilder, Out>(render: (model: Model, rh: ResumableBuilder<MessageOf<Builder>>) => Out) => (model: Model, h: Builder) => Out;
132
- //#endregion
133
- //#region src/context.d.ts
32
+ /** A handler the page cannot name, so its event waits for the live runtime. Reported once per process. */
33
+ interface HandlerUnnamed extends Diagnostic {
34
+ readonly _tag: 'HandlerUnnamed';
35
+ readonly plan: string;
36
+ readonly element: string;
37
+ readonly event: string;
38
+ }
39
+ /** Every diagnostic SSR reports. */
40
+ type SsrDiagnostic = PageContained | StaticRegionMissing | BundleUnloaded | PageFailed | HandlerUnnamed;
41
+ declare const pageContained: (reason: PageContained['reason'], detail: string) => PageContained;
42
+ declare const noBuildId: PageContained;
43
+ /** The page's stamped build id, if it has one, is not the client's `client`. */
44
+ declare const otherBuild: (served: Option.Option<string>, client: string) => PageContained;
45
+ declare const staticRegionMissing: (region: string) => StaticRegionMissing;
46
+ declare const bundleUnloaded: (error: unknown) => BundleUnloaded;
47
+ declare const pageFailed: (url: string, cause: Cause.Cause<unknown>) => PageFailed;
48
+ declare const handlerUnnamed: (plan: string, element: string, event: string) => HandlerUnnamed;
49
+ /** `effect` reporting to `report` when one is given, else to the reporter in its context. */
50
+ declare const reportingTo: (report: ReportDiagnostic | undefined) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
134
51
  type Region = ReadonlyArray<Html | string>;
135
52
  /** An element whose handler for `event` is a function, which the page cannot describe. */
136
53
  interface UnnamedHandler {
137
54
  readonly element: string;
138
55
  readonly event: string;
139
56
  }
140
- //#endregion
141
- //#region src/shared.d.ts
57
+ /**
58
+ * An element's binding as the server's render records it, before encoding:
59
+ * the Foldkit attribute and its DOM event, the element for diagnostics, and
60
+ * the Message it causes. For a Message with a hole, `message` is the Message
61
+ * with the hole filled by a placeholder, and `hole` names the fields the event
62
+ * fills.
63
+ */
64
+ interface Binding {
65
+ /** Foldkit's attribute, whose tag says what the handler does beside dispatching. */
66
+ readonly attribute: string;
67
+ readonly event: string;
68
+ readonly element: string;
69
+ readonly message: unknown;
70
+ readonly hole?: ReadonlyArray<string> | undefined;
71
+ /** How many placement wrappers enclose the hole's fields: `message` is entered that many times. */
72
+ readonly depth?: number | undefined;
73
+ readonly options?: unknown;
74
+ }
75
+ type RenderContext = {
76
+ readonly mode: 'collect';
77
+ readonly regions: Map<string, Region>;
78
+ readonly duplicates: Set<string>;
79
+ readonly bindings: Array<Binding>;
80
+ /** Encodes a form's Message for its no-script fallback; absent when the plan has none. */
81
+ readonly fallback: ((message: unknown) => string | undefined) | undefined;
82
+ /** Lifts a Message of the view in progress to the application's, through each enclosing placement. */
83
+ wrap: (message: unknown) => unknown;
84
+ /** How many placements enclose the view in progress. */
85
+ depth: number;
86
+ /** The static region whose render is in progress, if any. */
87
+ region: string | undefined;
88
+ /** Handlers met inside a static region, which the server alone renders. */
89
+ readonly inStatic: Array<{
90
+ readonly region: string;
91
+ readonly element: string;
92
+ readonly event: string;
93
+ }>;
94
+ /** Each element and event marked `*`: a handler the page cannot name. */
95
+ readonly unnamed: Array<UnnamedHandler>;
96
+ /** Why each `KeepTyped` field met cannot be replayed, one line each. */
97
+ readonly unkeepable: Array<string>;
98
+ } | {
99
+ readonly mode: 'replay';
100
+ readonly regions: ReadonlyMap<string, Region>;
101
+ readonly bindings: Array<Binding>;
102
+ readonly fallback: ((message: unknown) => string | undefined) | undefined;
103
+ wrap: (message: unknown) => unknown;
104
+ depth: number;
105
+ } | {
106
+ readonly mode: 'resume';
107
+ readonly snapshots: ReadonlyMap<string, string>;
108
+ /** The regions already reported missing, so each is reported once. */
109
+ readonly reported: Set<string>;
110
+ readonly report: (diagnostic: StaticRegionMissing) => void;
111
+ };
112
+ /** The context of the view call in progress, if any. */
113
+ declare const current: () => RenderContext | undefined;
114
+ declare const within: <A>(next: RenderContext, run: () => A) => A;
115
+ /** The config whose view runs inside `next`. */
116
+ declare const withContext: <Config extends {
117
+ readonly view: (model: any, h: any) => unknown;
118
+ }>(config: Config, next: RenderContext) => Config;
142
119
  /**
143
120
  * The attribute Foldkit's server stamps on an application's root, as
144
121
  * `foldkit/experimental/server` exports it. Written out here so a page can
@@ -151,12 +128,27 @@ declare const FOLDKIT_APP_ATTRIBUTE = "data-foldkit-app";
151
128
  * beside the app stamp, and the client reads it before adopting anything.
152
129
  */
153
130
  declare const RESUME_ATTRIBUTE = "data-foldkit-plus-resume";
131
+ /** The envelope format this package writes and reads. */
132
+ declare const PROTOCOL = 1;
133
+ /**
134
+ * The comment a render's `styles` follow in the stamped root. Hydration
135
+ * removes children the view does not draw, so `SSR.hydrate` moves what
136
+ * follows it into the head before adopting the page.
137
+ */
138
+ declare const STYLES_MARKER = "foldkit-plus-styles";
154
139
  /**
155
140
  * JSON for a script element: `<` is escaped so `</script>` in the data ends
156
141
  * nothing. U+2028 and U+2029 are escaped too: they are fine in JSON and break a
157
142
  * reader that treats the text as JavaScript.
158
143
  */
159
144
  declare const serializeJsonScript: (value: unknown) => string;
145
+ /**
146
+ * The envelope JSON as the stamped root carries it: `serializeJsonScript`
147
+ * already escaped `<` and the line separators, and an attribute must escape
148
+ * `&` and `"` besides, so no string in the Model can break out of the value.
149
+ * `getAttribute` resolves the entities back, which is exactly the JSON.
150
+ */
151
+ declare const attributeOf: (json: string) => string;
160
152
  /**
161
153
  * What a page says of itself beyond Foldkit's `Document` (`title`, `lang`,
162
154
  * `dir`, `canonical`, `ogUrl`): what a search result and a link preview show.
@@ -185,8 +177,27 @@ interface Meta {
185
177
  declare const META_ATTRIBUTE = "data-foldkit-meta";
186
178
  /** The head markup of a `Meta`, every value escaped, one element per line. */
187
179
  declare const metaMarkup: (meta: Meta) => string;
180
+ /**
181
+ * The Subscription entry that keeps the head's `meta` elements in step with
182
+ * the Model, so a move within the page (another post) changes its
183
+ * description too. It writes the head and sends no Message.
184
+ */
185
+ declare const metaEntry: <Model>(meta: (model: Model) => Meta) => {
186
+ dependenciesSchema: Schema.String;
187
+ modelToDependencies: (model: Model) => string;
188
+ dependenciesToStream: (markup: string) => Stream.Stream<never, never, never>;
189
+ };
188
190
  /** One entry of a resume plan's `surfaces`: a lone Surface, or a `Surface.each` family. */
189
191
  type PlanSurface<Model> = ActiveSurface<Model> | SurfaceSource<Model>;
192
+ /**
193
+ * What a plan entry resolves to for a Model: the lone projection of a
194
+ * `Surface.at`/`Surface.when` value, or a family's parent first and then each
195
+ * instance. The parent joins so the envelope carries what the instances were
196
+ * discovered through, not just what they read.
197
+ */
198
+ declare const projectionsOf: <Model>(source: PlanSurface<Model>, model: Model) => ReadonlyArray<{
199
+ readonly metadata: Metadata;
200
+ }>;
190
201
  /**
191
202
  * Which part of the Model the browser owns, and what it starts from.
192
203
  *
@@ -200,7 +211,7 @@ interface ResumePlan<Model, Fields extends Schema.Struct.Fields, Commands = unkn
200
211
  readonly state: WritableProjection<Model, Fields>;
201
212
  readonly baseline: Model;
202
213
  readonly boot?: ((model: Model) => Commands) | undefined;
203
- /** Model paths allowed to start from the baseline, as `ModelRef.dependency` gives them. */
214
+ /** Model paths allowed to start from the baseline, as each place's focus gives them. */
204
215
  readonly local: ReadonlyArray<ReadonlyArray<string>>;
205
216
  /** The Surfaces the browser may activate, which the plan must cover. */
206
217
  readonly surfaces: ReadonlyArray<PlanSurface<Model>>;
@@ -266,6 +277,12 @@ declare const ResumeRefused_base: Schema.Class<ResumeRefused, Schema.TaggedStruc
266
277
  }>, import("effect/Cause").YieldableError>;
267
278
  /** Why a page's resume envelope was refused. */
268
279
  declare class ResumeRefused extends ResumeRefused_base {}
280
+ declare const refuse: (reason: ResumeRefused['reason'], message: string) => Result.Result<never, ResumeRefused>;
281
+ /**
282
+ * The slice's Schema as a codec needing no services. A resume plan's state is
283
+ * plain data, so any field that needs one cannot cross a page anyway.
284
+ */
285
+ declare const codecOf: <Fields extends Schema.Struct.Fields>(schema: Schema.Struct<Fields>) => Schema.Codec<Schema.Struct.Type<Fields>, unknown>;
269
286
  /**
270
287
  * A resume plan for an application. The baseline defaults to the
271
288
  * application's initial Model. It is never written: a writable projection's
@@ -285,9 +302,7 @@ declare const plan: <Model, Fields extends Schema.Struct.Fields, Commands = unkn
285
302
  readonly state: WritableProjection<Model, Fields>;
286
303
  readonly baseline?: Model | undefined;
287
304
  readonly boot?: ((model: Model) => Commands) | undefined;
288
- readonly local?: ReadonlyArray<{
289
- readonly dependency: ReadonlyArray<string>;
290
- }> | undefined;
305
+ readonly local?: ReadonlyArray<ModelPlace<NoInfer<Model>>> | undefined;
291
306
  readonly surfaces?: ReadonlyArray<PlanSurface<Model>> | undefined;
292
307
  readonly parts?: ReadonlyArray<ResumePart<Model>> | undefined;
293
308
  readonly start?: Start | undefined;
@@ -303,6 +318,17 @@ declare const plan: <Model, Fields extends Schema.Struct.Fields, Commands = unkn
303
318
  * for every query, and for `/about` and `/about/` alike.
304
319
  */
305
320
  type RouteMatch = 'full' | 'path';
321
+ /** A path as a `path` match compares it. */
322
+ declare const pathKey: (route: string) => string;
323
+ /**
324
+ * The Model a payload resumes: the baseline with the slice set onto it, then
325
+ * each part restored, in order. Every part the plan names must be there and
326
+ * restore, and no other may be: a page is never half-restored.
327
+ */
328
+ declare const modelFrom: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, payload: {
329
+ readonly state: unknown;
330
+ readonly parts?: unknown;
331
+ }) => Result.Result<Model, string>;
306
332
  /**
307
333
  * The Model a page resumes from: the baseline with the stamped root's envelope
308
334
  * set onto it. Refused, with the reason, when the page holds no stamped root
@@ -313,6 +339,20 @@ type RouteMatch = 'full' | 'path';
313
339
  declare const resume: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, page: ParentNode, options?: {
314
340
  readonly route?: string | undefined;
315
341
  }) => Result.Result<Model, ResumeRefused>;
342
+ /**
343
+ * The Message telling the application the URL it is at, when the page was
344
+ * recorded for its path alone and the browser is at a query: `init` never ran
345
+ * here, so the application would otherwise never learn the query. None for
346
+ * an application without routing, or a page at no query.
347
+ */
348
+ declare const arrival: <Model, Message>(config: ResumableConfig<Model, Message>, page: ParentNode, href: string) => Option.Option<Message>;
349
+ /** The tag a Message value carries, for naming it. */
350
+ declare const tagOf: (message: unknown) => string;
351
+ /**
352
+ * The Message tags the plan's Surfaces active for `model` may send, which is
353
+ * what a page's bindings may dispatch (the design's rule 3).
354
+ */
355
+ declare const allowedTags: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, model: Model) => ReadonlySet<string>;
316
356
  /** The attribute on a static region's element, naming the region. */
317
357
  declare const STATIC_ATTRIBUTE = "data-foldkit-plus-static";
318
358
  /**
@@ -375,6 +415,60 @@ interface Loadable {
375
415
  readonly load: () => Promise<void>;
376
416
  readonly isLoaded: () => boolean;
377
417
  }
418
+ /** The config whose `init` returns this start, whatever arguments it is given. */
419
+ declare const startingFrom: <Model>(config: ResumableConfig<Model>, start: {
420
+ readonly model: Model;
421
+ readonly commands?: ReadonlyArray<unknown> | undefined;
422
+ }) => {
423
+ ports?: Readonly<{
424
+ inbound?: Readonly<Record<string, import("foldkit/port").Inbound<any, any>>>;
425
+ outbound?: Readonly<Record<string, import("foldkit/port").Outbound<any, any>>>;
426
+ }> | undefined;
427
+ crash?: Readonly<{
428
+ view?: (context: Readonly<{
429
+ error: Error;
430
+ model: Model;
431
+ message: Option.Option<any>;
432
+ }>, h: HtmlBuilder<never>) => Readonly<{
433
+ title: string;
434
+ lang?: string;
435
+ dir?: import("foldkit/html").TextDirection;
436
+ canonical?: string;
437
+ ogUrl?: string;
438
+ body: Html;
439
+ }>;
440
+ report?: (context: Readonly<{
441
+ error: Error;
442
+ model: Model;
443
+ message: Option.Option<any>;
444
+ }>) => void;
445
+ }>;
446
+ slow?: Runtime.SlowConfig<Model, any>;
447
+ viewTransition?: Runtime.ViewTransitionConfig<Model, any>;
448
+ freezeModel?: boolean;
449
+ preserveScroll?: boolean;
450
+ devTools?: Runtime.DevToolsConfig;
451
+ routing?: Readonly<{
452
+ onUrlRequest: (request: import("foldkit/navigation").UrlRequest) => any;
453
+ onUrlChange: (url: import("foldkit/url").Url) => any;
454
+ }>;
455
+ Model: Schema.Codec<Model, any, unknown, unknown>;
456
+ update: (model: Model, message: any) => {
457
+ readonly model: Model;
458
+ };
459
+ view: (model: Model, h: any) => unknown;
460
+ container: HTMLElement | null;
461
+ subscriptions?: Readonly<Record<string, unknown>> | undefined;
462
+ managedResources?: Readonly<Record<string, unknown>> | undefined;
463
+ resources?: Layer.Layer<never, never, never> | undefined;
464
+ lazy?: ReadonlyArray<Loadable> | undefined;
465
+ init: () => {
466
+ readonly model: Model;
467
+ readonly commands?: ReadonlyArray<unknown> | undefined;
468
+ };
469
+ };
470
+ /** A route as the envelope records it: the path and the query. */
471
+ declare const routeOf: (url: string) => string;
378
472
  /**
379
473
  * The page's bindings, decoded through the plan's Message Schema, kept to the
380
474
  * Messages the Surfaces active for `model` may send, and checked against
@@ -384,68 +478,13 @@ interface Loadable {
384
478
  * is answered whole or not at all.
385
479
  */
386
480
  declare const bindings: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, page: ParentNode, root: Element, model: Model) => Result.Result<ReadonlyArray<DecodedBinding>, ResumeRefused>;
387
- //#endregion
388
- //#region src/client.d.ts
389
481
  /**
390
- * Starts the browser from the page's resumed Model, without running `init`.
391
- *
392
- * In the order Foldkit checks a page: the build id first, before the payload
393
- * is read, then the envelope and its route. A page from another build is
394
- * refused by Foldkit itself. A page that cannot resume is refused and contained
395
- * by Foldkit's own refusal, and the reason is logged. A server page is never
396
- * rendered again on the client. A page with no server render at all, no
397
- * stamped root, is rendered on the client as usual.
482
+ * `bindings`, and the events the envelope says the markers name, if it says:
483
+ * a page from before the envelope listed them leaves `listen` to find them.
398
484
  */
399
- declare const hydrate: <Model, Fields extends Schema.Struct.Fields, Message = any>(config: ResumableConfig<Model, Message>, plan: ResumePlan<Model, Fields>, options: {
400
- readonly buildId: string;
401
- /**
402
- * Whether this page is taken over: asked before anything is adopted, so
403
- * a page showing another reader's data never becomes live facts. Omitted
404
- * adopts as before. Must not throw: a throwing predicate propagates out
405
- * of `hydrate` with no runtime booted and nothing contained.
406
- */
407
- readonly when?: ((page: Document) => boolean) | undefined;
408
- /**
409
- * What a declined or stale page does: `render` runs the application
410
- * afresh where the rendered page is, replacing its markup in place (the
411
- * config's container with no served page). Omitted contains the page the
412
- * way a resume failure does.
413
- */
414
- readonly otherwise?: 'render' | undefined;
415
- /**
416
- * With `otherwise: 'render'`, when the fresh application is ready to be
417
- * seen: until a Model it has drawn satisfies this, it draws out of view
418
- * and the served page stays, so a page is not swapped for its loading
419
- * state and back. Omitted, the fresh application replaces the page at
420
- * once. The served page stays no longer than `UNTIL_LIMIT_MS`.
421
- */
422
- readonly until?: ((model: Model) => boolean) | undefined;
423
- /**
424
- * Whether the plan's data version is still current: asked once, with
425
- * `plan.version`, before anything is adopted. Omitted never asks. A plan
426
- * with no version still asks, with `undefined` (a check shaped like
427
- * `version === expected` then marks every such page stale). Must not
428
- * throw, as `when`.
429
- */
430
- readonly fresh?: ((version: unknown) => boolean) | undefined;
431
- }) => void;
432
- /** The longest a served page stays in view while a fresh application waits for `until`. */
433
- declare const UNTIL_LIMIT_MS = 3000;
434
- /** The resumable track: bindings the server's markup names, so a page can answer before it boots. */
435
- declare const Resume: {
436
- builder: typeof builder;
437
- view: typeof view;
438
- bindings: typeof bindings;
439
- listen: typeof listen;
440
- };
441
- /** The browser's part of `SSR`: the same functions, without the server's. */
442
- declare const SSR: {
443
- plan: typeof plan;
444
- resume: typeof resume;
445
- hydrate: typeof hydrate;
446
- static: typeof staticRegion;
447
- serving: typeof serving;
448
- };
449
- //#endregion
450
- export { UnnamedHandler as C, SLOT_ATTRIBUTE as D, ResumableBuilder as E, DecodedBinding as O, staticRegion as S, FALLBACK_FIELD as T, metaMarkup as _, Loadable as a, serializeJsonScript as b, PlanSurface as c, ResumePart as d, ResumePlan as f, Start as g, STATIC_ATTRIBUTE as h, FOLDKIT_APP_ATTRIBUTE as i, EncodedBinding as k, RESUME_ATTRIBUTE as l, RouteMatch as m, SSR as n, META_ATTRIBUTE as o, ResumeRefused as p, UNTIL_LIMIT_MS as r, Meta as s, Resume as t, ResumableConfig as u, plan as v, BINDING_ATTRIBUTE as w, serving as x, resume as y };
451
- //# sourceMappingURL=client-DkwAniQQ.d.mts.map
485
+ declare const bindingsAndEvents: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, page: ParentNode, root: Element, model: Model) => Result.Result<{
486
+ readonly bindings: ReadonlyArray<DecodedBinding>;
487
+ readonly events: ReadonlyArray<string> | undefined;
488
+ }, ResumeRefused>;
489
+ export { pageContained as $, routeOf as A, current as B, metaMarkup as C, projectionsOf as D, plan as E, tagOf as F, PageContained as G, within as H, Binding as I, StaticRegionMissing as J, PageFailed as K, Region as L, serving as M, startingFrom as N, refuse as O, staticRegion as P, otherBuild as Q, RenderContext as R, metaEntry as S, pathKey as T, BundleUnloaded as U, withContext as V, HandlerUnnamed as W, handlerUnnamed as X, bundleUnloaded as Y, noBuildId as Z, arrival as _, PROTOCOL as a, bindingsAndEvents as b, ResumableConfig as c, ResumeRefused as d, pageFailed as et, RouteMatch as f, allowedTags as g, Start as h, Meta as i, serializeJsonScript as j, resume as k, ResumePart as l, STYLES_MARKER as m, Loadable as n, staticRegionMissing as nt, PlanSurface as o, STATIC_ATTRIBUTE as p, SsrDiagnostic as q, META_ATTRIBUTE as r, RESUME_ATTRIBUTE as s, FOLDKIT_APP_ATTRIBUTE as t, reportingTo as tt, ResumePlan as u, attributeOf as v, modelFrom as w, codecOf as x, bindings as y, UnnamedHandler as z };
490
+ //# sourceMappingURL=shared-DbupL3vO.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-DbupL3vO.d.ts","names":[],"sources":["../src/diagnostics.ts","../src/context.ts","../src/shared.ts"],"mappings":";;;;;;;UAaiB,sBAAsB;WAC5B;;;;;WAKA,qCAAqC;;;UAI/B,4BAA4B;WAClC;WACA;;;UAIM,uBAAuB;WAC7B;WACA;;;UAIM,mBAAmB;WACzB;WACA;WACA,OAAO,MAAM;;;UAIP,uBAAuB;WAC7B;WACA;WACA;WACA;;;KAIC,gBACR,gBACA,sBACA,iBACA,aACA;cAES,gBAAa,QAAY,yBAAuB,mBAAmB;cAQnE,WAAW;;cAMX,aAAU,QAAY,OAAO,gBAAc,mBAAmB;cAS9D,sBAAmB,mBAAqB;cAQxC,iBAAc,mBAAqB;cAQnC,aAAU,aAAe,OAAS,MAAM,mBAAiB;cASzD,iBAAc,cAAgB,iBAAiB,kBAAkB;;cAWjE,cAAW,QACb,kCACR,GAAG,GAAG,GAAC,QAAU,OAAO,OAAO,GAAG,GAAG,OAAK,OAAO,OAAO,GAAG,GAAG;KCpGrD,SAAS,cAAc;;UAGlB;WACN;WACA;;;;;;;;;UAUM;;WAEN;WACA;WACA;WACA;WACA,OAAO;;WAEP;WACA;;KAGC;WAEG;WACA,SAAS,YAAY;WACrB,YAAY;WACZ,UAAU,MAAM;;WAEhB,YAAY;;EAErB,OAAO;;EAEP;;EAEA;;WAES,UAAU;aACR;aACA;aACA;;;WAGF,SAAS,MAAM;;WAEf,YAAY;;WAGZ;WACA,SAAS,oBAAoB;WAC7B,UAAU,MAAM;WAChB,YAAY;EACrB,OAAO;EACP;;WAGS;WACA,WAAW;;WAEX,UAAU;WACV,SAAS,YAAY;;;cAMvB,eAAc;cAWd,SAAU,GAAC,MAAQ,eAAa,WAAa,MAAI;;cAejD,cAAe;WAA0B,OAAO,YAAY;GAAoB,QACnF,QAAM,MACR,kBACL;;;;;;cC3FU;;;;;;cAOA;;cAGA;;;;;;cAO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K,gBAAA,SAAS;EACN,mBAAA,SAAS;EAEhB,YAAA,MAAM;EAMX,OAAA,cAAc;;aAuBL,OAAA;aAA2B,WAAA;;;;cAIzC,UAAO;;;;;;;;;cAaP,WAAY,OAAO,eAAe,OAAO,OAAO,QAAM,MAC3D,WAAW,OAAO,SAAO,MACzB,YAAU,MACV,SAAO,OACN,UACN,OAAO,OAAO,cAAc,iBAAiB;;;;;cASnC,oBAAqB,OAAO,eAAe,OAAO,OAAO,QAAM,MACpE,WAAW,OAAO,SAAO,MACzB,YAAU,MACV,SAAO,OACN,UACN,OAAO;WAEG,UAAU,cAAc;WACxB,QAAQ;GAEnB"}
@@ -0,0 +1,2 @@
1
+ import { A as routeOf, C as metaMarkup, D as projectionsOf, E as plan, F as tagOf, M as serving, N as startingFrom, O as refuse, P as staticRegion, S as metaEntry, T as pathKey, _ as arrival, a as PROTOCOL, b as bindingsAndEvents, c as ResumableConfig, d as ResumeRefused, f as RouteMatch, g as allowedTags, h as Start, i as Meta, j as serializeJsonScript, k as resume, l as ResumePart, m as STYLES_MARKER, n as Loadable, o as PlanSurface, p as STATIC_ATTRIBUTE, r as META_ATTRIBUTE, s as RESUME_ATTRIBUTE, t as FOLDKIT_APP_ATTRIBUTE, u as ResumePlan, v as attributeOf, w as modelFrom, x as codecOf, y as bindings } from "./shared-DbupL3vO.js";
2
+ export { FOLDKIT_APP_ATTRIBUTE, Loadable, META_ATTRIBUTE, Meta, PROTOCOL, PlanSurface, RESUME_ATTRIBUTE, ResumableConfig, ResumePart, ResumePlan, ResumeRefused, RouteMatch, STATIC_ATTRIBUTE, STYLES_MARKER, Start, allowedTags, arrival, attributeOf, bindings, bindingsAndEvents, codecOf, metaEntry, metaMarkup, modelFrom, pathKey, plan, projectionsOf, refuse, resume, routeOf, serializeJsonScript, serving, startingFrom, staticRegion, tagOf };