@valbuild/server 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 (66) hide show
  1. package/CHANGELOG.md +341 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +5 -137
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +5 -137
  4. package/browser/dist/valbuild-server-browser.esm.js +4 -140
  5. package/dist/ValRouter-05fcb0da.esm.js +14663 -0
  6. package/dist/ValRouter-afcba447.cjs.dev.js +14759 -0
  7. package/dist/ValRouter-b4e5b412.cjs.prod.js +14759 -0
  8. package/dist/{ValRouterCore-0c7ae881.cjs.prod.js → ValRouterCore-a0ea46bf.cjs.prod.js} +3324 -1883
  9. package/dist/{ValRouterCore-5b6cccd4.esm.js → ValRouterCore-b5d70504.esm.js} +3316 -1879
  10. package/dist/{ValRouterCore-cfa7b001.cjs.dev.js → ValRouterCore-d16c3327.cjs.dev.js} +3324 -1883
  11. package/dist/declarations/src/ValOps.d.ts +334 -70
  12. package/dist/declarations/src/ValOpsFS.d.ts +32 -0
  13. package/dist/declarations/src/ValOpsHttp.d.ts +93 -3
  14. package/dist/declarations/src/ValOpsMemory.d.ts +22 -47
  15. package/dist/declarations/src/ValRouter.d.ts +10 -0
  16. package/dist/declarations/src/ValServer.d.ts +0 -10
  17. package/dist/declarations/src/browser/inTabFetch.d.ts +19 -2
  18. package/dist/declarations/src/draftOverlay.d.ts +51 -0
  19. package/dist/declarations/src/draftReads.d.ts +103 -0
  20. package/dist/declarations/src/head.d.ts +312 -0
  21. package/dist/declarations/src/history/getJsonEntryAtCommit.d.ts +52 -0
  22. package/dist/declarations/src/index.d.ts +1 -0
  23. package/dist/declarations/src/internal/browser/index.d.ts +11 -0
  24. package/dist/declarations/src/internal/index.d.ts +15 -0
  25. package/dist/declarations/src/patch/jsonValuesPatch.d.ts +2 -165
  26. package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +38 -0
  27. package/dist/declarations/src/patch/ts/loadTypeScriptKit.d.ts +14 -0
  28. package/dist/declarations/src/patch/ts/ops.d.ts +45 -0
  29. package/dist/declarations/src/patch/ts/publishKit.d.ts +26 -0
  30. package/dist/declarations/src/platform.d.ts +14 -0
  31. package/dist/declarations/src/proposal.d.ts +54 -3
  32. package/dist/declarations/src/valRuntime.d.ts +35 -0
  33. package/dist/draftReads-05415ff6.cjs.dev.js +366 -0
  34. package/dist/draftReads-5f99edd3.esm.js +361 -0
  35. package/dist/draftReads-ea3946e0.cjs.prod.js +366 -0
  36. package/dist/inTabFetch-095bb2be.cjs.prod.js +179 -0
  37. package/dist/inTabFetch-2cbbfaa4.cjs.dev.js +179 -0
  38. package/dist/inTabFetch-91c3e85e.esm.js +176 -0
  39. package/dist/{getJsonEntryAtCommit-d9b5f753.cjs.dev.js → publishKit-4e2b0014.cjs.dev.js} +55 -6
  40. package/dist/{getJsonEntryAtCommit-acf8c269.cjs.prod.js → publishKit-6e52ffa6.cjs.prod.js} +55 -6
  41. package/dist/{getJsonEntryAtCommit-8ff81ef5.esm.js → publishKit-af14cd7a.esm.js} +48 -5
  42. package/dist/valbuild-server.cjs.dev.js +160 -13319
  43. package/dist/valbuild-server.cjs.prod.js +160 -13319
  44. package/dist/valbuild-server.esm.js +34 -13174
  45. package/internal/browser/dist/valbuild-server-internal-browser.cjs.d.ts +2 -0
  46. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +19 -0
  47. package/internal/browser/dist/valbuild-server-internal-browser.cjs.js +7 -0
  48. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +19 -0
  49. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +10 -0
  50. package/internal/browser/package.json +4 -0
  51. package/internal/dist/valbuild-server-internal.cjs.d.ts +2 -0
  52. package/internal/dist/valbuild-server-internal.cjs.dev.js +43 -0
  53. package/internal/dist/valbuild-server-internal.cjs.js +7 -0
  54. package/internal/dist/valbuild-server-internal.cjs.prod.js +43 -0
  55. package/internal/dist/valbuild-server-internal.esm.js +24 -0
  56. package/internal/package.json +4 -0
  57. package/package.json +17 -6
  58. package/dist/jsonValuesModule-235bd751.cjs.dev.js +0 -326
  59. package/dist/jsonValuesModule-23eb6f53.esm.js +0 -310
  60. package/dist/jsonValuesModule-625ebae8.cjs.prod.js +0 -326
  61. package/dist/ops-0e54b388.cjs.prod.js +0 -361
  62. package/dist/ops-9ca2ef2a.cjs.dev.js +0 -361
  63. package/dist/ops-b904007e.esm.js +0 -353
  64. package/dist/publishKit-34f71e50.cjs.dev.js +0 -42
  65. package/dist/publishKit-65e9e564.cjs.prod.js +0 -42
  66. package/dist/publishKit-7441c0fd.esm.js +0 -31
package/CHANGELOG.md CHANGED
@@ -1,5 +1,346 @@
1
1
  # @valbuild/server
2
2
 
3
+ ## 0.152.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1013](https://github.com/valbuild/val/pull/1013) [`3bb76d7`](https://github.com/valbuild/val/commit/3bb76d74d82b499aa15023838d63018a70fd7ce7) Thanks [@freekh](https://github.com/freekh)! - A save that the content service fails to take no longer looks like a successful one.
8
+
9
+ Before, when the content service answered a save with a server error (or could not be reached), the Studio treated the edit as invalid and dropped it: the field went back to its old value, and the status bar kept saying "All changes saved". Now:
10
+
11
+ - **Your edit is kept.** The field keeps what you typed.
12
+ - **The Studio says the save failed.** The status bar shows "Could not save" (never "All changes saved" while a save has failed or is still pending), and a notice says which service failed, with the service's own message under **Details**.
13
+ - **Try again** sends the same save again. The Studio also retries by itself in the background, so if you leave the tab open your changes are saved once the service is back.
14
+
15
+ Pressing Publish while a save has failed now says what failed, in the service's words, with a **Save again** button, instead of "Check the connection and try again".
16
+
17
+ Saves that the service refuses because of your plan, and saves that conflict with someone else's change, work as before.
18
+
19
+ Error messages from the content service also stop blaming your network. "Could not get your changes. It is most likely due to a network issue. Check your network connection" was shown even when the service had answered with a 500. These messages now say what actually happened (the service answered with an error, refused the request, or could not be reached from your site's server) and name the service. The status code and the service's response are kept as details for whoever needs to look into it. Publish failures now also show the service's own message, where they used to say "Unknown error".
20
+
21
+ - 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)]:
22
+ - @valbuild/ui@0.152.0
23
+ - @valbuild/shared@0.152.0
24
+
25
+ ## 0.151.0
26
+
27
+ ### Minor Changes
28
+
29
+ - [#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
30
+ mode used to make Val's server read every module, apply every pending
31
+ change, and preview and validate the whole project on every request -- and
32
+ then ask again for each `.jsonValues()` entry it showed. Now there is one
33
+ copy of the draft per process, made once per change and shared by every
34
+ editor and every request:
35
+
36
+ - A module nobody edited costs nothing: the page reads its own build, as a
37
+ visitor's does.
38
+ - A request asks one cheap question -- has anything changed? -- once, and
39
+ the draft is only re-read when it has. An edit is applied once, to the
40
+ version before it, however many pages read it afterwards.
41
+ - `fetchVal`, `fetchValKey`, `fetchValRoute`, `fetchValRouteUrl` and
42
+ `fetchValDraft` (Next.js and TanStack Start alike) and Val's API routes
43
+ read that one copy, so a save through the API is seen by every reader at
44
+ once. Before, each kept its own, and a publish moved only the copy of the
45
+ server that handled it: in a host that keeps its content in memory, a
46
+ draft page read through `fetchValKey` or `fetchValRoute` went on showing
47
+ the content from before the publish.
48
+ - The MCP tools (`initValMcp`) read the same copy in local development and
49
+ on Val's hosting, where Val's options come from your config and the
50
+ environment. `initValMcp` takes no patch store or source files of its
51
+ own, so in a host that keeps its content in memory it keeps a copy of its
52
+ own, as before.
53
+ - If `initValServer` and `initValContent` (or `initValRsc`) are given
54
+ different options for the same `val.modules` (a different patch store,
55
+ say), they keep separate copies, and Val logs a warning saying which
56
+ options differ.
57
+
58
+ On a site of 20 MB of content a draft read went from about half a second per
59
+ request to well under a millisecond once the draft is in memory, and the
60
+ memory it holds grows with what was edited rather than with the size of the
61
+ site. Hosted sites in proxy mode ask the content service one small question
62
+ per request instead of reading every pending change; with a content service
63
+ that predates it, Val reads the pending changes as before.
64
+
65
+ `ValDraft` (what `fetchValDraft` returns and `<ValProvider draft>` takes)
66
+ has a new optional `versions` field, filled in by the server: the page uses
67
+ it to tell that what the Studio sends is what it already shows, without
68
+ comparing the content. Nothing to change in your app.
69
+
70
+ **Changed:** `PUT /api/val/sources/~` no longer computes previews or
71
+ validates the content (the Studio does both itself, and `/api/val/validate`
72
+ checks a module on request); its `validate_sources` and
73
+ `validate_binary_files` flags are accepted and ignored.
74
+
75
+ **Deprecated, and removed in the next release.** These stay for one release
76
+ only so that a Studio, a page or a server of the previous release keeps
77
+ working while a deploy rolls out. Nothing in this release uses them; if
78
+ your own code calls any of them, move off it now:
79
+
80
+ - `PUT /api/val/sources/~`, the whole route. This release's Studio reads
81
+ `GET /api/val/manifest` and `GET /api/val/modules/~<path>`, and the draft
82
+ readers and MCP read in-process.
83
+ - The `source` field of the overlay's `source-update` event and the canvas's
84
+ `sourceUpdate` message, and a page's support for an event that carries
85
+ only `source` (this release sends `read` beside it).
86
+ - `ValDraft.base`: not sent and not read; the type stays one release so
87
+ code written against the previous one still compiles.
88
+ - `/api/val/stat`'s `sourcesSha` and `schemaSha`: the next release's Studio
89
+ stops depending on them, and the release after it stops sending them.
90
+
91
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`560abd9`](https://github.com/valbuild/val/commit/560abd9df36e52e63b6592b03a8040396320df00) Thanks [@freekh](https://github.com/freekh)! - Val's server in the browser (`@valbuild/server/browser`, which the demo
92
+ runs) no longer carries the TypeScript compiler. Bundled into a single file,
93
+ as a Cloudflare Worker is, it goes from 12.9 MB to 2.0 MB (2.1 MB to 0.4 MB
94
+ gzipped). An app that splits its bundle into chunks, as Vite does, no longer
95
+ builds a 3.5 MB chunk that the demo never loaded.
96
+
97
+ Nothing changes for a server started with `createValServer`: it still
98
+ publishes and reads history as before.
99
+
100
+ If you construct `ValOpsMemory` yourself and publish through it, pass
101
+ `typescript: loadTypeScriptKit` (exported from `@valbuild/server`). Without
102
+ it, a publish is refused with an error that says so, and nothing is lost:
103
+ the changes stay pending.
104
+
105
+ ### Patch Changes
106
+
107
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`33c8b80`](https://github.com/valbuild/val/commit/33c8b80f877f1c3bec3cb61ef41dea9d2efcf908) Thanks [@freekh](https://github.com/freekh)! - **Build on their push.** When a developer pushes to a proposal's git branch
108
+ (`val/p/<name>`), Commit and Publish no longer leave you stuck. Instead of
109
+ committing over a push it has not seen, the Studio says who pushed and when,
110
+ links to their commit, and offers **Build on their push**:
111
+
112
+ - Their changes come into the proposal. Where you both changed the same file,
113
+ the proposal's version is kept, and the Studio lists those files. Anything
114
+ a proposal cannot hold (for example a change outside the project) is listed
115
+ too, since the next Commit leaves it as the site has it.
116
+ - Anything waiting to be saved is saved first, so "the proposal's version" is
117
+ what you see.
118
+ - The proposal's preview is rebuilt with their code. Commit goes through
119
+ right away, on top of their commit; Publish waits for the rebuild and says
120
+ so.
121
+ - If they push again in the meantime, the notice moves to their newer commit.
122
+ If GitHub cannot be reached, the session ran out, or the project's plan
123
+ does not allow changes, it offers Try again, Sign in or Billing. When
124
+ nothing can help from here (their push is too large to bring in, say), it
125
+ says so and offers only their commit.
126
+
127
+ Publish refused the same way now shows the same notice inside the Publish
128
+ dialog, rather than a Try again that would fail again. When GitHub refuses
129
+ Publish's commit for good (a protected branch), the dialog links the branch
130
+ instead of offering Try again. On a phone, where Publish is finished in a new
131
+ tab, the commit message you typed now goes with it, and a refusal there
132
+ comes back to the dialog with the same offer.
133
+
134
+ Publish pressed from the design tab, on the site, is refused the same way
135
+ when someone has pushed to the proposal's branch. Build on their push can
136
+ only be done in the proposal's own Studio, so the dialog says who pushed and
137
+ when, links their commit, and offers **Open the proposal**, where Publish
138
+ offers Build on their push. It no longer offers a Try again that would fail
139
+ again, and a branch GitHub refuses for good links the branch there too.
140
+
141
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`59faf33`](https://github.com/valbuild/val/commit/59faf332418af836617e09150fb89007e468394e) Thanks [@freekh](https://github.com/freekh)! - Code mode now works in a hosted Studio. In a proposal, the `</>` beside the
142
+ proposal's name turns code mode on for everyone in it, and the assistant can
143
+ then change the proposal's code. On the site, the `</>` lists the open
144
+ proposals and opens the one you choose with code mode on.
145
+
146
+ - **Nothing you typed is lost when code changes.** Turning code mode on saves
147
+ every pending change first, and so does each of the assistant's code
148
+ changes, so a field the assistant adds can be filled in and stays filled
149
+ in. Turning code mode off discards nothing.
150
+ - **Each person chooses what they see.** While code mode is on you can stay
151
+ in the content editor, or see the proposal's preview and its code changes.
152
+ The proposal's menu says who turned code mode on, and when.
153
+ - **The assistant asks.** With code mode off, its code tools refuse and say
154
+ who turned it off; it asks for code mode with a button in the chat instead.
155
+ - **Save is the one main button** in a proposal, and also updates the
156
+ preview when the code changed. Its menu holds **Commit**, in a project
157
+ connected to git, which puts the proposal on its git branch as one commit,
158
+ and **Publish**, which commits and then merges into the site. Both use the
159
+ project's commit message setting. In code mode, Save saves even when
160
+ content has validation errors; Publish is still refused until they are
161
+ fixed. If someone else pushed to the proposal's branch, Commit says who and
162
+ when, and links to their commit, instead of committing over it.
163
+ - The "schema changed, reload" dialog is not shown in code mode, where the
164
+ schema changes with every build.
165
+
166
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`abf6148`](https://github.com/valbuild/val/commit/abf6148a255abe795620fede66006462bccb8322) Thanks [@freekh](https://github.com/freekh)! - The assistant's code tools now see a publish of the site made while the Studio
167
+ is open. They read the site's code once and kept that copy for as long as the
168
+ page was open, so a file published in the meantime was shown as it was before.
169
+ They now ask on every call, and the content service answers "unchanged" without
170
+ sending the code again unless it did change.
171
+
172
+ - [#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.**
173
+
174
+ - **Pending edits to an entry.** In draft mode, `fetchVal` of a whole
175
+ `.jsonValues()` record now shows the unpublished edits to its entries. It
176
+ used to show the published content of every entry, even one an editor had
177
+ just changed, while `fetchValKey` and `fetchValRoute` of the same entry
178
+ showed the edit. The entries a pending change touches are read from Val's
179
+ server; the others are loaded from your build, as before.
180
+ - **Entries published without a rebuild.** On a host that does not rebuild
181
+ the site after a publish, a draft page now shows the published entries
182
+ straight away -- in `fetchVal`, and in `useVal`, `useValKey` and
183
+ `useValRoute` alike. They used to show those entries as they were before
184
+ the publish, from the site's build, until it was rebuilt (and on TanStack
185
+ Start the server render showed the new content, then the page switched
186
+ back to the old). Val's server marks each entry a publish wrote, and the
187
+ readers and the Studio load a marked entry from the server.
188
+
189
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`04bae7e`](https://github.com/valbuild/val/commit/04bae7e54e6b191fc70f45e6f10bbce820b6069c) Thanks [@freekh](https://github.com/freekh)! - **No more "A new version has been deployed" dialog.** A Studio that is open
190
+ while the site is deployed no longer stops you with a dialog you can only
191
+ answer by reloading. Instead:
192
+
193
+ - **On Val's hosting**, the Studio takes the new build's fields in where you
194
+ are, without reloading: a field the deploy added can be filled in at once,
195
+ and the assistant's chat, the page you were on and your unsaved edits stay
196
+ as they were. Each build now carries its content schemas as a small file of
197
+ its own beside its scripts, which the Studio loads.
198
+ - **Anywhere else** (a Next.js site, or a TanStack Start site hosted
199
+ somewhere else), the Studio reloads itself a few seconds after the deploy,
200
+ once everything you typed has been saved. Nothing is lost: where you were is
201
+ in the address, and every edit is on the server.
202
+ - **In local development** nothing changes: your dev server's hot reload
203
+ brings the new fields, as before.
204
+
205
+ When a deploy upgrades Val itself, the Studio reloads itself the same way,
206
+ since its own code changed too.
207
+
208
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`4fd35f3`](https://github.com/valbuild/val/commit/4fd35f321fe510cfb5b9b679ca14ce2b9e852d40) Thanks [@freekh](https://github.com/freekh)! - Unpublished edits are now applied the same way everywhere the server reads
209
+ them, and a few cases that showed something different from what Publish would
210
+ save are fixed:
211
+
212
+ - A field you emptied to `null`, `""`, `0` or `false` no longer jumps back to
213
+ its published value at your next edit.
214
+ - When an edit cannot be applied, later edits to `.jsonValues()` entries stop
215
+ there too, instead of showing an entry the page will never get.
216
+ - An image or file added to a `.jsonValues()` entry no longer fails the whole
217
+ entry when the upload comes before the field in the edit.
218
+ - Clearing a nullable `.jsonValues()` record removes its entries from drafts
219
+ as well.
220
+
221
+ Long chains of unpublished edits are also much faster to read: a draft with
222
+ 650 edits went from about 580 ms to about 110 ms.
223
+
224
+ - [#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
225
+ of on a timer.
226
+
227
+ - **The page settles faster, and without the 10 second fallback.** Content your
228
+ page reads on the server (a TanStack Start loader, a Next.js server component)
229
+ is refreshed when the editor's change has been saved, once per saved change.
230
+ It used to be refreshed the moment you typed — before the change was saved,
231
+ so the refresh often came back without it — and then again every 10 seconds
232
+ for half a minute in case it had. That safety refresh is gone, and so are the
233
+ extra requests it made while you edited. Another editor's change refreshes
234
+ the page too, once the server has it. While a deploy rolls out, a Studio of
235
+ the previous release (which never says it has saved) still refreshes the
236
+ page as each change arrives, as before.
237
+ - **Next.js: `ValProvider` takes an optional `draft` prop**, as
238
+ `@valbuild/tanstack`'s does: the editor's draft, read on the server for the
239
+ request. With it, the server renders the draft and the browser hydrates the
240
+ same thing, so a draft page no longer shows the published text first, and a
241
+ page that exists only as an unpublished change is found on the first render
242
+ instead of answering 404. Without it, nothing changes. See "The `draft` prop"
243
+ in the `@valbuild/next` README.
244
+ - **Next.js: `initValRsc` returns `fetchValDraft`**, which reads that draft:
245
+ pass `draft={await fetchValDraft()}` to `ValProvider` in your root layout. It
246
+ returns `null` unless the request is in draft mode, after one `draftMode()`
247
+ lookup and no other work, so visitors pay nothing and a static page stays
248
+ static. It reads the draft the way `@valbuild/tanstack/server`'s
249
+ `fetchValDraft` does and returns the same type, `ValDraft | null`, which
250
+ is now exported from `@valbuild/next` and `@valbuild/next/rsc` too.
251
+ - **`suspend` waits for the editor's changes properly.** With `suspend` on
252
+ `ValProvider`, a page could be told it had everything before the editor had
253
+ sent the pending change it needed, and render the published content first —
254
+ for a page that exists only as an unpublished change, a 404. It now waits
255
+ until the change is there.
256
+ - A draft page whose draft was discarded or published before the editor's
257
+ overlay or canvas connected now shows what the editor has, instead of keeping
258
+ the draft it was rendered with -- an edit inside a `.jsonValues()` entry
259
+ included.
260
+ - Turning draft mode on or off refreshes the page once. In development (React's
261
+ `StrictMode`) it could refresh twice, and Next.js could log "Cannot call
262
+ startTransition while rendering" while the page refreshed.
263
+
264
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`3aff85e`](https://github.com/valbuild/val/commit/3aff85e9a40cb0879285b86fd41fa8167db1bb5e) Thanks [@freekh](https://github.com/freekh)! - **A JSON Patch `test` op now fails when it does not hold.** A `test` op is a
265
+ precondition: "only apply this patch if the value at this path is still
266
+ this". Val used to accept every `test` op without checking it, so a patch
267
+ that should have been refused was applied anyway.
268
+
269
+ Now a `test` op fails its patch when the path does not exist, or when the
270
+ value there is not deeply equal to the one given (objects and arrays are
271
+ compared all the way down, and `0`, `""`, `false` and `null` are all
272
+ different from each other). The ops after it are not applied. This holds in
273
+ every place Val applies a patch -- the Studio's drafts, a draft page, the
274
+ content tools for MCP, and Publish -- so a patch a draft shows is a patch
275
+ Publish accepts.
276
+
277
+ Nothing in the Studio, the CLI or the content tools writes `test` ops of
278
+ its own, so this only changes anything for a patch you, or an agent through
279
+ the MCP `create_patch` tool, wrote with a `test` op in it: one whose test
280
+ does not hold is now refused with `Test failed` (or, for a path that does
281
+ not exist, `Path refers to non-existing object/array`) instead of applied.
282
+
283
+ - [#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`,
284
+ `useVal`, the key and route readers, on the server and in the browser — now
285
+ loads content the same way, so they can no longer disagree about which content
286
+ wins. Nothing you call changes. What you may notice:
287
+
288
+ - `useValRoute` on a `.jsonValues()` router loads only the entry for the
289
+ current route. It used to load every entry of the record first.
290
+ `useValRouteUrl` and `fetchValRouteUrl` load none at all: a URL does not need
291
+ them.
292
+ - In development, an edited `*.val.json` entry shows its new content after a
293
+ hot reload. The hooks kept the entry they had loaded before it.
294
+ - Next.js: `useValKey` no longer shows the published entry of a nullable
295
+ `.jsonValues()` record that a draft has set to `null`, nor anything for an
296
+ entry named like a built-in object property (such as `toString`) that the
297
+ draft does not have.
298
+ - With `suspend` on `ValProvider`, `useValKey` now waits for draft mode and the
299
+ editor's changes too, as `useVal` and `useValRoute` already did.
300
+ - When one entry of a `.jsonValues()` record cannot be loaded, `useVal` logs
301
+ the error and renders the others, as `fetchVal` already did, instead of
302
+ failing the whole component.
303
+
304
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`be276e7`](https://github.com/valbuild/val/commit/be276e76f5849fcc421398abdb7e114f3de4d3e8) Thanks [@freekh](https://github.com/freekh)! - In a proposal in code mode, an edit to a field the assistant has just added is
305
+ saved with the assistant's next change, without waiting for the proposal to be
306
+ built.
307
+
308
+ The Studio already let you type into a field that only the assistant's staged
309
+ code has. But the save that runs before the assistant's next change applied
310
+ your edit to the content as the proposal's last build had it -- without the new
311
+ field -- so it failed, and the assistant's next change was refused ("the
312
+ changes waiting to be saved could not be saved first") until someone pressed
313
+ Build.
314
+
315
+ Val's server at the proposal's address now learns which staged code the build
316
+ it runs was made of (the platform hands it over beside the build), and saves a
317
+ module whose code was staged after that build from the staged `.val.ts` itself.
318
+ A page at the address keeps reading such a module as its build has it until a
319
+ build of the new code serves it, so it never shows content made for code it
320
+ does not have.
321
+
322
+ When the server cannot read a staged module's content without running it --
323
+ its content is built by code, or it is a `.jsonValues()` record -- the edit is
324
+ kept, and the assistant's change is refused saying the proposal has to be built
325
+ first, rather than failing with no reason.
326
+
327
+ `@valbuild/tanstack-build` rewrites the proposal block of a `val.server.ts`
328
+ generated before this, so a site picks it up at its next build.
329
+
330
+ - [#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.
331
+
332
+ - **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.
333
+ - **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.
334
+ - **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.
335
+ - **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.
336
+ - **When the editor opens on a page that already shows your changes,** the Studio no longer sends them to the page again.
337
+
338
+ - [#1011](https://github.com/valbuild/val/pull/1011) [`4edd384`](https://github.com/valbuild/val/commit/4edd384cf04a25836df77aae6d88378f8750a761) Thanks [@freekh](https://github.com/freekh)! - Requests that `@valbuild/server` and the `val` CLI send to Val Build now carry an `x-val-client` header naming the package and its version, for example `x-val-client: @valbuild/server@0.150.24`. It lets Val Build see which versions are still in use, and which old endpoints they still call, before anything is retired. The header holds no credential and nothing about your site's visitors, and nothing changes in how your app behaves.
339
+ - 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)]:
340
+ - @valbuild/ui@0.151.0
341
+ - @valbuild/shared@0.151.0
342
+ - @valbuild/core@0.151.0
343
+
3
344
  ## 0.150.23
4
345
 
5
346
  ### Patch Changes
@@ -2,148 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var core = require('@valbuild/core');
6
- var ValRouterCore = require('../../dist/ValRouterCore-cfa7b001.cjs.dev.js');
7
- require('@valbuild/shared/internal');
5
+ var inTabFetch = require('../../dist/inTabFetch-2cbbfaa4.cjs.dev.js');
6
+ require('@valbuild/core');
7
+ require('../../dist/ValRouterCore-d16c3327.cjs.dev.js');
8
8
  require('zod');
9
+ require('@valbuild/shared/internal');
9
10
  require('zod-validation-error');
10
11
  require('@valbuild/core/fp');
11
12
  require('@valbuild/core/patch');
12
13
  require('image-size');
13
14
 
14
- const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
15
-
16
- /**
17
- * The platform for a server running in a browser tab.
18
- *
19
- * Memory mode only: there is no filesystem for `fs` mode and no credential for
20
- * `http` mode. Everything else answers as a server without those things does
21
- * -- no `val login` token, no credential for remote files, no link checks --
22
- * and the session functions refuse, because a tab has no secret to sign with
23
- * and the server is constructed with `unsafelyAllowUnauthenticated`, so
24
- * nothing asks for one.
25
- */
26
- const browserPlatform = {
27
- createOps: (valModules, options) => {
28
- if (options.mode !== "memory") {
29
- throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
30
- }
31
- return new ValRouterCore.ValOpsMemory(valModules, {
32
- formatter: options.formatter,
33
- config: options.config,
34
- sourceFiles: options.sourceFiles,
35
- patchStore: options.patchStore,
36
- unsafelyAllowUnauthenticated: options.unsafelyAllowUnauthenticated,
37
- // Nothing can reach a server in a tab but the page it runs in.
38
- warnUnauthenticated: false,
39
- contentUrl: options.valContentUrl
40
- });
41
- },
42
- probeUrl: async () => ({
43
- kind: "skipped",
44
- message: "Links are not checked in the browser."
45
- }),
46
- jwt: {
47
- verifyJwt: () => ({
48
- success: false,
49
- reason: "missing-secret",
50
- message: NO_SESSIONS
51
- }),
52
- decodeJwtWithoutVerifying: () => ({
53
- success: false,
54
- reason: "missing-secret",
55
- message: NO_SESSIONS
56
- }),
57
- encodeJwt: () => {
58
- throw new Error(NO_SESSIONS);
59
- },
60
- getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
61
- },
62
- bytesToBase64: ValRouterCore.bytesToBase64,
63
- readValLoginToken: async () => null,
64
- resolveRemoteFileAuth: async () => ({
65
- status: "error",
66
- errorCode: "api-key-missing",
67
- message: "Remote files are not available in the browser."
68
- })
69
- };
70
-
71
- /** A `fetch`, as far as the Studio's client calls one. */
72
-
73
- /**
74
- * Val's API, served in this tab: a `fetch` that never touches the network.
75
- *
76
- * The whole server -- the router's request parsing, `ValServer`'s routes,
77
- * memory mode's patch chain -- runs here, exactly as it runs on a server.
78
- * What is removed is the hop between them, and nothing else, which is why the
79
- * demo built on it cannot drift from the product: there is no second
80
- * implementation to drift. See `docs/plans/demo-mode.md`.
81
- *
82
- * Memory mode with no source files, because nothing here publishes (only a
83
- * publish reads `.val.ts` text), and without authentication, because the only
84
- * caller is the page this runs in.
85
- */
86
- function createInTabValFetch(valModules, options) {
87
- const route = options.route ?? "/api/val";
88
- const serverConfig = {
89
- mode: "memory",
90
- route,
91
- sourceFiles: {},
92
- patchStore: options.patchStore,
93
- unsafelyAllowUnauthenticated: true,
94
- valContentUrl: core.DEFAULT_CONTENT_HOST,
95
- config: options.config,
96
- ...(options.framework !== undefined ? {
97
- framework: options.framework
98
- } : {})
99
- };
100
- const server = ValRouterCore.ValServer(valModules, serverConfig, {
101
- // Draft content is the only content a demo has.
102
- isEnabled: async () => true,
103
- onEnable: async () => {},
104
- onDisable: async () => {}
105
- }, browserPlatform);
106
- const handle = ValRouterCore.createValRequestHandler(route, Promise.resolve(server), toResponse);
107
- return (input, init) => {
108
- const base = typeof window === "undefined" ? "http://localhost" : window.location.origin;
109
- // A `Request` already has an absolute URL, and `init` overrides what it
110
- // carries, as it does for `fetch`. Only a string or URL is resolved.
111
- return handle(input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), base).href, init));
112
- };
113
- }
114
15
 
115
- /**
116
- * The server's answer as a `Response`. The same conversion a host makes,
117
- * less the cookies: a `Response` made in the page cannot set one, and a server
118
- * that never authenticates has none to set.
119
- */
120
- function toResponse(valRes) {
121
- const headers = new Headers();
122
- const valResHeaders = "headers" in valRes && valRes.headers || {};
123
- for (const key in valResHeaders) {
124
- const value = valResHeaders[key];
125
- if (typeof value === "string") {
126
- headers.set(key, value);
127
- }
128
- }
129
- if ("json" in valRes) {
130
- headers.set("Content-Type", "application/json");
131
- return new Response(JSON.stringify(valRes.json), {
132
- headers,
133
- status: valRes.status
134
- });
135
- }
136
- if (valRes.status === 302) {
137
- headers.set("Location", valRes.redirectTo);
138
- return new Response(null, {
139
- status: valRes.status,
140
- headers
141
- });
142
- }
143
- return new Response("body" in valRes ? valRes.body : null, {
144
- headers,
145
- status: valRes.status
146
- });
147
- }
148
16
 
149
- exports.createInTabValFetch = createInTabValFetch;
17
+ exports.createInTabValFetch = inTabFetch.createInTabValFetch;
@@ -2,148 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var core = require('@valbuild/core');
6
- var ValRouterCore = require('../../dist/ValRouterCore-0c7ae881.cjs.prod.js');
7
- require('@valbuild/shared/internal');
5
+ var inTabFetch = require('../../dist/inTabFetch-095bb2be.cjs.prod.js');
6
+ require('@valbuild/core');
7
+ require('../../dist/ValRouterCore-a0ea46bf.cjs.prod.js');
8
8
  require('zod');
9
+ require('@valbuild/shared/internal');
9
10
  require('zod-validation-error');
10
11
  require('@valbuild/core/fp');
11
12
  require('@valbuild/core/patch');
12
13
  require('image-size');
13
14
 
14
- const NO_SESSIONS = "Val: sessions are not available here -- this server runs in the browser, " + "has no secret to sign them with, and serves without authenticating.";
15
-
16
- /**
17
- * The platform for a server running in a browser tab.
18
- *
19
- * Memory mode only: there is no filesystem for `fs` mode and no credential for
20
- * `http` mode. Everything else answers as a server without those things does
21
- * -- no `val login` token, no credential for remote files, no link checks --
22
- * and the session functions refuse, because a tab has no secret to sign with
23
- * and the server is constructed with `unsafelyAllowUnauthenticated`, so
24
- * nothing asks for one.
25
- */
26
- const browserPlatform = {
27
- createOps: (valModules, options) => {
28
- if (options.mode !== "memory") {
29
- throw new Error(`Val: a server in the browser runs in memory mode, not '${options.mode}'.`);
30
- }
31
- return new ValRouterCore.ValOpsMemory(valModules, {
32
- formatter: options.formatter,
33
- config: options.config,
34
- sourceFiles: options.sourceFiles,
35
- patchStore: options.patchStore,
36
- unsafelyAllowUnauthenticated: options.unsafelyAllowUnauthenticated,
37
- // Nothing can reach a server in a tab but the page it runs in.
38
- warnUnauthenticated: false,
39
- contentUrl: options.valContentUrl
40
- });
41
- },
42
- probeUrl: async () => ({
43
- kind: "skipped",
44
- message: "Links are not checked in the browser."
45
- }),
46
- jwt: {
47
- verifyJwt: () => ({
48
- success: false,
49
- reason: "missing-secret",
50
- message: NO_SESSIONS
51
- }),
52
- decodeJwtWithoutVerifying: () => ({
53
- success: false,
54
- reason: "missing-secret",
55
- message: NO_SESSIONS
56
- }),
57
- encodeJwt: () => {
58
- throw new Error(NO_SESSIONS);
59
- },
60
- getExpire: () => Math.floor(Date.now() / 1000) + 60 * 60
61
- },
62
- bytesToBase64: ValRouterCore.bytesToBase64,
63
- readValLoginToken: async () => null,
64
- resolveRemoteFileAuth: async () => ({
65
- status: "error",
66
- errorCode: "api-key-missing",
67
- message: "Remote files are not available in the browser."
68
- })
69
- };
70
-
71
- /** A `fetch`, as far as the Studio's client calls one. */
72
-
73
- /**
74
- * Val's API, served in this tab: a `fetch` that never touches the network.
75
- *
76
- * The whole server -- the router's request parsing, `ValServer`'s routes,
77
- * memory mode's patch chain -- runs here, exactly as it runs on a server.
78
- * What is removed is the hop between them, and nothing else, which is why the
79
- * demo built on it cannot drift from the product: there is no second
80
- * implementation to drift. See `docs/plans/demo-mode.md`.
81
- *
82
- * Memory mode with no source files, because nothing here publishes (only a
83
- * publish reads `.val.ts` text), and without authentication, because the only
84
- * caller is the page this runs in.
85
- */
86
- function createInTabValFetch(valModules, options) {
87
- const route = options.route ?? "/api/val";
88
- const serverConfig = {
89
- mode: "memory",
90
- route,
91
- sourceFiles: {},
92
- patchStore: options.patchStore,
93
- unsafelyAllowUnauthenticated: true,
94
- valContentUrl: core.DEFAULT_CONTENT_HOST,
95
- config: options.config,
96
- ...(options.framework !== undefined ? {
97
- framework: options.framework
98
- } : {})
99
- };
100
- const server = ValRouterCore.ValServer(valModules, serverConfig, {
101
- // Draft content is the only content a demo has.
102
- isEnabled: async () => true,
103
- onEnable: async () => {},
104
- onDisable: async () => {}
105
- }, browserPlatform);
106
- const handle = ValRouterCore.createValRequestHandler(route, Promise.resolve(server), toResponse);
107
- return (input, init) => {
108
- const base = typeof window === "undefined" ? "http://localhost" : window.location.origin;
109
- // A `Request` already has an absolute URL, and `init` overrides what it
110
- // carries, as it does for `fetch`. Only a string or URL is resolved.
111
- return handle(input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), base).href, init));
112
- };
113
- }
114
15
 
115
- /**
116
- * The server's answer as a `Response`. The same conversion a host makes,
117
- * less the cookies: a `Response` made in the page cannot set one, and a server
118
- * that never authenticates has none to set.
119
- */
120
- function toResponse(valRes) {
121
- const headers = new Headers();
122
- const valResHeaders = "headers" in valRes && valRes.headers || {};
123
- for (const key in valResHeaders) {
124
- const value = valResHeaders[key];
125
- if (typeof value === "string") {
126
- headers.set(key, value);
127
- }
128
- }
129
- if ("json" in valRes) {
130
- headers.set("Content-Type", "application/json");
131
- return new Response(JSON.stringify(valRes.json), {
132
- headers,
133
- status: valRes.status
134
- });
135
- }
136
- if (valRes.status === 302) {
137
- headers.set("Location", valRes.redirectTo);
138
- return new Response(null, {
139
- status: valRes.status,
140
- headers
141
- });
142
- }
143
- return new Response("body" in valRes ? valRes.body : null, {
144
- headers,
145
- status: valRes.status
146
- });
147
- }
148
16
 
149
- exports.createInTabValFetch = createInTabValFetch;
17
+ exports.createInTabValFetch = inTabFetch.createInTabValFetch;