brumate 0.2.0 → 0.4.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 (138) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-D-IdPy7B.d.ts → boot-DLlRmD9z.d.ts} +11 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BvDsC6Qr.js +3463 -0
  7. package/dist/client-BvDsC6Qr.js.map +1 -0
  8. package/dist/client-DBwL2wKQ.d.ts +669 -0
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-Cnbf4w-S.js} +15 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-D0bo1Gqx.js → defer-CKWZLv2K.js} +8 -4
  14. package/dist/defer-CKWZLv2K.js.map +1 -0
  15. package/dist/devtools-4uTPwR_v.js +597 -0
  16. package/dist/devtools-4uTPwR_v.js.map +1 -0
  17. package/dist/devtools-panel-Be9pxYgv.js +1994 -0
  18. package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
  19. package/dist/events-LgLdp1R7.js +114 -0
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-WW4RlajL.js +506 -0
  24. package/dist/files-WW4RlajL.js.map +1 -0
  25. package/dist/forms-j1xPAR14.d.ts +281 -0
  26. package/dist/forms-nXK7-Lv_.js +440 -0
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.d.ts +17 -0
  29. package/dist/highlight.js +278 -0
  30. package/dist/highlight.js.map +1 -0
  31. package/dist/html-BtKRyi7g.js +305 -0
  32. package/dist/html-BtKRyi7g.js.map +1 -0
  33. package/dist/html-Bw9Qwu6F.d.ts +107 -0
  34. package/dist/index.d.ts +142 -11
  35. package/dist/index.js +641 -106
  36. package/dist/index.js.map +1 -1
  37. package/dist/{inspect-BJtACnQp.js → inspect-Y6y4uNZp.js} +4333 -681
  38. package/dist/inspect-Y6y4uNZp.js.map +1 -0
  39. package/dist/{loader-B18i3_-T.js → loader-BjKGJzLN.js} +21 -14
  40. package/dist/loader-BjKGJzLN.js.map +1 -0
  41. package/dist/logo-DQ_OYhBi.js +10 -0
  42. package/dist/logo-DQ_OYhBi.js.map +1 -0
  43. package/dist/{navigate-BwuZveDF.js → navigate-CfOr-TRF.js} +130 -24
  44. package/dist/navigate-CfOr-TRF.js.map +1 -0
  45. package/dist/nesting-DA5vJw9X.js +265 -0
  46. package/dist/nesting-DA5vJw9X.js.map +1 -0
  47. package/dist/produce-B7X9ori9.js +402 -0
  48. package/dist/produce-B7X9ori9.js.map +1 -0
  49. package/dist/produce-DIgHBVwL.d.ts +148 -0
  50. package/dist/{rpc-B-Zkn6Ch.js → rpc-Q-XkLwFh.js} +28 -13
  51. package/dist/rpc-Q-XkLwFh.js.map +1 -0
  52. package/dist/runtime/batch.js +9 -7
  53. package/dist/runtime/batch.js.map +1 -1
  54. package/dist/runtime/client.d.ts +4 -4
  55. package/dist/runtime/client.js +4 -4
  56. package/dist/runtime/devtools.d.ts +172 -5
  57. package/dist/runtime/devtools.js +3 -1
  58. package/dist/runtime/env.js +14 -2
  59. package/dist/runtime/env.js.map +1 -1
  60. package/dist/runtime/events.d.ts +38 -1
  61. package/dist/runtime/events.js +1 -1
  62. package/dist/runtime/forms.d.ts +2 -0
  63. package/dist/runtime/forms.js +1 -0
  64. package/dist/runtime/gather.d.ts +25 -0
  65. package/dist/runtime/gather.js +33 -0
  66. package/dist/runtime/gather.js.map +1 -0
  67. package/dist/runtime/hot.d.ts +1 -1
  68. package/dist/runtime/hot.js +5 -2
  69. package/dist/runtime/hot.js.map +1 -1
  70. package/dist/runtime/html.d.ts +2 -2
  71. package/dist/runtime/html.js +1 -1
  72. package/dist/runtime/loader.d.ts +2 -2
  73. package/dist/runtime/loader.js +2 -2
  74. package/dist/runtime/routes.js +4 -1
  75. package/dist/runtime/routes.js.map +1 -1
  76. package/dist/runtime/server.d.ts +5 -4
  77. package/dist/runtime/server.js +5 -5
  78. package/dist/runtime/signals.d.ts +75 -2
  79. package/dist/runtime/signals.js +44 -2
  80. package/dist/runtime/signals.js.map +1 -1
  81. package/dist/runtime/static-loader.d.ts +2 -2
  82. package/dist/runtime/static-loader.js +1 -1
  83. package/dist/runtime/testing.d.ts +18 -3
  84. package/dist/runtime/testing.js +150 -33
  85. package/dist/runtime/testing.js.map +1 -1
  86. package/dist/runtime/values.d.ts +2 -0
  87. package/dist/runtime/values.js +24 -0
  88. package/dist/runtime/values.js.map +1 -0
  89. package/dist/{server-BA9SJ2Vm.d.ts → server-BvPIg9pT.d.ts} +363 -32
  90. package/dist/{server-BqfM95r1.js → server-DjyOVJtJ.js} +1309 -220
  91. package/dist/server-DjyOVJtJ.js.map +1 -0
  92. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
  93. package/dist/static-loader-BZR17hSw.js +312 -0
  94. package/dist/static-loader-BZR17hSw.js.map +1 -0
  95. package/dist/{stream-JaMHMdBD.js → stream-BP5AVmg5.js} +182 -17
  96. package/dist/stream-BP5AVmg5.js.map +1 -0
  97. package/dist/values-B8C7CLvG.d.ts +63 -0
  98. package/dist/vite.d.ts +20 -20
  99. package/dist/vite.js +2031 -539
  100. package/dist/vite.js.map +1 -1
  101. package/elements.d.ts +951 -0
  102. package/forms/forms.brm.ts +141 -0
  103. package/package.json +41 -3
  104. package/skills/brumate/SKILL.md +58 -0
  105. package/skills/brumate/references/errors.md +2078 -0
  106. package/skills/brumate/references/events.md +117 -0
  107. package/skills/brumate/references/signals.md +61 -0
  108. package/skills/brumate/references/state.md +235 -0
  109. package/skills/brumate/references/syntax.md +250 -0
  110. package/types.d.ts +4 -4
  111. package/dist/client-C0UCNL3J.js +0 -1643
  112. package/dist/client-C0UCNL3J.js.map +0 -1
  113. package/dist/client-MD0ZmcFR.d.ts +0 -354
  114. package/dist/client-routes-JTbGtukf.js.map +0 -1
  115. package/dist/cookies-Av5WFmcf.js.map +0 -1
  116. package/dist/defer-D0bo1Gqx.js.map +0 -1
  117. package/dist/devtools-C50VH8gZ.js +0 -113
  118. package/dist/devtools-C50VH8gZ.js.map +0 -1
  119. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  120. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  121. package/dist/events-BKWRqtMg.js +0 -52
  122. package/dist/events-BKWRqtMg.js.map +0 -1
  123. package/dist/files-Bnn1JqHx.js +0 -192
  124. package/dist/files-Bnn1JqHx.js.map +0 -1
  125. package/dist/html-bHZbkK-h.js +0 -170
  126. package/dist/html-bHZbkK-h.js.map +0 -1
  127. package/dist/html-y1q7-t7D.d.ts +0 -60
  128. package/dist/inspect-BJtACnQp.js.map +0 -1
  129. package/dist/loader-B18i3_-T.js.map +0 -1
  130. package/dist/navigate-BwuZveDF.js.map +0 -1
  131. package/dist/produce-CWfJ4byV.js +0 -167
  132. package/dist/produce-CWfJ4byV.js.map +0 -1
  133. package/dist/produce-D4K7qpaL.d.ts +0 -72
  134. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  135. package/dist/server-BqfM95r1.js.map +0 -1
  136. package/dist/static-loader-DOygOFj5.js +0 -216
  137. package/dist/static-loader-DOygOFj5.js.map +0 -1
  138. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -1,7 +1,8 @@
1
- import { t as Raw } from "./html-y1q7-t7D.js";
2
- import { a as PageState, i as PackedState, n as ElementReference, o as ScopeId, s as ScopeState } from "./produce-D4K7qpaL.js";
3
1
  import { t as Context$1 } from "./context-btHuB01Z.js";
2
+ import { n as Raw } from "./html-Bw9Qwu6F.js";
3
+ import { a as PackedState, l as ScopeId, n as Binding, o as PageState, r as ElementReference, s as PropSink, u as ScopeState } from "./produce-DIgHBVwL.js";
4
4
  import { t as StandardSchemaV1 } from "./standard-schema-BNY82yX3.js";
5
+ import { f as Intent, v as SubmissionResult } from "./forms-j1xPAR14.js";
5
6
  //#region src/runtime/cookies.d.ts
6
7
  interface CookieOptions {
7
8
  /** Seconds until the cookie expires. Without it, the cookie lasts until the browser closes. */
@@ -114,6 +115,15 @@ interface RequestEventOptions {
114
115
  * a page render, or a call of middleware or an endpoint. Its methods read
115
116
  * the request and change the response. Get it with `getEvent()`.
116
117
  */
118
+ /** A step of the render of a page, for the Server tab of the devtools. */
119
+ interface TraceEntry {
120
+ kind: "render" | "stream" | "memo" | "call" | "body";
121
+ label: string;
122
+ start: number;
123
+ /** Undefined while it runs. */
124
+ end?: number;
125
+ failed?: boolean;
126
+ }
117
127
  declare class RequestEvent {
118
128
  readonly request: Request;
119
129
  /** What the request is for. */
@@ -140,6 +150,26 @@ declare class RequestEvent {
140
150
  refreshed?: Set<unknown>;
141
151
  /** Cookies that this request set, or deleted with undefined, so later reads see them. */
142
152
  cookies?: Map<string, string | undefined>;
153
+ /**
154
+ * True once the request read its cookies or its `authorization` header, or
155
+ * set a cookie, such as for a session. The answer then depends on the user,
156
+ * so a page with `cache` is not cached for everyone.
157
+ */
158
+ personal: boolean;
159
+ /**
160
+ * In development, what the render of the page did and when, in
161
+ * milliseconds from its start, for the Server tab of the devtools.
162
+ */
163
+ trace?: TraceEntry[];
164
+ /** When the trace started, by `performance.now()`. */
165
+ traceStart: number;
166
+ /** Starts an entry of the trace, when there is one, and returns what ends it. */
167
+ traced(kind: TraceEntry["kind"], label: string): (failed?: boolean) => void;
168
+ /**
169
+ * The tags of the `cached` functions that the request called, with the
170
+ * version that each had then, so `revalidate` drops the page that it renders.
171
+ */
172
+ readonly cacheTags: Map<string, string | undefined>;
143
173
  private readonly controller;
144
174
  /**
145
175
  * Aborts when the request no longer needs an answer: the request's own
@@ -228,12 +258,6 @@ type EntryMiddleware = (event: RequestEvent, next: () => Promise<Response>) => R
228
258
  * ```
229
259
  */
230
260
  declare function defineMiddleware(middleware: EntryMiddleware): EntryMiddleware;
231
- /**
232
- * Wraps a server function, so its calls while a page renders share a result
233
- * when their arguments are the same. Calls from the browser, which are
234
- * requests of their own, always run, so a function that changes something
235
- * runs each time.
236
- */
237
261
  declare function dedupe<F extends (...args: any[]) => unknown>(fn: F, id: string): F;
238
262
  /**
239
263
  * An error whose message reaches the client. A server function call that
@@ -413,6 +437,73 @@ declare function parseForm<S extends StandardSchemaV1>(schema: S, form: FormData
413
437
  */
414
438
  declare function fieldErrors(issues: readonly (StandardSchemaV1.Issue | ValidationIssue)[]): Record<string, string[]>;
415
439
  //#endregion
440
+ //#region src/runtime/submission.d.ts
441
+ /** What a server function adds to the reply of a submission. */
442
+ interface ReplyOptions {
443
+ /** Errors of the whole form, such as "That email is taken". */
444
+ formErrors?: string[];
445
+ /** Errors of fields, by field name, such as `{ email: ['That email is taken'] }`. */
446
+ fieldErrors?: Record<string, string[]>;
447
+ /** Sets the form back to its default values, such as after a save. */
448
+ reset?: boolean;
449
+ }
450
+ /** The options of `parseSubmission`. */
451
+ interface SubmissionOptions {
452
+ /**
453
+ * Field names whose values are never sent back, such as `password`. Files
454
+ * are never sent back either, because a file input cannot be filled.
455
+ */
456
+ hide?: string[];
457
+ }
458
+ interface SubmissionBase {
459
+ /** The posted values, after the intent, before the schema. */
460
+ payload: Record<string, unknown> | undefined;
461
+ /** The reply for `createForm`, with the errors of the submission and of `options`. */
462
+ reply(options?: ReplyOptions): SubmissionResult;
463
+ }
464
+ /** A submission whose values passed the schema. */
465
+ interface SuccessfulSubmission<T> extends SubmissionBase {
466
+ status: "success";
467
+ /** The output of the schema. */
468
+ value: T;
469
+ intent?: undefined;
470
+ }
471
+ /** A submission whose values did not pass the schema, or whose names or intent were not allowed. */
472
+ interface FailedSubmission extends SubmissionBase {
473
+ status: "error";
474
+ value?: undefined;
475
+ intent?: Intent;
476
+ issues: ValidationIssue[];
477
+ }
478
+ /** A submission of an intent button, such as "Add an item". It is not a save. */
479
+ interface IntentSubmission extends SubmissionBase {
480
+ status: "intent";
481
+ value?: undefined;
482
+ intent: Intent;
483
+ }
484
+ /** A submission of a form: a success, an error, or an intent. */
485
+ type Submission<T> = SuccessfulSubmission<T> | FailedSubmission | IntentSubmission;
486
+ /**
487
+ * Reads the data of a form that `createForm` shows. It turns the entries
488
+ * into an object, as `parseForm` does, applies the intent of the button
489
+ * that was pressed, and validates the values with a Standard Schema when
490
+ * the button was not an intent. It does not throw for data that does not
491
+ * match. `reply()` gives what the function returns, for `createForm` to show.
492
+ *
493
+ * ```ts
494
+ * async function save(form: FormData) {
495
+ * 'use server';
496
+ * const submission = await parseSubmission(Order, form);
497
+ * if (submission.status !== 'success') {
498
+ * return submission.reply();
499
+ * }
500
+ * await db.orders.save(submission.value);
501
+ * return submission.reply({ reset: true });
502
+ * }
503
+ * ```
504
+ */
505
+ declare function parseSubmission<S extends StandardSchemaV1>(schema: S, form: FormData, options?: SubmissionOptions): Promise<Submission<StandardSchemaV1.InferOutput<S>>>;
506
+ //#endregion
416
507
  //#region src/runtime/rate-limit.d.ts
417
508
  /**
418
509
  * Where a limit keeps its counts. The default counts in memory, per
@@ -525,7 +616,99 @@ interface RateLimit {
525
616
  */
526
617
  declare function clientAddress(event: RequestEvent, proxies?: string[]): string | undefined;
527
618
  //#endregion
619
+ //#region src/runtime/cache.d.ts
620
+ /**
621
+ * Where cached results live. Values are text. `maxAge` is in seconds, after
622
+ * which the store can drop the value. Each method can return a promise.
623
+ */
624
+ interface CacheStore {
625
+ get(key: string): Promise<string | null | undefined> | string | null | undefined;
626
+ set(key: string, value: string, maxAge: number): Promise<void> | void;
627
+ }
628
+ /**
629
+ * A store in the memory of the server, the default. Each process has its
630
+ * own, and it keeps at most `size` values, dropping the oldest first.
631
+ */
632
+ declare function memoryStore(size?: number): CacheStore & {
633
+ readonly memory: true;
634
+ };
635
+ /**
636
+ * Sets the store of `cached`, such as one that keeps results in Redis for
637
+ * every process of the app. Set it before the first request.
638
+ */
639
+ declare function setCacheStore(next: CacheStore): void;
640
+ /** The store of unstorage, which Nitro gives as `useStorage()`. */
641
+ interface Storage {
642
+ getItem(key: string): Promise<unknown>;
643
+ setItem(key: string, value: string, options?: {
644
+ ttl?: number;
645
+ }): Promise<void>;
646
+ getItemRaw?(key: string): Promise<unknown>;
647
+ setItemRaw?(key: string, value: string, options?: {
648
+ ttl?: number;
649
+ }): Promise<void>;
650
+ }
651
+ /**
652
+ * A store of `cached` from an unstorage storage, such as Nitro's
653
+ * `useStorage('cache')`. It reads and writes the values as they are, since
654
+ * `getItem` would parse text that looks like JSON.
655
+ */
656
+ declare function storageStore(storage: Storage): CacheStore;
657
+ interface CachedOptions<A extends unknown[]> {
658
+ /** Seconds that a result is used for the same arguments. */
659
+ maxAge: number;
660
+ /** What a result depends on, for `revalidate`. A function gets the arguments. */
661
+ tags?: string[] | ((...args: A) => string[]);
662
+ /**
663
+ * The name of the results in the store. A store that other processes
664
+ * share, such as Redis, needs one, so each process finds the same results.
665
+ */
666
+ name?: string;
667
+ }
668
+ /**
669
+ * Makes a function that keeps its results for `maxAge` seconds, by its
670
+ * arguments, and returns a kept result in place of running again. Use it for
671
+ * data that every user sees the same, such as a list of products.
672
+ *
673
+ * - The function runs without the request: `getEvent()` throws in it, so a
674
+ * result never holds one user's data. Pass what it needs as arguments.
675
+ * - Arguments and results are values that brumate can send, such as plain
676
+ * objects, arrays, dates and maps.
677
+ * - Calls with the same arguments while one runs share that run.
678
+ * - `revalidate(tag)` drops the results of a tag.
679
+ */
680
+ declare function cached<A extends unknown[], R>(fn: (...args: A) => Promise<R> | R, options: CachedOptions<A>): (...args: A) => Promise<Awaited<R>>;
681
+ /**
682
+ * Drops the results of `cached` functions with these tags, such as after a
683
+ * server function changes the data. The next call runs the function again.
684
+ * To show the new data on the page, call `refresh` too.
685
+ */
686
+ declare function revalidate(...tags: string[]): Promise<void>;
687
+ //#endregion
688
+ //#region src/runtime/idempotent.d.ts
689
+ interface IdempotentOptions {
690
+ /** Seconds that the result of a key is kept. Defaults to 600. */
691
+ maxAge?: number;
692
+ }
693
+ /**
694
+ * Makes a server function that runs once for each form that the server
695
+ * renders for it. A second post of the same form, such as a double click
696
+ * before the page loaded or a post again after a reload, gets the result of
697
+ * the first, or the same redirect, without running the function again.
698
+ *
699
+ * - It works for the exported functions of a `'use server'` file, used as the
700
+ * `action` of a form.
701
+ * - The key is in the URL of the form, so a page with such a form is not
702
+ * cached for everyone. Each render has a new key.
703
+ * - With scripts, the form gets a new key after each answer, so a post that
704
+ * the user means again runs again.
705
+ * - A call without a key, such as from a handler, runs as usual.
706
+ */
707
+ declare function idempotent<F extends (...args: any[]) => unknown>(fn: F, options?: IdempotentOptions): F;
708
+ //#endregion
528
709
  //#region src/runtime/server.d.ts
710
+ /** What `$bind(name)` passes a child: the value of the name, and the scope and slot it writes. */
711
+ declare function binding<T>(value: T, scope: ScopeId, slot: number, set?: unknown): Binding<T>;
529
712
  /** The scope and the slot that hold the list of a list item. */
530
713
  type ItemSource = readonly [scope: ScopeId, slot: number];
531
714
  /** A `#loading` body that renders after the rest of the page. */
@@ -540,6 +723,44 @@ interface Boundary {
540
723
  cancelled?: boolean;
541
724
  /** A body around the target of a request for a `#defer` body, which renders but is not sent. */
542
725
  around?: boolean;
726
+ /** The `#reveal` group that orders it, when it is in one. */
727
+ group?: RevealGroup;
728
+ /** The `#try` blocks around it, from the outside in. */
729
+ catchers: Catcher[];
730
+ }
731
+ /** A `#try` that is rendering its body, and how to render its `#catch` body later. */
732
+ interface Catcher {
733
+ /** The marker of the block, `<scope>:<anchor>`. */
734
+ key: string;
735
+ /** Renders the `#catch` body for an error, in a context of its own. */
736
+ render: (ctx: Context, error: unknown) => Promise<string>;
737
+ }
738
+ /** The order of a `#reveal` block. */
739
+ type RevealOrder = "sequential" | "backwards" | "together" | "natural";
740
+ /**
741
+ * The `#loading` bodies of a `#reveal` block, in the order of the markup.
742
+ * When a body is ready, the stream asks the group, which sends the bodies
743
+ * that its order lets show. The data of every body still loads at once.
744
+ */
745
+ declare class RevealGroup {
746
+ readonly order: RevealOrder;
747
+ readonly collapsed: boolean;
748
+ /** The bodies that stream, each with how to send it once it is ready. */
749
+ private readonly members;
750
+ /** The fallbacks that `collapsed` hides until the body before them shows. */
751
+ readonly hidden: Set<ScopeId>;
752
+ private closed;
753
+ constructor(order: RevealOrder, collapsed: boolean);
754
+ /** True when a body that is ready can render in place, before the bodies that stream. */
755
+ mayShow(): boolean;
756
+ /** True when the fallback of the next body that streams waits, for `collapsed`. */
757
+ hides(): boolean;
758
+ add(id: ScopeId): void;
759
+ /** The body is ready, or failed with nothing to send. `send` writes it, and runs `after` with it. */
760
+ ready(id: ScopeId, send: (after: string) => void): void;
761
+ /** The block ended, so the group knows its last body. */
762
+ close(): void;
763
+ private flush;
543
764
  }
544
765
  /** The `#defer` body that a render renders, for the request of the browser that asks for it. */
545
766
  interface DeferTarget {
@@ -588,7 +809,7 @@ interface IdSpace {
588
809
  entries: (ScopeEntry | undefined)[];
589
810
  }
590
811
  /** A scope of a render: its record, and what the server keeps of it while the page renders. */
591
- interface ScopeEntry {
812
+ interface ScopeEntry extends PropSink {
592
813
  id: ScopeId;
593
814
  /** The prefix of the ID and the number after it, such as `'5.'` and `1`, or `''` and `3`. */
594
815
  prefix: string;
@@ -651,6 +872,10 @@ declare class Context {
651
872
  /** The titles that this render set, and whether they all came from a `<title>` in `#head`. */
652
873
  private titles;
653
874
  private onBoundary;
875
+ /** The `#try` blocks of the parents of this context, from the outside in. */
876
+ outer: Catcher[];
877
+ /** The `#try` blocks of this context that are rendering their bodies now. */
878
+ private readonly catchers;
654
879
  /** The scope that renders the next component, which becomes its owner. */
655
880
  private owner;
656
881
  /**
@@ -664,6 +889,8 @@ declare class Context {
664
889
  private rpcPrefix;
665
890
  /** The ID of the build, for forms that post to server functions. See `RenderOptions`. */
666
891
  build: string | undefined;
892
+ /** True in development, where a memo that failed or a `#catch` sends its error to the browser. */
893
+ development: boolean;
667
894
  /** Results of server functions that a form posted to this page, for `$action`. */
668
895
  actions: Map<unknown, unknown>;
669
896
  /** The params of the route of the page, for `$route`. */
@@ -674,6 +901,10 @@ declare class Context {
674
901
  readonly calls: Map<string, unknown>;
675
902
  /** The event of the page, for `getEvent()` in a component, which the compiler rewrites to this. */
676
903
  getEvent(): RequestEvent;
904
+ /** Starts an entry of the trace of the request, in development. */
905
+ traced(kind: TraceEntry["kind"], label: string): ((failed?: boolean) => void) | undefined;
906
+ /** Marks the request of the page as one that depends on the user, so the page is not cached for everyone. */
907
+ personal(): void;
677
908
  /** Runs code of the render with its event and its call results, such as a memo's compute. */
678
909
  run<T>(callback: () => T): T;
679
910
  /** The result of a server function that a form posted to this page. */
@@ -703,6 +934,8 @@ declare class Context {
703
934
  leave(): void;
704
935
  /** Returns the URL prefix of server function calls. */
705
936
  rpc(): string;
937
+ /** True when the render is in development. */
938
+ isDev(): boolean;
706
939
  /** Returns the ID of the build, when the render has one. */
707
940
  buildId(): string | undefined;
708
941
  /**
@@ -718,7 +951,9 @@ declare class Context {
718
951
  * keep `from`, the scope of the markup that wrote them, for their values,
719
952
  * and find their contexts from `at`.
720
953
  */
721
- children(from: ScopeId, at: ScopeId, renderBody: () => Promise<string>): Promise<string>;
954
+ children(from: ScopeId, at: ScopeId, renderBody: () => Promise<string>, tag?: string): Promise<string>;
955
+ /** The tag of the element where the children that render now are inserted, for spacers. */
956
+ spacerTag(): string;
722
957
  /**
723
958
  * The ID that `$id()` makes: the scope's ID and the position of the call.
724
959
  * A dot in a scope ID inside a `#loading` body becomes `_`, so the ID also
@@ -730,9 +965,9 @@ declare class Context {
730
965
  /** Provides a value of a context to the scopes inside `scope`. */
731
966
  provide<T>(context: Context$1<T>, value: T, scope: ScopeId): void;
732
967
  /**
733
- * Reads a context from the nearest scope that provides it, starting at
734
- * `scope`. With `slot`, records which slot holds it, so the client can
735
- * update it when the provided value changes.
968
+ * Reads a context from the nearest scope above `scope` that provides it.
969
+ * With `slot`, records which slot holds it, so the client can update it
970
+ * when the provided value changes.
736
971
  */
737
972
  consume<T>(context: Context$1<T>, scope: ScopeId, slot?: number): T;
738
973
  /** The ID that the next call to `scope()` returns. */
@@ -765,7 +1000,23 @@ declare class Context {
765
1000
  * scope, as `[scope, slot]`. The items of a list share one array.
766
1001
  */
767
1002
  get sources(): Map<ScopeId, ItemSource>;
1003
+ /** The scope that `unbind` collects the promise props of its component in. */
1004
+ sink(scope: ScopeId): PropSink;
768
1005
  slots(scope: ScopeId, values: unknown[], names?: string[]): void;
1006
+ /** Elements that bound props of components forwarded to the slots of scopes that have no slots yet. */
1007
+ private forwards?;
1008
+ /**
1009
+ * Writes the element that a component forwards to a slot of a scope above it, and on through
1010
+ * the props that scope binds in turn. The parent records its slots after its children render,
1011
+ * so a write for a scope that has none waits for them.
1012
+ */
1013
+ private forward;
1014
+ /**
1015
+ * Records the props that a parent bound with `$bind`, among the props that
1016
+ * the component writes: `slots` has the slot of each, by its name. Its
1017
+ * writes in the browser go to the parent's slots.
1018
+ */
1019
+ bindings(scope: ScopeId, props: Record<string, unknown>, slots: Record<string, number>): void;
769
1020
  /**
770
1021
  * Records the item of a list that can change on the client. `source` is
771
1022
  * the scope and slot that hold the list, when the compiler found one, so
@@ -774,10 +1025,20 @@ declare class Context {
774
1025
  item(scope: ScopeId, value: unknown, source?: ItemSource): void;
775
1026
  /** Records the scope of a child component at an anchor of its parent. */
776
1027
  link(scope: ScopeId, anchor: number, child: ScopeId): void;
1028
+ /**
1029
+ * A `ref` that the rest props of a component hold is a binding of a signal above. The element
1030
+ * that spreads them goes to that signal, as when the component names `ref` itself.
1031
+ */
1032
+ restRef<T extends Record<string, unknown>>(attributes: T, scope: ScopeId, anchor: number, tag?: unknown): T;
777
1033
  /** Returns the reference that a `ref` signal holds on the server. */
778
1034
  element(scope: ScopeId, anchor: number): ElementReference;
779
- /** Marks a function as a client function, so it serializes as a reference. */
780
- fn<T>(value: T, ref: string, scope: ScopeId): T;
1035
+ /**
1036
+ * Marks a function as a client function, so it serializes as a reference.
1037
+ * `args` are the arguments of a handler that `$handler` made, which go
1038
+ * with the reference. Each call makes a new reference, so a function that
1039
+ * `$handler` marks gets a copy for its arguments.
1040
+ */
1041
+ fn<T>(value: T, ref: string, scope: ScopeId, args?: unknown[]): T;
781
1042
  /** Returns a component's stylesheet the first time the page renders the component. */
782
1043
  style(id: string, css: string): string;
783
1044
  /** Adds the markup of a `#head` block. */
@@ -810,6 +1071,25 @@ declare class Context {
810
1071
  }): void;
811
1072
  /** True when the bodies of `#defer` blocks render in place, for a page that renders in order. */
812
1073
  inOrder: boolean;
1074
+ /** The `#reveal` blocks that are open in this context, the innermost last. */
1075
+ private readonly reveals;
1076
+ /** Starts a `#reveal` block: the `#loading` bodies until `revealEnd` show in its order. */
1077
+ revealStart(order: RevealOrder, collapsed: boolean): void;
1078
+ /** Ends the `#reveal` block that `revealStart` started. */
1079
+ revealEnd(): void;
1080
+ /** The group of the `#reveal` block around the next body, when the stream orders it. */
1081
+ private get reveal();
1082
+ /** True when a `#loading` body that is ready can render in place, as its `#reveal` allows. */
1083
+ mayShow(): boolean;
1084
+ /** Starts the fallback of a `#loading` body, which `collapsed` hides in a template. */
1085
+ fallbackStart(id: ScopeId): string;
1086
+ /** Ends the fallback that `fallbackStart` started. */
1087
+ fallbackEnd(id: ScopeId): string;
1088
+ /**
1089
+ * Starts a `#try` body. A `#loading` body inside it that fails renders the `#catch` body with
1090
+ * `draw`, after the page is sent. The returned function ends the `#try` body.
1091
+ */
1092
+ catcher(key: string, draw: Catcher["render"]): () => void;
813
1093
  /** Returns the ID of a new `#loading` boundary. */
814
1094
  boundary(): ScopeId;
815
1095
  /** Renders a `#loading` body after the rest of the page, in its own context and ID space. */
@@ -838,9 +1118,11 @@ interface Memo<T = unknown> {
838
1118
  value?: unknown;
839
1119
  error?: unknown;
840
1120
  load?: Promise<unknown>;
1121
+ /** The name of the memo, for the trace of the devtools. */
1122
+ name?: string;
841
1123
  }
842
1124
  /** Declares a memo. Its value is computed when it is first read. */
843
- declare function memo<T>(compute: () => T, ctx?: Context): Memo<T>;
1125
+ declare function memo<T>(compute: () => T, ctx?: Context, name?: string): Memo<T>;
844
1126
  /**
845
1127
  * Reads a memo. A value that is still loading throws `NotReady` with its
846
1128
  * load, and a memo that read such a value stays unread, so it computes
@@ -856,9 +1138,9 @@ declare function wait(node: Memo): Promise<unknown>;
856
1138
  declare function ready(node: Memo): unknown;
857
1139
  /**
858
1140
  * The value of a memo for the page state: its value when it is ready, or
859
- * a promise of it while it loads. A memo that fails gives a rejected
860
- * promise either way, so the page renders and the failure reaches the
861
- * browser as the load that failed.
1141
+ * a promise of it while it loads. A memo that fails gives a `MemoError`
1142
+ * either way, so the page renders, the stream goes on, and a read in the
1143
+ * browser throws the error as a memo that failed there.
862
1144
  */
863
1145
  declare function stateValue(node: Memo): unknown;
864
1146
  /**
@@ -879,14 +1161,19 @@ declare function settled(nodes: Memo[]): boolean;
879
1161
  declare const LAZY: unique symbol;
880
1162
  /** Markup that renders where it is inserted, so it can read the contexts there. */
881
1163
  interface Lazy {
882
- [LAZY]: (ctx: Context, scope: ScopeId | undefined) => Promise<string>;
1164
+ [LAZY]: (ctx: Context, scope: ScopeId | undefined, tag?: string, anchor?: number) => Promise<string>;
883
1165
  }
884
1166
  /**
885
1167
  * The children of a component, which render where the component inserts
886
1168
  * them, so they read the contexts that the component provides. `from` is the
887
1169
  * scope of the markup that wrote them.
888
1170
  */
889
- declare function children(from: ScopeId, renderBody: (ctx: Context) => Promise<string>): Lazy;
1171
+ declare function children(from: ScopeId, renderBody: (ctx: Context) => Promise<string>, ref?: string): Lazy;
1172
+ /**
1173
+ * The tag of the spacers of a windowed list in children: a row in a table body, an item in a
1174
+ * list, as the element where the children are inserted says, or else a `div`.
1175
+ */
1176
+ declare function spacerTag(ctx: Context): string;
890
1177
  /** Makes markup that renders where it is inserted, such as the children of a layout. */
891
1178
  declare function lazy(renderAt: (ctx: Context, scope: ScopeId | undefined) => Promise<string>): Lazy;
892
1179
  /** Renders the attributes of a form or button that posts to a server function. */
@@ -897,18 +1184,18 @@ declare function action(ctx: Context, name: string, id: string, method?: string,
897
1184
  */
898
1185
  declare function actionResult(ctx: Context, fn: unknown): unknown;
899
1186
  /**
900
- * Renders a value inserted in markup. `ctx` and `scope` are where it is
901
- * inserted, for markup that renders there.
1187
+ * Renders a value inserted in markup. `ctx`, `scope` and `anchor` are where it
1188
+ * is inserted, for markup that renders there.
902
1189
  */
903
- declare function insert(value: unknown, ctx?: Context, scope?: ScopeId): string | Promise<string>;
904
- type Component<P = any> = (props: P, ctx: Context) => Promise<string>;
1190
+ declare function insert(value: unknown, ctx?: Context, scope?: ScopeId, tag?: string, anchor?: number): string | Promise<string>;
1191
+ type Component<P = any> = (props: P, ctx: Context) => Promise<string | object>;
905
1192
  /**
906
1193
  * Renders a child component. With `scope` and `anchor`, records the child's
907
1194
  * scope so the parent can update its props on the client.
908
1195
  */
909
- declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: ScopeId, anchor?: number): Promise<string>;
1196
+ declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: ScopeId, anchor?: number, paragraph?: string): Promise<string>;
910
1197
  /** Renders a dynamic tag, which can be an element name or a component. */
911
- declare function dynamic(tag: string | Component, attributes: Record<string, unknown>, content: Raw | Lazy | undefined, ctx: Context, scope?: ScopeId): string | Promise<string>;
1198
+ declare function dynamic(tag: string | Component, attributes: Record<string, unknown>, content: Raw | Lazy | undefined, ctx: Context, scope?: ScopeId, ref?: unknown): string | Promise<string>;
912
1199
  /** The records of the scopes of a render, by scope ID. */
913
1200
  type StateMap = Map<ScopeId, ScopeState>;
914
1201
  /**
@@ -939,6 +1226,10 @@ interface StateAttributes {
939
1226
  params?: Record<string, string>;
940
1227
  /** The ID of the build that rendered the page, on its first record, for skew protection. */
941
1228
  build?: string;
1229
+ /** The ID of a `#loading` boundary whose body failed. The record is the error. */
1230
+ fail?: ScopeId;
1231
+ /** The marker of a `#try` whose `#catch` body replaces its body, from the template `b-c`. */
1232
+ catches?: string;
942
1233
  }
943
1234
  /**
944
1235
  * Returns the script of a state record. `scopes` marks a record with scopes,
@@ -984,6 +1275,8 @@ interface RenderResult {
984
1275
  interface RenderOptions {
985
1276
  /** The URL prefix of server function calls, for forms that post to one. Defaults to `/_brumate`. */
986
1277
  rpc?: string;
1278
+ /** In development: the swaps of `#loading` bodies keep their fallbacks, for the devtools. */
1279
+ dev?: boolean;
987
1280
  /**
988
1281
  * The first scope and boundary ID. A page that the client loads in place
989
1282
  * of another starts above the IDs of the page it keeps parts of.
@@ -1088,6 +1381,14 @@ type StreamOptions = DocumentOptions;
1088
1381
  declare function renderToStream<P>(Root: Component<P>, props: P, options?: DocumentOptions): ReadableStream<string>;
1089
1382
  /** Streams the parts of a page from `render`: the first render whole, then what resolves later. */
1090
1383
  declare function streamParts(parts: RenderResult, options?: DocumentOptions): ReadableStream<string>;
1384
+ /**
1385
+ * The error that a `#catch` body gets on the server, which the page state carries to the
1386
+ * browser. In development it is the error itself, for debugging. In production it is a plain
1387
+ * `Error` with the message of a `ServerError`, or a generic message, and the real error is
1388
+ * logged, as for a server function that fails. The body renders with this value too, so the
1389
+ * HTML cannot print what the state does not carry.
1390
+ */
1391
+ declare function caught(error: unknown, ctx: Context): unknown;
1091
1392
  interface RequestOptions {
1092
1393
  /**
1093
1394
  * Other origins that may call server functions and post forms to them,
@@ -1138,7 +1439,33 @@ declare function isCrossSite(request: Request, options?: RequestOptions): boolea
1138
1439
  * another site answers 403. See `isCrossSite`.
1139
1440
  */
1140
1441
  declare function handleRequest(functions: Record<string, (...args: any[]) => unknown>, request: Request, prefix?: string, options?: RequestOptions): Promise<Response | undefined>;
1442
+ /**
1443
+ * How long a page can be cached for everyone, as a route exports it from
1444
+ * its module script: `export const cache = { maxAge: 60 }`. A layout's
1445
+ * applies to the pages below it, and the nearest one wins.
1446
+ */
1447
+ interface PageCache {
1448
+ /** Seconds that a cache can serve the page without asking again. */
1449
+ maxAge: number;
1450
+ /** Seconds after `maxAge` that a cache can serve the old page while it gets a new one. */
1451
+ staleWhileRevalidate?: number;
1452
+ }
1141
1453
  interface RouteOptions extends DocumentOptions, RequestOptions {
1454
+ /**
1455
+ * The HTML that the build prerendered for the path, for a server that has
1456
+ * the file. The server sends it at once, then renders the `#defer` blocks
1457
+ * with the `load` or `idle` trigger in the same response, in place of a
1458
+ * request for each. Requests for a `#defer` body and client navigation
1459
+ * render the route as usual.
1460
+ */
1461
+ shell?: string;
1462
+ /**
1463
+ * Keeps the pages that `cache` makes public in the store of `cached`, and
1464
+ * answers the next request for the same URL from it until `maxAge` ends or
1465
+ * `revalidate` drops a tag that the page used. Defaults to true. A CDN in
1466
+ * front of the server can keep them instead.
1467
+ */
1468
+ pageCache?: boolean;
1142
1469
  /**
1143
1470
  * Throws errors that are not a `ServerError` instead of rendering
1144
1471
  * `_error.brm`, so a dev server can show them, such as with `errorPage`
@@ -1154,6 +1481,12 @@ interface RouteOptions extends DocumentOptions, RequestOptions {
1154
1481
  * passes them from the client build.
1155
1482
  */
1156
1483
  hints?: string[];
1484
+ /**
1485
+ * The URLs of the bundle of each root component, such as a route or a layout, by component ID:
1486
+ * its chunk and the chunks that it imports. A page adds those of its views to `hints`, so the
1487
+ * code of the page loads with the HTML. `virtual:brumate/routes` passes them.
1488
+ */
1489
+ bundleHints?: Record<string, string[]>;
1157
1490
  /**
1158
1491
  * Receives the `Link` values of `hints` before the page renders, so a
1159
1492
  * server can send them as `103 Early Hints`, such as with Node's
@@ -1183,9 +1516,7 @@ declare function handleRoute(tree: RouteNode, request: Request, options?: RouteO
1183
1516
  * function belongs to and the modifiers of its wrappers. A function that
1184
1517
  * refers to nothing in the browser is left out.
1185
1518
  */
1186
- declare function spread(attributes: Record<string, unknown>, on?: string[]): string;
1187
- /** The `b-on` attribute of an element with spreads: its own handlers, then those of its spreads. */
1188
- declare function onAttribute(on: string[], own: string): string;
1519
+ declare function spread(attributes: Record<string, unknown>, on?: string[], names?: boolean): string;
1189
1520
  //#endregion
1190
- export { rateLimit as $, onAttribute as A, CookieOptions as At, streamParts as B, handleRequest as C, ServerError as Ct, isCrossSite as D, isRedirect as Dt, insert as E, getEvent as Et, renderToStream as F, serializeCookie as Ft, RateLimitConfig as G, wait as H, settled as I, toNodeHeaders as It, RateLimitOptions as J, RateLimitError as K, spread as L, read as M, SessionOptions as Mt, ready as N, createSession as Nt, lazy as O, redirect as Ot, render as P, parseCookies as Pt, configureRateLimit as Q, stateScript as R, dynamic as S, RequestKind as St, inlineBodies as T, defineMiddleware as Tt, waitAll as U, streamState as V, RateLimit as W, Window as X, RateLimitStore as Y, clientAddress as Z, StreamOptions as _, Locals as _t, ItemSource as a, parseForm as at, children as b, RequestEvent as bt, Memo as c, Handler as ct, RenderResult as d, MiddlewareLoader as dt, ParseResult as et, RequestOptions as f, RouteMatch as ft, StateMap as g, EntryMiddleware as gt, StateAttributes as h, matchRoute as ht, DocumentOptions as i, parse as it, packState as j, Session as jt, memo as k, withEvent as kt, NotReady as l, Loader as lt, ScopeEntry as m, RouteView as mt, Context as n, ValidationIssue as nt, Lazy as o, safeParse as ot, RouteOptions as p, RouteNode as pt, RateLimitMiddleware as q, DeferTarget as r, fieldErrors as rt, Mark as s, EndpointLoader as st, Component as t, ValidationError as tt, RenderOptions as u, Middleware as ut, action as v, Redirect as vt, handleRoute as w, dedupe as wt, component as x, RequestEventOptions as xt, actionResult as y, RequestCall as yt, stateValue as z };
1191
- //# sourceMappingURL=server-BA9SJ2Vm.d.ts.map
1521
+ export { memoryStore as $, createSession as $t, insert as A, Middleware as At, spacerTag as B, RequestEvent as Bt, caught as C, fieldErrors as Ct, handleRequest as D, EndpointLoader as Dt, dynamic as E, safeParse as Et, read as F, matchRoute as Ft, streamState as G, defineMiddleware as Gt, stateScript as H, RequestKind as Ht, ready as I, EntryMiddleware as It, IdempotentOptions as J, redirect as Jt, wait as K, getEvent as Kt, render as L, Locals as Lt, lazy as M, RouteMatch as Mt, memo as N, RouteNode as Nt, handleRoute as O, Handler as Ot, packState as P, RouteView as Pt, cached as Q, SessionOptions as Qt, renderToStream as R, Redirect as Rt, binding as S, ValidationIssue as St, component as T, parseForm as Tt, stateValue as U, ServerError as Ut, spread as V, RequestEventOptions as Vt, streamParts as W, dedupe as Wt, CacheStore as X, CookieOptions as Xt, idempotent as Y, withEvent as Yt, CachedOptions as Z, Session as Zt, StateAttributes as _, SubmissionOptions as _t, ItemSource as a, RateLimitError as at, action as b, ParseResult as bt, Memo as c, RateLimitStore as ct, RenderOptions as d, configureRateLimit as dt, parseCookies as en, revalidate as et, RenderResult as f, rateLimit as ft, ScopeEntry as g, Submission as gt, RouteOptions as h, ReplyOptions as ht, DocumentOptions as i, RateLimitConfig as it, isCrossSite as j, MiddlewareLoader as jt, inlineBodies as k, Loader as kt, NotReady as l, Window as lt, RevealOrder as m, IntentSubmission as mt, Context as n, toNodeHeaders as nn, storageStore as nt, Lazy as o, RateLimitMiddleware as ot, RequestOptions as p, FailedSubmission as pt, waitAll as q, isRedirect as qt, DeferTarget as r, RateLimit as rt, Mark as s, RateLimitOptions as st, Component as t, serializeCookie as tn, setCacheStore as tt, PageCache as u, clientAddress as ut, StateMap as v, SuccessfulSubmission as vt, children as w, parse as wt, actionResult as x, ValidationError as xt, StreamOptions as y, parseSubmission as yt, settled as z, RequestCall as zt };
1522
+ //# sourceMappingURL=server-BvPIg9pT.d.ts.map