@valbuild/react 0.150.23 → 0.152.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 (27) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/declarations/src/internal/index.d.ts +1 -0
  3. package/dist/declarations/src/read/draft.d.ts +105 -0
  4. package/dist/declarations/src/read/index.d.ts +8 -0
  5. package/dist/declarations/src/read/jsonValues.d.ts +26 -0
  6. package/dist/declarations/src/read/layered.d.ts +45 -0
  7. package/dist/declarations/src/read/overlayStore.d.ts +113 -0
  8. package/dist/declarations/src/read/readers.d.ts +51 -0
  9. package/dist/declarations/src/read/refreshLoop.d.ts +61 -0
  10. package/dist/declarations/src/read/resolveVal.d.ts +93 -0
  11. package/dist/declarations/src/read/sources.d.ts +63 -0
  12. package/dist/{raw-be4b57fa.browser.esm.js → raw-15ce77ae.browser.esm.js} +1 -1
  13. package/dist/{raw-1b40484b.esm.js → raw-534fcde0.esm.js} +1 -1
  14. package/dist/{raw-43f9221a.worker.esm.js → raw-645a854a.worker.esm.js} +1 -1
  15. package/dist/{raw-ff060f24.cjs.dev.js → raw-67d24dd6.cjs.dev.js} +2 -0
  16. package/dist/{raw-b3745603.cjs.prod.js → raw-d504f4fd.cjs.prod.js} +2 -0
  17. package/internal/dist/valbuild-react-internal.browser.esm.js +1723 -6
  18. package/internal/dist/valbuild-react-internal.cjs.dev.js +1748 -4
  19. package/internal/dist/valbuild-react-internal.cjs.prod.js +1748 -4
  20. package/internal/dist/valbuild-react-internal.esm.js +1723 -6
  21. package/internal/dist/valbuild-react-internal.worker.esm.js +1723 -6
  22. package/package.json +4 -4
  23. package/stega/dist/valbuild-react-stega.browser.esm.js +2 -2
  24. package/stega/dist/valbuild-react-stega.cjs.dev.js +1 -1
  25. package/stega/dist/valbuild-react-stega.cjs.prod.js +1 -1
  26. package/stega/dist/valbuild-react-stega.esm.js +2 -2
  27. package/stega/dist/valbuild-react-stega.worker.esm.js +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,183 @@
1
1
  # @valbuild/react
2
2
 
3
+ ## 0.152.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`f4e0660`](https://github.com/valbuild/val/commit/f4e06601495dbee680a4b9000344f84cd3af717f), [`3bb76d7`](https://github.com/valbuild/val/commit/3bb76d74d82b499aa15023838d63018a70fd7ce7), [`08a3977`](https://github.com/valbuild/val/commit/08a39779dbe43702a72ae57cbf8cf29b14e64672)]:
8
+ - @valbuild/ui@0.152.0
9
+ - @valbuild/shared@0.152.0
10
+
11
+ ## 0.151.0
12
+
13
+ ### Patch Changes
14
+
15
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`a325152`](https://github.com/valbuild/val/commit/a325152856a881faec84c112fcf226828739f563) Thanks [@freekh](https://github.com/freekh)! - **A draft page shows the right `.jsonValues()` entries, whichever reader reads them.**
16
+
17
+ - **Pending edits to an entry.** In draft mode, `fetchVal` of a whole
18
+ `.jsonValues()` record now shows the unpublished edits to its entries. It
19
+ used to show the published content of every entry, even one an editor had
20
+ just changed, while `fetchValKey` and `fetchValRoute` of the same entry
21
+ showed the edit. The entries a pending change touches are read from Val's
22
+ server; the others are loaded from your build, as before.
23
+ - **Entries published without a rebuild.** On a host that does not rebuild
24
+ the site after a publish, a draft page now shows the published entries
25
+ straight away -- in `fetchVal`, and in `useVal`, `useValKey` and
26
+ `useValRoute` alike. They used to show those entries as they were before
27
+ the publish, from the site's build, until it was rebuilt (and on TanStack
28
+ Start the server render showed the new content, then the page switched
29
+ back to the old). Val's server marks each entry a publish wrote, and the
30
+ readers and the Studio load a marked entry from the server.
31
+
32
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`346e6fd`](https://github.com/valbuild/val/commit/346e6fdc8e242bf826ab66a729eacd9f8d4be1a6) Thanks [@freekh](https://github.com/freekh)! - **Draft pages read what was edited, not the whole site.** A page in draft
33
+ mode used to make Val's server read every module, apply every pending
34
+ change, and preview and validate the whole project on every request -- and
35
+ then ask again for each `.jsonValues()` entry it showed. Now there is one
36
+ copy of the draft per process, made once per change and shared by every
37
+ editor and every request:
38
+
39
+ - A module nobody edited costs nothing: the page reads its own build, as a
40
+ visitor's does.
41
+ - A request asks one cheap question -- has anything changed? -- once, and
42
+ the draft is only re-read when it has. An edit is applied once, to the
43
+ version before it, however many pages read it afterwards.
44
+ - `fetchVal`, `fetchValKey`, `fetchValRoute`, `fetchValRouteUrl` and
45
+ `fetchValDraft` (Next.js and TanStack Start alike) and Val's API routes
46
+ read that one copy, so a save through the API is seen by every reader at
47
+ once. Before, each kept its own, and a publish moved only the copy of the
48
+ server that handled it: in a host that keeps its content in memory, a
49
+ draft page read through `fetchValKey` or `fetchValRoute` went on showing
50
+ the content from before the publish.
51
+ - The MCP tools (`initValMcp`) read the same copy in local development and
52
+ on Val's hosting, where Val's options come from your config and the
53
+ environment. `initValMcp` takes no patch store or source files of its
54
+ own, so in a host that keeps its content in memory it keeps a copy of its
55
+ own, as before.
56
+ - If `initValServer` and `initValContent` (or `initValRsc`) are given
57
+ different options for the same `val.modules` (a different patch store,
58
+ say), they keep separate copies, and Val logs a warning saying which
59
+ options differ.
60
+
61
+ On a site of 20 MB of content a draft read went from about half a second per
62
+ request to well under a millisecond once the draft is in memory, and the
63
+ memory it holds grows with what was edited rather than with the size of the
64
+ site. Hosted sites in proxy mode ask the content service one small question
65
+ per request instead of reading every pending change; with a content service
66
+ that predates it, Val reads the pending changes as before.
67
+
68
+ `ValDraft` (what `fetchValDraft` returns and `<ValProvider draft>` takes)
69
+ has a new optional `versions` field, filled in by the server: the page uses
70
+ it to tell that what the Studio sends is what it already shows, without
71
+ comparing the content. Nothing to change in your app.
72
+
73
+ **Changed:** `PUT /api/val/sources/~` no longer computes previews or
74
+ validates the content (the Studio does both itself, and `/api/val/validate`
75
+ checks a module on request); its `validate_sources` and
76
+ `validate_binary_files` flags are accepted and ignored.
77
+
78
+ **Deprecated, and removed in the next release.** These stay for one release
79
+ only so that a Studio, a page or a server of the previous release keeps
80
+ working while a deploy rolls out. Nothing in this release uses them; if
81
+ your own code calls any of them, move off it now:
82
+
83
+ - `PUT /api/val/sources/~`, the whole route. This release's Studio reads
84
+ `GET /api/val/manifest` and `GET /api/val/modules/~<path>`, and the draft
85
+ readers and MCP read in-process.
86
+ - The `source` field of the overlay's `source-update` event and the canvas's
87
+ `sourceUpdate` message, and a page's support for an event that carries
88
+ only `source` (this release sends `read` beside it).
89
+ - `ValDraft.base`: not sent and not read; the type stays one release so
90
+ code written against the previous one still compiles.
91
+ - `/api/val/stat`'s `sourcesSha` and `schemaSha`: the next release's Studio
92
+ stops depending on them, and the release after it stops sending them.
93
+
94
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`b0ad7f4`](https://github.com/valbuild/val/commit/b0ad7f496f2dc0384b8df847b1d77becf617b7bf) Thanks [@freekh](https://github.com/freekh)! - A draft page now catches up with an edit as soon as the server has it, instead
95
+ of on a timer.
96
+
97
+ - **The page settles faster, and without the 10 second fallback.** Content your
98
+ page reads on the server (a TanStack Start loader, a Next.js server component)
99
+ is refreshed when the editor's change has been saved, once per saved change.
100
+ It used to be refreshed the moment you typed — before the change was saved,
101
+ so the refresh often came back without it — and then again every 10 seconds
102
+ for half a minute in case it had. That safety refresh is gone, and so are the
103
+ extra requests it made while you edited. Another editor's change refreshes
104
+ the page too, once the server has it. While a deploy rolls out, a Studio of
105
+ the previous release (which never says it has saved) still refreshes the
106
+ page as each change arrives, as before.
107
+ - **Next.js: `ValProvider` takes an optional `draft` prop**, as
108
+ `@valbuild/tanstack`'s does: the editor's draft, read on the server for the
109
+ request. With it, the server renders the draft and the browser hydrates the
110
+ same thing, so a draft page no longer shows the published text first, and a
111
+ page that exists only as an unpublished change is found on the first render
112
+ instead of answering 404. Without it, nothing changes. See "The `draft` prop"
113
+ in the `@valbuild/next` README.
114
+ - **Next.js: `initValRsc` returns `fetchValDraft`**, which reads that draft:
115
+ pass `draft={await fetchValDraft()}` to `ValProvider` in your root layout. It
116
+ returns `null` unless the request is in draft mode, after one `draftMode()`
117
+ lookup and no other work, so visitors pay nothing and a static page stays
118
+ static. It reads the draft the way `@valbuild/tanstack/server`'s
119
+ `fetchValDraft` does and returns the same type, `ValDraft | null`, which
120
+ is now exported from `@valbuild/next` and `@valbuild/next/rsc` too.
121
+ - **`suspend` waits for the editor's changes properly.** With `suspend` on
122
+ `ValProvider`, a page could be told it had everything before the editor had
123
+ sent the pending change it needed, and render the published content first —
124
+ for a page that exists only as an unpublished change, a 404. It now waits
125
+ until the change is there.
126
+ - A draft page whose draft was discarded or published before the editor's
127
+ overlay or canvas connected now shows what the editor has, instead of keeping
128
+ the draft it was rendered with -- an edit inside a `.jsonValues()` entry
129
+ included.
130
+ - Turning draft mode on or off refreshes the page once. In development (React's
131
+ `StrictMode`) it could refresh twice, and Next.js could log "Cannot call
132
+ startTransition while rendering" while the page refreshed.
133
+
134
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`809873c`](https://github.com/valbuild/val/commit/809873cd7dd2c17e261b7e92716397a6bb4d6e56) Thanks [@freekh](https://github.com/freekh)! - Every content reader in `@valbuild/next` and `@valbuild/tanstack` — `fetchVal`,
135
+ `useVal`, the key and route readers, on the server and in the browser — now
136
+ loads content the same way, so they can no longer disagree about which content
137
+ wins. Nothing you call changes. What you may notice:
138
+
139
+ - `useValRoute` on a `.jsonValues()` router loads only the entry for the
140
+ current route. It used to load every entry of the record first.
141
+ `useValRouteUrl` and `fetchValRouteUrl` load none at all: a URL does not need
142
+ them.
143
+ - In development, an edited `*.val.json` entry shows its new content after a
144
+ hot reload. The hooks kept the entry they had loaded before it.
145
+ - Next.js: `useValKey` no longer shows the published entry of a nullable
146
+ `.jsonValues()` record that a draft has set to `null`, nor anything for an
147
+ entry named like a built-in object property (such as `toString`) that the
148
+ draft does not have.
149
+ - With `suspend` on `ValProvider`, `useValKey` now waits for draft mode and the
150
+ editor's changes too, as `useVal` and `useValRoute` already did.
151
+ - When one entry of a `.jsonValues()` record cannot be loaded, `useVal` logs
152
+ the error and renders the others, as `fetchVal` already did, instead of
153
+ failing the whole component.
154
+
155
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`66d487f`](https://github.com/valbuild/val/commit/66d487f3662164a9a167ec660afc6d12b441aa22) Thanks [@freekh](https://github.com/freekh)! - Typing in the Studio no longer slows down with the size of the module.
156
+
157
+ - **A keystroke in a large module is about five times faster.** The Studio
158
+ used to copy the whole module for every change it applied; it now applies
159
+ changes the way Val's server does, copying only what the change touches.
160
+ In a module of 5 MB a keystroke went from about 100 ms to about 20 ms, and
161
+ a module of 1 MB from about 17 ms to about 3 ms.
162
+ - **The Studio and the server show a change the same way.** Where an uploaded
163
+ file's draft address goes, what an edit inside a `.jsonValues()` entry
164
+ does, and what a new entry is, are decided by the same code in both, so
165
+ the editor's fields, the page behind the Studio and a draft page's server
166
+ render cannot disagree about them.
167
+
168
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`4dc1481`](https://github.com/valbuild/val/commit/4dc1481cfb7cad4072bdbeaeb51b2b2ad43a9f5d) Thanks [@freekh](https://github.com/freekh)! - The Studio now shows each module as your server has it, by version, with only your own unsaved edits on top.
169
+
170
+ - **Publishing is faster.** After a publish, or when your site serves content published without a build, the Studio used to download every module's content before it showed anything new. It now reads only the modules that changed, one at a time: in our measurements with a 1,000-entry `.jsonValues()` record, the Studio was ready again after a publish in about 35 ms instead of 300–800 ms.
171
+ - **No flicker of old content on a draft page.** For up to a minute after a deploy, a request can still reach the build before it; that build now says it has been replaced (when Val's content service can tell it), and the Studio asks again rather than taking its content for the current one. In local development the same holds after you change a `.val.ts`: an answer from the code before the change is no longer taken for the new code's, so a page in draft mode no longer shows the new text, then the old, then the new again.
172
+ - **Another editor's change appears as your server has it.** The Studio no longer replays other people's changes on top of the content it loaded with, so a change made against a newer deployment can no longer show up twice or out of order.
173
+ - **Less sent with every draft page.** A page in draft mode no longer embeds the whole published content of a site served without a rebuild for the Studio to start from; `ValDraft.base` is deprecated and no longer filled in.
174
+ - **When the editor opens on a page that already shows your changes,** the Studio no longer sends them to the page again.
175
+
176
+ - Updated dependencies [[`33c8b80`](https://github.com/valbuild/val/commit/33c8b80f877f1c3bec3cb61ef41dea9d2efcf908), [`213d635`](https://github.com/valbuild/val/commit/213d6359a1ec09cba1596ef03f415d3b5c0f2710), [`59faf33`](https://github.com/valbuild/val/commit/59faf332418af836617e09150fb89007e468394e), [`abf6148`](https://github.com/valbuild/val/commit/abf6148a255abe795620fede66006462bccb8322), [`04ed1f1`](https://github.com/valbuild/val/commit/04ed1f10b597a52822d32017597692f0e1062b7b), [`01772a5`](https://github.com/valbuild/val/commit/01772a5b36549d71f6b438ff17803dfcb64ce645), [`1f08b65`](https://github.com/valbuild/val/commit/1f08b6517adeac27fd9e43c7bf726976daefee3b), [`a325152`](https://github.com/valbuild/val/commit/a325152856a881faec84c112fcf226828739f563), [`b682509`](https://github.com/valbuild/val/commit/b682509b91dcd6e6aa2e1dfcedab0f259634c73e), [`f5110c9`](https://github.com/valbuild/val/commit/f5110c9aa2a0a6ff0586e9f0f2a29eb1baef557d), [`a806f7d`](https://github.com/valbuild/val/commit/a806f7de0c605145163c7f0babf389a5b5bf3ef3), [`04bae7e`](https://github.com/valbuild/val/commit/04bae7e54e6b191fc70f45e6f10bbce820b6069c), [`4fd35f3`](https://github.com/valbuild/val/commit/4fd35f321fe510cfb5b9b679ca14ce2b9e852d40), [`346e6fd`](https://github.com/valbuild/val/commit/346e6fdc8e242bf826ab66a729eacd9f8d4be1a6), [`b0ad7f4`](https://github.com/valbuild/val/commit/b0ad7f496f2dc0384b8df847b1d77becf617b7bf), [`3aff85e`](https://github.com/valbuild/val/commit/3aff85e9a40cb0879285b86fd41fa8167db1bb5e), [`809873c`](https://github.com/valbuild/val/commit/809873cd7dd2c17e261b7e92716397a6bb4d6e56), [`b41da31`](https://github.com/valbuild/val/commit/b41da31a26b3236ccd55c02108c56422d8d91f5e), [`e30da7d`](https://github.com/valbuild/val/commit/e30da7d9bca5d5773aa287e8b4c16a01e757ff9a), [`66d487f`](https://github.com/valbuild/val/commit/66d487f3662164a9a167ec660afc6d12b441aa22), [`4dc1481`](https://github.com/valbuild/val/commit/4dc1481cfb7cad4072bdbeaeb51b2b2ad43a9f5d), [`4edd384`](https://github.com/valbuild/val/commit/4edd384cf04a25836df77aae6d88378f8750a761)]:
177
+ - @valbuild/ui@0.151.0
178
+ - @valbuild/shared@0.151.0
179
+ - @valbuild/core@0.151.0
180
+
3
181
  ## 0.150.23
4
182
 
5
183
  ### Patch Changes
@@ -1 +1,2 @@
1
1
  export { ValRichText } from "./ValRichText.js";
2
+ export * from "../read/index.js";
@@ -0,0 +1,105 @@
1
+ import type { Json, ModuleFilePath } from "@valbuild/core";
2
+ import type { ModuleVersion } from "@valbuild/shared/internal";
3
+ import { ValExternalStore } from "./overlayStore.js";
4
+ /**
5
+ * What a draft page shows, read by the server for the request that renders it.
6
+ *
7
+ * The source of every module the editor's draft CHANGES -- the ones with
8
+ * patches applied, published-not-yet-built ones included -- and nothing
9
+ * else: a module without changes is the build's own source, which the page
10
+ * already has. Handed to `<ValProvider draft>` so the server's render and the
11
+ * browser's first render resolve the same text, and the page never shows the
12
+ * published version first and the draft a moment later.
13
+ *
14
+ * A `.jsonValues()` module is in the shape the Studio's own store gives it: the
15
+ * entries the draft edits hold their content, and every other entry is the
16
+ * thunkless marker the hooks resolve from the bundle.
17
+ *
18
+ * Plain JSON, because it travels from the server to the browser in the page's
19
+ * loader data (or a server component's props). `fetchValDraft` in
20
+ * `@valbuild/tanstack/server` reads it. Moved here from `@valbuild/tanstack`,
21
+ * which still exports it, when `@valbuild/next`'s `ValProvider` took a
22
+ * `draft` too: the page's half is the same in both.
23
+ */
24
+ export type ValDraft = {
25
+ sources: Record<ModuleFilePath, Json>;
26
+ /**
27
+ * The version of each module in {@link sources}, as the server's draft
28
+ * computed it: `{ schema, base, chain }`, plain strings. The Studio relays
29
+ * each module with the version it computed, which is the server's for the
30
+ * same content, so the page compares two versions rather than two
31
+ * modules' content -- on the first relay too -- and tells the Studio which
32
+ * versions it holds when it connects. Optional: a draft read by a server
33
+ * of the release before carries none, and is compared by content.
34
+ */
35
+ versions?: Record<ModuleFilePath, {
36
+ schema: string;
37
+ base: string;
38
+ chain: string;
39
+ }>;
40
+ /**
41
+ * At a proposal's address: the Source the proposal has saved, which
42
+ * replaces the bundle's for those modules on EVERY render, draft or not --
43
+ * the third source provider (`ValProposal` in `@valbuild/server`). Sent
44
+ * whether or not draft mode is on, because a reviewer who is not editing is
45
+ * looking at the proposal too. A draft, when there is one, applies on top.
46
+ */
47
+ snapshot?: Record<ModuleFilePath, Json>;
48
+ /**
49
+ * @deprecated Not sent any more, and not read: the Studio's overlay reads
50
+ * the base the server is on by version (the manifest names it), so a page
51
+ * no longer hands it over. Kept on the type for a release, so a draft of
52
+ * the release before still type-checks; it goes after that.
53
+ */
54
+ base?: Record<ModuleFilePath, Json>;
55
+ /**
56
+ * `false` when no draft was read -- draft mode is off -- and this carries
57
+ * only the {@link snapshot}. Absent: a draft, as it always was.
58
+ */
59
+ draftMode?: false;
60
+ /**
61
+ * `true` at a proposal's address. Not the same as a {@link snapshot}: a
62
+ * site serving a content version -- content published without a build --
63
+ * hands the readers that as a snapshot too, and is the live site. Content
64
+ * analytics counts the live site's visitors and nobody else's, so this is
65
+ * what `ValProvider` asks, never whether there is a snapshot.
66
+ */
67
+ atProposal?: true;
68
+ };
69
+ /**
70
+ * Whether a server-read draft is a draft. At a proposal's address the server
71
+ * sends its snapshot whether or not draft mode is on, and one that is ONLY a
72
+ * snapshot (`draftMode: false`) is not a draft: it must not turn draft mode on
73
+ * or say the draft is synced.
74
+ */
75
+ export declare function isDraft(draft: ValDraft | null | undefined): draft is ValDraft;
76
+ /**
77
+ * The store a page starts from: seeded with the server-read draft, so the
78
+ * server render and the browser's first render show the same thing. What
79
+ * both frameworks' providers start from, and the scenario world's page.
80
+ *
81
+ * The seed (`seeded`, in a read's `from`) is held in the overlay's store
82
+ * rather than read as a source of its own, because what the Studio relays
83
+ * later is compared with what the page shows (`ValExternalStore.receive`):
84
+ * the first relay of a module the server already rendered moves nothing.
85
+ */
86
+ export declare function createDraftStore(draft: ValDraft | null | undefined): ValExternalStore;
87
+ /**
88
+ * What the page reports to the Studio when it connects: the modules it was
89
+ * rendered with a draft of. The Studio sends each of them in its catch-up,
90
+ * pending or not (`sendPendingSources` in `@valbuild/ui`), so a draft that
91
+ * stopped being the draft before the Studio was there -- discarded,
92
+ * published -- is replaced rather than kept. With the version of each
93
+ * where the draft carries one ({@link draftHoldsVersions}): the page compares
94
+ * what it is sent with what it holds by version (`ValExternalStore.receive`),
95
+ * and a module that did not move costs nothing.
96
+ */
97
+ export declare function draftHolds(draft: ValDraft | null | undefined): ModuleFilePath[];
98
+ /**
99
+ * The versions the page was rendered with, of the modules
100
+ * {@link draftHolds} names, where the draft says (phase 6 of
101
+ * `docs/plans/one-content-model.md`): what the page reports beside the paths
102
+ * when it connects, so the Studio can tell a module the page holds at the
103
+ * version it would send. A module without one is left out.
104
+ */
105
+ export declare function draftHoldsVersions(draft: ValDraft | null | undefined): Partial<Record<ModuleFilePath, ModuleVersion>>;
@@ -0,0 +1,8 @@
1
+ export { ValExternalStore, applyValEvent, type HeldRead, type ValEventOutcome, } from "./overlayStore.js";
2
+ export { createDraftStore, draftHolds, draftHoldsVersions, isDraft, type ValDraft, } from "./draft.js";
3
+ export { startRefreshLoop, type RefreshLoop } from "./refreshLoop.js";
4
+ export { bundleSource, entryOfModuleSource, overlaySource, snapshotSource, type OverlayState, } from "./sources.js";
5
+ export { layered, type LocatedRead, type SchemaRule, type LayeredView, } from "./layered.js";
6
+ export { mapResolution, planOf, readWork, resolveModuleEntry, resolveVal, resolveValEntry, type ReadEnv, type ReadOf, type ReadPlan, type Resolution, type ResolveOptions, } from "./resolveVal.js";
7
+ export { awaitResolved, fetchValFrom, readsOfFetchVal, useResolved, useResolvedEntry, useResolvedVal, type FetchValWithReads, type Ready, } from "./readers.js";
8
+ export { bundledJsonEntryImport, getJsonEntryStegaRoot, isJsonValuesRecordSchema, } from "./jsonValues.js";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * True when the module's schema is a `.jsonValues()` record/router — i.e. each
3
+ * entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
4
+ * readers to load ONLY the entries they need instead of the whole record.
5
+ */
6
+ export declare function isJsonValuesRecordSchema(schema: unknown): boolean;
7
+ /**
8
+ * The bundle's import of one `.jsonValues()` entry: `undefined` when the
9
+ * module's own source has no marker for `key` to import from.
10
+ */
11
+ export declare function bundledJsonEntryImport(module: any, key: string): (() => Promise<{
12
+ default: unknown;
13
+ }>) | undefined;
14
+ /**
15
+ * Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
16
+ * strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
17
+ * identity transform (the content carries no selector path/schema).
18
+ *
19
+ * Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
20
+ * field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
21
+ * `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
22
+ */
23
+ export declare function getJsonEntryStegaRoot(selector: any, key: string): {
24
+ path: any;
25
+ schema: any;
26
+ } | undefined;
@@ -0,0 +1,45 @@
1
+ import { type ModuleFilePath } from "@valbuild/core";
2
+ import type { ContentSource, EntryRead, ModuleRead } from "@valbuild/shared/internal";
3
+ /**
4
+ * The rule that content is only read with the schema it was made for
5
+ * (`docs/plans/one-content-model.md`, goal 3).
6
+ *
7
+ * `schemaOf(path)` is the version of the schema the READER's code has for a
8
+ * module (`null`: not known, so no rule). A source whose answer names
9
+ * another schema is not read: with `codeChanged` the read waits until the
10
+ * code catches up; without it the next source answers, which ends at the
11
+ * reader's own bundle -- content of the code that reads it.
12
+ */
13
+ export type SchemaRule = {
14
+ schemaOf(path: ModuleFilePath): string | null;
15
+ codeChanged?(path: ModuleFilePath, schema: string): Promise<void>;
16
+ };
17
+ /** A module read, with the place in the list of the source that answered it. */
18
+ export type LocatedRead = {
19
+ read: ModuleRead;
20
+ /** The index of the source that answered; `-1` when none did. */
21
+ at: number;
22
+ };
23
+ /** What `layered` gives back: one view over the sources, first answer wins. */
24
+ export type LayeredView = {
25
+ readonly sources: readonly ContentSource[];
26
+ module(path: ModuleFilePath): LocatedRead;
27
+ /** An entry, from the sources after `after` (all of them by default). */
28
+ entry(path: ModuleFilePath, key: string, after?: number): EntryRead;
29
+ subscribe(paths: readonly ModuleFilePath[], onChange: () => void): () => void;
30
+ revision(paths: readonly ModuleFilePath[]): string;
31
+ };
32
+ /**
33
+ * The ONE place that decides which source wins: the first that does not
34
+ * pass. Replaces the source-priority arrays each reader wrote inline
35
+ * (`[draft, snapshot]`, then the bundle, in four places), and is the only
36
+ * place the schema rule is applied.
37
+ */
38
+ export declare function layered(sources: readonly ContentSource[], rule?: SchemaRule,
39
+ /**
40
+ * Waits that are already over. A source still answering one of them is
41
+ * passed over: what it waited for came and did not give it an answer (draft
42
+ * mode stayed unknown, a module the Studio never sent), and the read goes on
43
+ * as it would have without waiting.
44
+ */
45
+ settled?: ReadonlySet<Promise<void>>): LayeredView;
@@ -0,0 +1,113 @@
1
+ import { type Json, type ModuleFilePath } from "@valbuild/core";
2
+ import type { ModuleRead } from "@valbuild/shared/internal";
3
+ /** A read the overlay holds: always an answer. */
4
+ export type HeldRead = Extract<ModuleRead, {
5
+ status: "ready";
6
+ }>;
7
+ /**
8
+ * The page's store of what the Studio sent it: one read per module, as the
9
+ * relay sent it (`startOverlayRelay`). What `overlaySource` answers from.
10
+ *
11
+ * Moved here from `@valbuild/next` and `@valbuild/tanstack`, which each had a
12
+ * copy: the page's half of the relay is the same in both.
13
+ */
14
+ export declare class ValExternalStore {
15
+ private readonly listeners;
16
+ private readonly loadPromises;
17
+ private readonly reads;
18
+ private readonly revisions;
19
+ private readonly snapshots;
20
+ private readonly loadListeners;
21
+ constructor();
22
+ subscribe: (paths: readonly ModuleFilePath[]) => (listener: () => void) => () => void;
23
+ /** {@link receive}, for a source with nothing more to say about it. */
24
+ update(path: ModuleFilePath, source: Json): boolean;
25
+ /**
26
+ * Take a module's read from the editor, as it sent it.
27
+ *
28
+ * Returns whether this actually MOVED the value, which the caller needs and
29
+ * cannot work out for itself: the same source arrives more than once by
30
+ * design. The editor sends a catch-up snapshot of everything it holds every
31
+ * time the page becomes a new document — a reload, or the one the dev server
32
+ * does when a publish rewrites the `.val.ts` files — and most of that
33
+ * snapshot is content this page already has.
34
+ *
35
+ * The answer tells the page's refresh loop whether the Studio's catch-up
36
+ * found the page behind (`startRefreshLoop`'s `changed`): a re-sent module
37
+ * the page already shows is no reason to re-read its server, and with
38
+ * auto-save on, counting arrivals was a whole-route request per pause in
39
+ * typing -- in development a re-render (and sometimes a recompile) of the
40
+ * page, and what left the canvas looking permanently busy.
41
+ */
42
+ receive(path: ModuleFilePath, read: HeldRead): boolean;
43
+ /** What the editor sent for `path`, or `undefined` for nothing yet. */
44
+ read(path: ModuleFilePath): HeldRead | undefined;
45
+ /**
46
+ * Changes exactly when what this store holds for any of `paths` moves: a
47
+ * `useSyncExternalStore` snapshot that is `===` while nothing moved.
48
+ */
49
+ revision(paths: readonly ModuleFilePath[]): string;
50
+ private emitChange;
51
+ getSnapshot: (paths: readonly ModuleFilePath[]) => () => Record<ModuleFilePath, Json> | undefined;
52
+ getServerSnapshot: (paths: readonly ModuleFilePath[]) => () => Record<ModuleFilePath, Json> | undefined;
53
+ get: (paths: readonly ModuleFilePath[]) => Record<ModuleFilePath, Json> | undefined;
54
+ hasAllLoaded: (paths: readonly ModuleFilePath[]) => boolean;
55
+ /**
56
+ * Returns a cached promise that resolves once `update()` has populated
57
+ * every path in `paths`. The same promise instance is returned for the
58
+ * same paths until it resolves — required so `React.use` / classic
59
+ * Suspense doesn't re-suspend on every render.
60
+ *
61
+ * If the data never arrives (network failure, a path that is never
62
+ * `update()`'d, a typo in a module path) the promise would otherwise hang
63
+ * forever and keep the Suspense boundary in its fallback. To avoid a silent
64
+ * hang it resolves anyway after `LOAD_TIMEOUT_MS`, logging an error so the
65
+ * failure is diagnosable while the page still renders with partial data.
66
+ */
67
+ waitForLoad: (paths: readonly ModuleFilePath[]) => Promise<void>;
68
+ }
69
+ /** What one `val-event` from the overlay did to the page's store. */
70
+ export type ValEventOutcome = {
71
+ type: "synced";
72
+ }
73
+ /**
74
+ * The server holds the editor's changes up to `seq`: what the page
75
+ * re-reads its server-rendered content on (`startRefreshLoop`).
76
+ */
77
+ | {
78
+ type: "confirmed";
79
+ seq: number | null;
80
+ }
81
+ /**
82
+ * `changed`: the store holds something new. Not a reason to refresh on its
83
+ * own -- the server may not have it yet -- only, before the first
84
+ * `confirmed`, that the page's render is behind the Studio's.
85
+ */
86
+ | {
87
+ type: "updated";
88
+ changed: boolean;
89
+ /**
90
+ * Sent by a Studio of the release before: a bare `source`, from a
91
+ * Studio that never says `confirmed` -- so the page refreshes on the
92
+ * change itself (`RefreshLoop.changedByPreviousStudio`), as that
93
+ * release's page did. Goes with the relay's `source` (see
94
+ * "Release-delayed deletions" in `docs/plans/one-content-model.md`).
95
+ */
96
+ fromPreviousStudio?: true;
97
+ } | {
98
+ type: "invalid";
99
+ detail: unknown;
100
+ };
101
+ /**
102
+ * Apply one overlay event (`detail` of a `val-event`) to the page's store.
103
+ * `sources-synced` says the editor has sent everything it holds;
104
+ * `confirmed` how far the server holds the editor's changes; a
105
+ * `source-update` hands over one module's read, which the store keeps as it
106
+ * is (`read`). A Studio from the release before sent the bare `source`
107
+ * instead, and a page newer than the Studio it is open in -- a deploy rolling
108
+ * out -- still takes that.
109
+ *
110
+ * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
111
+ * provider had the same rule written inline.
112
+ */
113
+ export declare function applyValEvent(store: ValExternalStore, detail: unknown): ValEventOutcome;
@@ -0,0 +1,51 @@
1
+ import type { ResolvableModule } from "@valbuild/core";
2
+ import type { JsonEntryContentOf, Resolvable, ResolvedVal } from "../stega/stegaEncode.js";
3
+ import type { ReadEnv, ReadOf, Resolution } from "./resolveVal.js";
4
+ /** A read that is ready: the value, and what it was read from. */
5
+ export type Ready<T> = {
6
+ value: T;
7
+ reads: readonly ReadOf[];
8
+ };
9
+ /**
10
+ * Resolve on the server: wait for what is pending, then resolve again, with
11
+ * the waits that are over handed back (`settled`, see `layered`).
12
+ */
13
+ export declare function awaitResolved<T>(resolve: (settled: ReadonlySet<Promise<void>>) => Resolution<T>): Promise<Ready<T>>;
14
+ /**
15
+ * Resolve in a component: subscribe to the modules `selector` reads, and
16
+ * suspend on what is pending (`React.use`, which the caller's `<Suspense>`
17
+ * boundary waits on). The one hook every client reader of both frameworks is
18
+ * built on; `env` is the framework's.
19
+ *
20
+ * Re-renders when a source says a read of those modules would answer
21
+ * differently -- `revision` is a string, so `useSyncExternalStore` compares
22
+ * it with `===` and a render that moves nothing re-renders nothing.
23
+ */
24
+ export declare function useResolved<T>(selector: unknown, env: ReadEnv, resolve: (settled: ReadonlySet<Promise<void>>) => Resolution<T>): T;
25
+ /**
26
+ * `useVal`, for both frameworks: the one hook that was `useValStega` in each,
27
+ * with the framework's env (its overlay, its snapshot, its rule for edit
28
+ * tags). `entries: false` for a reader that needs a `.jsonValues()` record's
29
+ * keys and not its entries.
30
+ */
31
+ export declare function useResolvedVal<T extends Resolvable>(selector: T, env: ReadEnv, opts?: {
32
+ entries?: boolean;
33
+ }): ResolvedVal<T>;
34
+ /**
35
+ * `useValKey`, for both frameworks: one `.jsonValues()` entry, loading that
36
+ * entry and no other. `key: null` reads nothing (a route the params did not
37
+ * match), and still subscribes, so the hooks of a component stay the same.
38
+ */
39
+ export declare function useResolvedEntry<T extends ResolvableModule>(selector: T, key: string | null, env: ReadEnv): JsonEntryContentOf<T> | undefined;
40
+ /** A `fetchVal` that also says what it read. */
41
+ export type FetchValWithReads = <T extends Resolvable>(selector: T) => Promise<Ready<ResolvedVal<T>>>;
42
+ /**
43
+ * The public `fetchVal` of a framework: `withReads`, giving the value only.
44
+ * The reads stay reachable, from the function, for the scenario world
45
+ * (`scenarios/`), which records the version beside the value a loader shows
46
+ * and must call the same function the product does to get it
47
+ * ({@link readsOfFetchVal}). Nothing in the product asks.
48
+ */
49
+ export declare function fetchValFrom(withReads: FetchValWithReads): <T extends Resolvable>(selector: T) => Promise<ResolvedVal<T>>;
50
+ /** The read behind a `fetchVal` made by {@link fetchValFrom}. */
51
+ export declare function readsOfFetchVal(fetchVal: object): FetchValWithReads | null;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * When a draft page re-reads what its server rendered: its loaders (TanStack
3
+ * Start's `router.invalidate()`) or its server components (Next's
4
+ * `router.refresh()`). The hooks need none of this -- they read what the
5
+ * Studio relays -- but server-read content only changes on a refresh, and only
6
+ * shows an edit once the server has it.
7
+ *
8
+ * So the page refreshes when the Studio says the server has CONFIRMED the
9
+ * edit (`confirmed`, with the server's `seq`), never when the edit arrives.
10
+ * Arrived, it raced the write: the page asked a server that did not have the
11
+ * patch yet, got the old content back, and nothing asked again until a safety
12
+ * refresh ten seconds later (S05 in `scenarios/`). That timer, and the 500 ms
13
+ * throttle that was there to keep the edit-driven refreshes from stacking,
14
+ * are gone: this has no timer at all. See `docs/plans/one-content-model.md`,
15
+ * "The page converges on the Studio".
16
+ *
17
+ * - **One refresh per confirmed version.** A version told twice (a save's
18
+ * answer, then the stat after it) or out of order refreshes once.
19
+ * - **At most one in flight**, where the refresh says when it is done (a
20
+ * promise): a version confirmed meanwhile waits for it and is then one more
21
+ * refresh, however many arrived. A refresh that cannot say (Next's
22
+ * `router.refresh()`) is simply sent each time.
23
+ * - **The first `confirmed` is the connection, not news.** The Studio says
24
+ * it once after its catch-up. The page refreshes then only if the catch-up
25
+ * moved what it holds (`changed`): its server render is older than what the
26
+ * Studio has. A page rendered from the draft the Studio holds -- the
27
+ * `draft` prop, read for this request -- is not refreshed for loading.
28
+ * - **A Studio of the release before never says `confirmed`** (a deploy
29
+ * rolling out: this page, that Studio). Its changes refresh the page as
30
+ * they arrive (`changedByPreviousStudio`), as that release's page did,
31
+ * until a `confirmed` says the Studio is this release's. They race the
32
+ * write, as they did then; it lasts as long as the rollout.
33
+ */
34
+ export type RefreshLoop = {
35
+ /** A relayed module moved what the page's store holds. */
36
+ changed(): void;
37
+ /**
38
+ * A relayed module moved what the page's store holds, sent by a Studio of
39
+ * the release before (a bare `source`), which never says `confirmed`: a
40
+ * refresh, unless a `confirmed` has been told on this page. Goes with the
41
+ * relay's `source` ("Release-delayed deletions").
42
+ */
43
+ changedByPreviousStudio(): void;
44
+ /** The server holds the editor's changes up to `seq` (`null`: unknown). */
45
+ confirmed(seq: number | null): void;
46
+ /**
47
+ * Something other than content changed what the server renders -- draft
48
+ * mode was turned on or off -- so refresh now (coalesced like the rest).
49
+ */
50
+ refresh(): void;
51
+ /** How many refreshes this loop has asked for: for the scenario budgets. */
52
+ readonly refreshes: number;
53
+ stop(): void;
54
+ };
55
+ export declare function startRefreshLoop(options: {
56
+ /**
57
+ * Re-read the server: the provider's refresh, in a transition. A promise
58
+ * that settles when the refreshed content is in, where the framework says.
59
+ */
60
+ refresh: () => Promise<unknown> | void;
61
+ }): RefreshLoop;