foldkit-ssr 0.8.1 → 0.9.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 (50) hide show
  1. package/README.md +203 -69
  2. package/dist/client-F16QT0sc.d.ts +75 -0
  3. package/dist/client-F16QT0sc.d.ts.map +1 -0
  4. package/dist/client.d.ts +5 -0
  5. package/dist/client.js +271 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/context.d.ts +2 -0
  8. package/dist/context.js +21 -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} +18 -7
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/{index.mjs → index.js} +79 -60
  16. package/dist/index.js.map +1 -0
  17. package/dist/listen-zNd0IIAT.d.ts +69 -0
  18. package/dist/listen-zNd0IIAT.d.ts.map +1 -0
  19. package/dist/listen.d.ts +2 -0
  20. package/dist/listen.js +179 -0
  21. package/dist/listen.js.map +1 -0
  22. package/dist/requestContext-D9nsbGSJ.d.ts +21 -0
  23. package/dist/requestContext-D9nsbGSJ.d.ts.map +1 -0
  24. package/dist/requestContext.d.ts +2 -0
  25. package/dist/requestContext.js +48 -0
  26. package/dist/requestContext.js.map +1 -0
  27. package/dist/resumable-BWItJsxF.d.ts +86 -0
  28. package/dist/resumable-BWItJsxF.d.ts.map +1 -0
  29. package/dist/resumable.d.ts +2 -0
  30. package/dist/resumable.js +358 -0
  31. package/dist/resumable.js.map +1 -0
  32. package/dist/{client-DkwAniQQ.d.mts → shared-v1u-OEQI.d.ts} +218 -194
  33. package/dist/shared-v1u-OEQI.d.ts.map +1 -0
  34. package/dist/shared.d.ts +2 -0
  35. package/dist/shared.js +324 -0
  36. package/dist/shared.js.map +1 -0
  37. package/dist/{vite.d.mts → vite.d.ts} +3 -5
  38. package/dist/vite.d.ts.map +1 -0
  39. package/dist/{vite.mjs → vite.js} +3 -4
  40. package/dist/vite.js.map +1 -0
  41. package/package.json +17 -17
  42. package/dist/client-DVG9_3rL.mjs +0 -1113
  43. package/dist/client-DVG9_3rL.mjs.map +0 -1
  44. package/dist/client-DkwAniQQ.d.mts.map +0 -1
  45. package/dist/client.d.mts +0 -2
  46. package/dist/client.mjs +0 -1
  47. package/dist/index.d.mts.map +0 -1
  48. package/dist/index.mjs.map +0 -1
  49. package/dist/vite.d.mts.map +0 -1
  50. package/dist/vite.mjs.map +0 -1
@@ -1,144 +1,119 @@
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-zNd0IIAT.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
+ } | {
97
+ readonly mode: 'replay';
98
+ readonly regions: ReadonlyMap<string, Region>;
99
+ readonly bindings: Array<Binding>;
100
+ readonly fallback: ((message: unknown) => string | undefined) | undefined;
101
+ wrap: (message: unknown) => unknown;
102
+ depth: number;
103
+ } | {
104
+ readonly mode: 'resume';
105
+ readonly snapshots: ReadonlyMap<string, string>;
106
+ /** The regions already reported missing, so each is reported once. */
107
+ readonly reported: Set<string>;
108
+ readonly report: (diagnostic: StaticRegionMissing) => void;
109
+ };
110
+ /** The context of the view call in progress, if any. */
111
+ declare const current: () => RenderContext | undefined;
112
+ declare const within: <A>(next: RenderContext, run: () => A) => A;
113
+ /** The config whose view runs inside `next`. */
114
+ declare const withContext: <Config extends {
115
+ readonly view: (model: any, h: any) => unknown;
116
+ }>(config: Config, next: RenderContext) => Config;
142
117
  /**
143
118
  * The attribute Foldkit's server stamps on an application's root, as
144
119
  * `foldkit/experimental/server` exports it. Written out here so a page can
@@ -151,12 +126,21 @@ declare const FOLDKIT_APP_ATTRIBUTE = "data-foldkit-app";
151
126
  * beside the app stamp, and the client reads it before adopting anything.
152
127
  */
153
128
  declare const RESUME_ATTRIBUTE = "data-foldkit-plus-resume";
129
+ /** The envelope format this package writes and reads. */
130
+ declare const PROTOCOL = 1;
154
131
  /**
155
132
  * JSON for a script element: `<` is escaped so `</script>` in the data ends
156
133
  * nothing. U+2028 and U+2029 are escaped too: they are fine in JSON and break a
157
134
  * reader that treats the text as JavaScript.
158
135
  */
159
136
  declare const serializeJsonScript: (value: unknown) => string;
137
+ /**
138
+ * The envelope JSON as the stamped root carries it: `serializeJsonScript`
139
+ * already escaped `<` and the line separators, and an attribute must escape
140
+ * `&` and `"` besides, so no string in the Model can break out of the value.
141
+ * `getAttribute` resolves the entities back, which is exactly the JSON.
142
+ */
143
+ declare const attributeOf: (json: string) => string;
160
144
  /**
161
145
  * What a page says of itself beyond Foldkit's `Document` (`title`, `lang`,
162
146
  * `dir`, `canonical`, `ogUrl`): what a search result and a link preview show.
@@ -185,8 +169,27 @@ interface Meta {
185
169
  declare const META_ATTRIBUTE = "data-foldkit-meta";
186
170
  /** The head markup of a `Meta`, every value escaped, one element per line. */
187
171
  declare const metaMarkup: (meta: Meta) => string;
172
+ /**
173
+ * The Subscription entry that keeps the head's `meta` elements in step with
174
+ * the Model, so a move within the page (another post) changes its
175
+ * description too. It writes the head and sends no Message.
176
+ */
177
+ declare const metaEntry: <Model>(meta: (model: Model) => Meta) => {
178
+ dependenciesSchema: Schema.String;
179
+ modelToDependencies: (model: Model) => string;
180
+ dependenciesToStream: (markup: string) => Stream.Stream<never, never, never>;
181
+ };
188
182
  /** One entry of a resume plan's `surfaces`: a lone Surface, or a `Surface.each` family. */
189
183
  type PlanSurface<Model> = ActiveSurface<Model> | SurfaceSource<Model>;
184
+ /**
185
+ * What a plan entry resolves to for a Model: the lone projection of a
186
+ * `Surface.at`/`Surface.when` value, or a family's parent first and then each
187
+ * instance. The parent joins so the envelope carries what the instances were
188
+ * discovered through, not just what they read.
189
+ */
190
+ declare const projectionsOf: <Model>(source: PlanSurface<Model>, model: Model) => ReadonlyArray<{
191
+ readonly metadata: Metadata;
192
+ }>;
190
193
  /**
191
194
  * Which part of the Model the browser owns, and what it starts from.
192
195
  *
@@ -200,7 +203,7 @@ interface ResumePlan<Model, Fields extends Schema.Struct.Fields, Commands = unkn
200
203
  readonly state: WritableProjection<Model, Fields>;
201
204
  readonly baseline: Model;
202
205
  readonly boot?: ((model: Model) => Commands) | undefined;
203
- /** Model paths allowed to start from the baseline, as `ModelRef.dependency` gives them. */
206
+ /** Model paths allowed to start from the baseline, as each place's focus gives them. */
204
207
  readonly local: ReadonlyArray<ReadonlyArray<string>>;
205
208
  /** The Surfaces the browser may activate, which the plan must cover. */
206
209
  readonly surfaces: ReadonlyArray<PlanSurface<Model>>;
@@ -266,6 +269,12 @@ declare const ResumeRefused_base: Schema.Class<ResumeRefused, Schema.TaggedStruc
266
269
  }>, import("effect/Cause").YieldableError>;
267
270
  /** Why a page's resume envelope was refused. */
268
271
  declare class ResumeRefused extends ResumeRefused_base {}
272
+ declare const refuse: (reason: ResumeRefused['reason'], message: string) => Result.Result<never, ResumeRefused>;
273
+ /**
274
+ * The slice's Schema as a codec needing no services. A resume plan's state is
275
+ * plain data, so any field that needs one cannot cross a page anyway.
276
+ */
277
+ declare const codecOf: <Fields extends Schema.Struct.Fields>(schema: Schema.Struct<Fields>) => Schema.Codec<Schema.Struct.Type<Fields>, unknown>;
269
278
  /**
270
279
  * A resume plan for an application. The baseline defaults to the
271
280
  * application's initial Model. It is never written: a writable projection's
@@ -285,9 +294,7 @@ declare const plan: <Model, Fields extends Schema.Struct.Fields, Commands = unkn
285
294
  readonly state: WritableProjection<Model, Fields>;
286
295
  readonly baseline?: Model | undefined;
287
296
  readonly boot?: ((model: Model) => Commands) | undefined;
288
- readonly local?: ReadonlyArray<{
289
- readonly dependency: ReadonlyArray<string>;
290
- }> | undefined;
297
+ readonly local?: ReadonlyArray<ModelPlace<NoInfer<Model>>> | undefined;
291
298
  readonly surfaces?: ReadonlyArray<PlanSurface<Model>> | undefined;
292
299
  readonly parts?: ReadonlyArray<ResumePart<Model>> | undefined;
293
300
  readonly start?: Start | undefined;
@@ -303,6 +310,17 @@ declare const plan: <Model, Fields extends Schema.Struct.Fields, Commands = unkn
303
310
  * for every query, and for `/about` and `/about/` alike.
304
311
  */
305
312
  type RouteMatch = 'full' | 'path';
313
+ /** A path as a `path` match compares it. */
314
+ declare const pathKey: (route: string) => string;
315
+ /**
316
+ * The Model a payload resumes: the baseline with the slice set onto it, then
317
+ * each part restored, in order. Every part the plan names must be there and
318
+ * restore, and no other may be: a page is never half-restored.
319
+ */
320
+ declare const modelFrom: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, payload: {
321
+ readonly state: unknown;
322
+ readonly parts?: unknown;
323
+ }) => Result.Result<Model, string>;
306
324
  /**
307
325
  * The Model a page resumes from: the baseline with the stamped root's envelope
308
326
  * set onto it. Refused, with the reason, when the page holds no stamped root
@@ -313,6 +331,13 @@ type RouteMatch = 'full' | 'path';
313
331
  declare const resume: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, page: ParentNode, options?: {
314
332
  readonly route?: string | undefined;
315
333
  }) => Result.Result<Model, ResumeRefused>;
334
+ /** The tag a Message value carries, for naming it. */
335
+ declare const tagOf: (message: unknown) => string;
336
+ /**
337
+ * The Message tags the plan's Surfaces active for `model` may send, which is
338
+ * what a page's bindings may dispatch (the design's rule 3).
339
+ */
340
+ declare const allowedTags: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, model: Model) => ReadonlySet<string>;
316
341
  /** The attribute on a static region's element, naming the region. */
317
342
  declare const STATIC_ATTRIBUTE = "data-foldkit-plus-static";
318
343
  /**
@@ -375,6 +400,60 @@ interface Loadable {
375
400
  readonly load: () => Promise<void>;
376
401
  readonly isLoaded: () => boolean;
377
402
  }
403
+ /** The config whose `init` returns this start, whatever arguments it is given. */
404
+ declare const startingFrom: <Model>(config: ResumableConfig<Model>, start: {
405
+ readonly model: Model;
406
+ readonly commands?: ReadonlyArray<unknown>;
407
+ }) => {
408
+ ports?: Readonly<{
409
+ inbound?: Readonly<Record<string, import("foldkit/port").Inbound<any, any>>>;
410
+ outbound?: Readonly<Record<string, import("foldkit/port").Outbound<any, any>>>;
411
+ }> | undefined;
412
+ crash?: Readonly<{
413
+ view?: (context: Readonly<{
414
+ error: Error;
415
+ model: Model;
416
+ message: Option.Option<any>;
417
+ }>, h: HtmlBuilder<never>) => Readonly<{
418
+ title: string;
419
+ lang?: string;
420
+ dir?: import("foldkit/html").TextDirection;
421
+ canonical?: string;
422
+ ogUrl?: string;
423
+ body: Html;
424
+ }>;
425
+ report?: (context: Readonly<{
426
+ error: Error;
427
+ model: Model;
428
+ message: Option.Option<any>;
429
+ }>) => void;
430
+ }>;
431
+ slow?: Runtime.SlowConfig<Model, any>;
432
+ viewTransition?: Runtime.ViewTransitionConfig<Model, any>;
433
+ freezeModel?: boolean;
434
+ preserveScroll?: boolean;
435
+ devTools?: Runtime.DevToolsConfig;
436
+ routing?: Readonly<{
437
+ onUrlRequest: (request: import("foldkit/navigation").UrlRequest) => any;
438
+ onUrlChange: (url: import("foldkit/url").Url) => any;
439
+ }>;
440
+ Model: Schema.Codec<Model, any, unknown, unknown>;
441
+ update: (model: Model, message: any) => {
442
+ readonly model: Model;
443
+ };
444
+ view: (model: Model, h: any) => unknown;
445
+ container: HTMLElement | null;
446
+ subscriptions?: Readonly<Record<string, unknown>> | undefined;
447
+ managedResources?: Readonly<Record<string, unknown>> | undefined;
448
+ resources?: Layer.Layer<never, never, never> | undefined;
449
+ lazy?: ReadonlyArray<Loadable> | undefined;
450
+ init: () => {
451
+ readonly model: Model;
452
+ readonly commands?: ReadonlyArray<unknown>;
453
+ };
454
+ };
455
+ /** A route as the envelope records it: the path and the query. */
456
+ declare const routeOf: (url: string) => string;
378
457
  /**
379
458
  * The page's bindings, decoded through the plan's Message Schema, kept to the
380
459
  * Messages the Surfaces active for `model` may send, and checked against
@@ -384,68 +463,13 @@ interface Loadable {
384
463
  * is answered whole or not at all.
385
464
  */
386
465
  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
466
  /**
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.
467
+ * `bindings`, and the events the envelope says the markers name, if it says:
468
+ * a page from before the envelope listed them leaves `listen` to find them.
398
469
  */
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
470
+ declare const bindingsAndEvents: <Model, Fields extends Schema.Struct.Fields>(plan: ResumePlan<Model, Fields>, page: ParentNode, root: Element, model: Model) => Result.Result<{
471
+ readonly bindings: ReadonlyArray<DecodedBinding>;
472
+ readonly events: ReadonlyArray<string> | undefined;
473
+ }, ResumeRefused>;
474
+ export { reportingTo as $, serving as A, within as B, pathKey as C, resume as D, refuse as E, Region as F, SsrDiagnostic as G, HandlerUnnamed as H, RenderContext as I, handlerUnnamed as J, StaticRegionMissing as K, UnnamedHandler as L, staticRegion as M, tagOf as N, routeOf as O, Binding as P, pageFailed as Q, current as R, modelFrom as S, projectionsOf as T, PageContained as U, BundleUnloaded as V, PageFailed as W, otherBuild as X, noBuildId as Y, pageContained as Z, bindings as _, PROTOCOL as a, metaEntry as b, ResumableConfig as c, ResumeRefused as d, staticRegionMissing as et, RouteMatch as f, attributeOf as g, allowedTags as h, Meta as i, startingFrom as j, serializeJsonScript as k, ResumePart as l, Start as m, Loadable as n, PlanSurface as o, STATIC_ATTRIBUTE as p, bundleUnloaded as q, META_ATTRIBUTE as r, RESUME_ATTRIBUTE as s, FOLDKIT_APP_ATTRIBUTE as t, ResumePlan as u, bindingsAndEvents as v, plan as w, metaMarkup as x, codecOf as y, withContext as z };
475
+ //# sourceMappingURL=shared-v1u-OEQI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-v1u-OEQI.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;cAS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;;;;;;cAgCzE;;;;;KASR,mBAAmB,OAAO,WAAW,QACxC,KACE,QAAQ,yBAAyB,OAAO,uBAAuB;;;;;;;UAkBlD,gBAAgB,OAAO,uBAAuB,mBAAmB,OAAO;WAC9E,OAAO,OAAO,MAAM;WACpB,UAAU,MAAM;aACd,OAAO;aACP,WAAW;eAAyB;;;WAEtC,SAAS,OAAO,OAAO,SAAS;aAAuB,OAAO;;WAC9D,OAAO,OAAO,OAAO;WACrB,WAAW;WACX;WACA,gBAAgB,SAAS;WACzB,mBAAmB,SAAS;;WAE5B,YAAY,MAAM;;;;;;WAMlB,OAAO,cAAc;;;UAIf;WACN;WACA,YAAY;WACZ;;;cAcE,eAAgB,OAAK,QACxB,gBAAgB,QAAM;WACZ,OAAO;WAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAnCnB,OAAA,OAAA,OAAA;EACb,WAAA;EAEK,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 serving, C as pathKey, D as resume, E as refuse, M as staticRegion, N as tagOf, O as routeOf, S as modelFrom, T as projectionsOf, _ as bindings, a as PROTOCOL, b as metaEntry, c as ResumableConfig, d as ResumeRefused, f as RouteMatch, g as attributeOf, h as allowedTags, i as Meta, j as startingFrom, k as serializeJsonScript, l as ResumePart, m as Start, 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 bindingsAndEvents, w as plan, x as metaMarkup, y as codecOf } from "./shared-v1u-OEQI.js";
2
+ export { FOLDKIT_APP_ATTRIBUTE, Loadable, META_ATTRIBUTE, Meta, PROTOCOL, PlanSurface, RESUME_ATTRIBUTE, ResumableConfig, ResumePart, ResumePlan, ResumeRefused, RouteMatch, STATIC_ATTRIBUTE, Start, allowedTags, attributeOf, bindings, bindingsAndEvents, codecOf, metaEntry, metaMarkup, modelFrom, pathKey, plan, projectionsOf, refuse, resume, routeOf, serializeJsonScript, serving, startingFrom, staticRegion, tagOf };