@valbuild/server 0.150.22 → 0.151.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.
- package/CHANGELOG.md +326 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +5 -137
- package/browser/dist/valbuild-server-browser.cjs.prod.js +5 -137
- package/browser/dist/valbuild-server-browser.esm.js +4 -140
- package/dist/ValRouter-2827d620.esm.js +14489 -0
- package/dist/ValRouter-ca467c83.cjs.dev.js +14585 -0
- package/dist/ValRouter-d43e0a33.cjs.prod.js +14585 -0
- package/dist/{ValRouterCore-3431ce5f.cjs.dev.js → ValRouterCore-0921fe9c.cjs.dev.js} +3156 -1758
- package/dist/{ValRouterCore-c5f6885a.esm.js → ValRouterCore-6c29fb75.esm.js} +3147 -1753
- package/dist/{ValRouterCore-df3f99c6.cjs.prod.js → ValRouterCore-eb1f53f5.cjs.prod.js} +3156 -1758
- package/dist/declarations/src/ValOps.d.ts +314 -68
- package/dist/declarations/src/ValOpsFS.d.ts +32 -0
- package/dist/declarations/src/ValOpsHttp.d.ts +93 -3
- package/dist/declarations/src/ValOpsMemory.d.ts +22 -47
- package/dist/declarations/src/ValRouter.d.ts +10 -0
- package/dist/declarations/src/ValServer.d.ts +0 -10
- package/dist/declarations/src/browser/inTabFetch.d.ts +19 -2
- package/dist/declarations/src/draftOverlay.d.ts +51 -0
- package/dist/declarations/src/draftReads.d.ts +103 -0
- package/dist/declarations/src/head.d.ts +312 -0
- package/dist/declarations/src/history/getJsonEntryAtCommit.d.ts +52 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/internal/browser/index.d.ts +11 -0
- package/dist/declarations/src/internal/index.d.ts +15 -0
- package/dist/declarations/src/patch/jsonValuesPatch.d.ts +2 -165
- package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +38 -0
- package/dist/declarations/src/patch/ts/loadTypeScriptKit.d.ts +14 -0
- package/dist/declarations/src/patch/ts/ops.d.ts +45 -0
- package/dist/declarations/src/patch/ts/publishKit.d.ts +26 -0
- package/dist/declarations/src/platform.d.ts +14 -0
- package/dist/declarations/src/proposal.d.ts +54 -3
- package/dist/declarations/src/valRuntime.d.ts +35 -0
- package/dist/draftReads-05415ff6.cjs.dev.js +366 -0
- package/dist/draftReads-5f99edd3.esm.js +361 -0
- package/dist/draftReads-ea3946e0.cjs.prod.js +366 -0
- package/dist/inTabFetch-0cd45721.esm.js +176 -0
- package/dist/inTabFetch-35cf5698.cjs.prod.js +179 -0
- package/dist/inTabFetch-49db354b.cjs.dev.js +179 -0
- package/dist/{getJsonEntryAtCommit-b52171b1.cjs.prod.js → publishKit-24e1406b.cjs.prod.js} +55 -6
- package/dist/{getJsonEntryAtCommit-21a4bbfa.cjs.dev.js → publishKit-3afe011d.cjs.dev.js} +55 -6
- package/dist/{getJsonEntryAtCommit-93f9aba9.esm.js → publishKit-d2e3e44d.esm.js} +48 -5
- package/dist/valbuild-server.cjs.dev.js +160 -13319
- package/dist/valbuild-server.cjs.prod.js +160 -13319
- package/dist/valbuild-server.esm.js +34 -13174
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.d.ts +2 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +19 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.js +7 -0
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +19 -0
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +10 -0
- package/internal/browser/package.json +4 -0
- package/internal/dist/valbuild-server-internal.cjs.d.ts +2 -0
- package/internal/dist/valbuild-server-internal.cjs.dev.js +43 -0
- package/internal/dist/valbuild-server-internal.cjs.js +7 -0
- package/internal/dist/valbuild-server-internal.cjs.prod.js +43 -0
- package/internal/dist/valbuild-server-internal.esm.js +24 -0
- package/internal/package.json +4 -0
- package/package.json +17 -6
- package/dist/jsonValuesModule-235bd751.cjs.dev.js +0 -326
- package/dist/jsonValuesModule-23eb6f53.esm.js +0 -310
- package/dist/jsonValuesModule-625ebae8.cjs.prod.js +0 -326
- package/dist/ops-0e54b388.cjs.prod.js +0 -361
- package/dist/ops-9ca2ef2a.cjs.dev.js +0 -361
- package/dist/ops-b904007e.esm.js +0 -353
- package/dist/publishKit-34f71e50.cjs.dev.js +0 -42
- package/dist/publishKit-65e9e564.cjs.prod.js +0 -42
- package/dist/publishKit-7441c0fd.esm.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,331 @@
|
|
|
1
1
|
# @valbuild/server
|
|
2
2
|
|
|
3
|
+
## 0.151.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
mode used to make Val's server read every module, apply every pending
|
|
9
|
+
change, and preview and validate the whole project on every request -- and
|
|
10
|
+
then ask again for each `.jsonValues()` entry it showed. Now there is one
|
|
11
|
+
copy of the draft per process, made once per change and shared by every
|
|
12
|
+
editor and every request:
|
|
13
|
+
|
|
14
|
+
- A module nobody edited costs nothing: the page reads its own build, as a
|
|
15
|
+
visitor's does.
|
|
16
|
+
- A request asks one cheap question -- has anything changed? -- once, and
|
|
17
|
+
the draft is only re-read when it has. An edit is applied once, to the
|
|
18
|
+
version before it, however many pages read it afterwards.
|
|
19
|
+
- `fetchVal`, `fetchValKey`, `fetchValRoute`, `fetchValRouteUrl` and
|
|
20
|
+
`fetchValDraft` (Next.js and TanStack Start alike) and Val's API routes
|
|
21
|
+
read that one copy, so a save through the API is seen by every reader at
|
|
22
|
+
once. Before, each kept its own, and a publish moved only the copy of the
|
|
23
|
+
server that handled it: in a host that keeps its content in memory, a
|
|
24
|
+
draft page read through `fetchValKey` or `fetchValRoute` went on showing
|
|
25
|
+
the content from before the publish.
|
|
26
|
+
- The MCP tools (`initValMcp`) read the same copy in local development and
|
|
27
|
+
on Val's hosting, where Val's options come from your config and the
|
|
28
|
+
environment. `initValMcp` takes no patch store or source files of its
|
|
29
|
+
own, so in a host that keeps its content in memory it keeps a copy of its
|
|
30
|
+
own, as before.
|
|
31
|
+
- If `initValServer` and `initValContent` (or `initValRsc`) are given
|
|
32
|
+
different options for the same `val.modules` (a different patch store,
|
|
33
|
+
say), they keep separate copies, and Val logs a warning saying which
|
|
34
|
+
options differ.
|
|
35
|
+
|
|
36
|
+
On a site of 20 MB of content a draft read went from about half a second per
|
|
37
|
+
request to well under a millisecond once the draft is in memory, and the
|
|
38
|
+
memory it holds grows with what was edited rather than with the size of the
|
|
39
|
+
site. Hosted sites in proxy mode ask the content service one small question
|
|
40
|
+
per request instead of reading every pending change; with a content service
|
|
41
|
+
that predates it, Val reads the pending changes as before.
|
|
42
|
+
|
|
43
|
+
`ValDraft` (what `fetchValDraft` returns and `<ValProvider draft>` takes)
|
|
44
|
+
has a new optional `versions` field, filled in by the server: the page uses
|
|
45
|
+
it to tell that what the Studio sends is what it already shows, without
|
|
46
|
+
comparing the content. Nothing to change in your app.
|
|
47
|
+
|
|
48
|
+
**Changed:** `PUT /api/val/sources/~` no longer computes previews or
|
|
49
|
+
validates the content (the Studio does both itself, and `/api/val/validate`
|
|
50
|
+
checks a module on request); its `validate_sources` and
|
|
51
|
+
`validate_binary_files` flags are accepted and ignored.
|
|
52
|
+
|
|
53
|
+
**Deprecated, and removed in the next release.** These stay for one release
|
|
54
|
+
only so that a Studio, a page or a server of the previous release keeps
|
|
55
|
+
working while a deploy rolls out. Nothing in this release uses them; if
|
|
56
|
+
your own code calls any of them, move off it now:
|
|
57
|
+
|
|
58
|
+
- `PUT /api/val/sources/~`, the whole route. This release's Studio reads
|
|
59
|
+
`GET /api/val/manifest` and `GET /api/val/modules/~<path>`, and the draft
|
|
60
|
+
readers and MCP read in-process.
|
|
61
|
+
- The `source` field of the overlay's `source-update` event and the canvas's
|
|
62
|
+
`sourceUpdate` message, and a page's support for an event that carries
|
|
63
|
+
only `source` (this release sends `read` beside it).
|
|
64
|
+
- `ValDraft.base`: not sent and not read; the type stays one release so
|
|
65
|
+
code written against the previous one still compiles.
|
|
66
|
+
- `/api/val/stat`'s `sourcesSha` and `schemaSha`: the next release's Studio
|
|
67
|
+
stops depending on them, and the release after it stops sending them.
|
|
68
|
+
|
|
69
|
+
- [#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
|
|
70
|
+
runs) no longer carries the TypeScript compiler. Bundled into a single file,
|
|
71
|
+
as a Cloudflare Worker is, it goes from 12.9 MB to 2.0 MB (2.1 MB to 0.4 MB
|
|
72
|
+
gzipped). An app that splits its bundle into chunks, as Vite does, no longer
|
|
73
|
+
builds a 3.5 MB chunk that the demo never loaded.
|
|
74
|
+
|
|
75
|
+
Nothing changes for a server started with `createValServer`: it still
|
|
76
|
+
publishes and reads history as before.
|
|
77
|
+
|
|
78
|
+
If you construct `ValOpsMemory` yourself and publish through it, pass
|
|
79
|
+
`typescript: loadTypeScriptKit` (exported from `@valbuild/server`). Without
|
|
80
|
+
it, a publish is refused with an error that says so, and nothing is lost:
|
|
81
|
+
the changes stay pending.
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- [#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
|
|
86
|
+
(`val/p/<name>`), Commit and Publish no longer leave you stuck. Instead of
|
|
87
|
+
committing over a push it has not seen, the Studio says who pushed and when,
|
|
88
|
+
links to their commit, and offers **Build on their push**:
|
|
89
|
+
|
|
90
|
+
- Their changes come into the proposal. Where you both changed the same file,
|
|
91
|
+
the proposal's version is kept, and the Studio lists those files. Anything
|
|
92
|
+
a proposal cannot hold (for example a change outside the project) is listed
|
|
93
|
+
too, since the next Commit leaves it as the site has it.
|
|
94
|
+
- Anything waiting to be saved is saved first, so "the proposal's version" is
|
|
95
|
+
what you see.
|
|
96
|
+
- The proposal's preview is rebuilt with their code. Commit goes through
|
|
97
|
+
right away, on top of their commit; Publish waits for the rebuild and says
|
|
98
|
+
so.
|
|
99
|
+
- If they push again in the meantime, the notice moves to their newer commit.
|
|
100
|
+
If GitHub cannot be reached, the session ran out, or the project's plan
|
|
101
|
+
does not allow changes, it offers Try again, Sign in or Billing. When
|
|
102
|
+
nothing can help from here (their push is too large to bring in, say), it
|
|
103
|
+
says so and offers only their commit.
|
|
104
|
+
|
|
105
|
+
Publish refused the same way now shows the same notice inside the Publish
|
|
106
|
+
dialog, rather than a Try again that would fail again. When GitHub refuses
|
|
107
|
+
Publish's commit for good (a protected branch), the dialog links the branch
|
|
108
|
+
instead of offering Try again. On a phone, where Publish is finished in a new
|
|
109
|
+
tab, the commit message you typed now goes with it, and a refusal there
|
|
110
|
+
comes back to the dialog with the same offer.
|
|
111
|
+
|
|
112
|
+
Publish pressed from the design tab, on the site, is refused the same way
|
|
113
|
+
when someone has pushed to the proposal's branch. Build on their push can
|
|
114
|
+
only be done in the proposal's own Studio, so the dialog says who pushed and
|
|
115
|
+
when, links their commit, and offers **Open the proposal**, where Publish
|
|
116
|
+
offers Build on their push. It no longer offers a Try again that would fail
|
|
117
|
+
again, and a branch GitHub refuses for good links the branch there too.
|
|
118
|
+
|
|
119
|
+
- [#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
|
|
120
|
+
proposal's name turns code mode on for everyone in it, and the assistant can
|
|
121
|
+
then change the proposal's code. On the site, the `</>` lists the open
|
|
122
|
+
proposals and opens the one you choose with code mode on.
|
|
123
|
+
|
|
124
|
+
- **Nothing you typed is lost when code changes.** Turning code mode on saves
|
|
125
|
+
every pending change first, and so does each of the assistant's code
|
|
126
|
+
changes, so a field the assistant adds can be filled in and stays filled
|
|
127
|
+
in. Turning code mode off discards nothing.
|
|
128
|
+
- **Each person chooses what they see.** While code mode is on you can stay
|
|
129
|
+
in the content editor, or see the proposal's preview and its code changes.
|
|
130
|
+
The proposal's menu says who turned code mode on, and when.
|
|
131
|
+
- **The assistant asks.** With code mode off, its code tools refuse and say
|
|
132
|
+
who turned it off; it asks for code mode with a button in the chat instead.
|
|
133
|
+
- **Save is the one main button** in a proposal, and also updates the
|
|
134
|
+
preview when the code changed. Its menu holds **Commit**, in a project
|
|
135
|
+
connected to git, which puts the proposal on its git branch as one commit,
|
|
136
|
+
and **Publish**, which commits and then merges into the site. Both use the
|
|
137
|
+
project's commit message setting. In code mode, Save saves even when
|
|
138
|
+
content has validation errors; Publish is still refused until they are
|
|
139
|
+
fixed. If someone else pushed to the proposal's branch, Commit says who and
|
|
140
|
+
when, and links to their commit, instead of committing over it.
|
|
141
|
+
- The "schema changed, reload" dialog is not shown in code mode, where the
|
|
142
|
+
schema changes with every build.
|
|
143
|
+
|
|
144
|
+
- [#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
|
|
145
|
+
is open. They read the site's code once and kept that copy for as long as the
|
|
146
|
+
page was open, so a file published in the meantime was shown as it was before.
|
|
147
|
+
They now ask on every call, and the content service answers "unchanged" without
|
|
148
|
+
sending the code again unless it did change.
|
|
149
|
+
|
|
150
|
+
- [#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.**
|
|
151
|
+
|
|
152
|
+
- **Pending edits to an entry.** In draft mode, `fetchVal` of a whole
|
|
153
|
+
`.jsonValues()` record now shows the unpublished edits to its entries. It
|
|
154
|
+
used to show the published content of every entry, even one an editor had
|
|
155
|
+
just changed, while `fetchValKey` and `fetchValRoute` of the same entry
|
|
156
|
+
showed the edit. The entries a pending change touches are read from Val's
|
|
157
|
+
server; the others are loaded from your build, as before.
|
|
158
|
+
- **Entries published without a rebuild.** On a host that does not rebuild
|
|
159
|
+
the site after a publish, a draft page now shows the published entries
|
|
160
|
+
straight away -- in `fetchVal`, and in `useVal`, `useValKey` and
|
|
161
|
+
`useValRoute` alike. They used to show those entries as they were before
|
|
162
|
+
the publish, from the site's build, until it was rebuilt (and on TanStack
|
|
163
|
+
Start the server render showed the new content, then the page switched
|
|
164
|
+
back to the old). Val's server marks each entry a publish wrote, and the
|
|
165
|
+
readers and the Studio load a marked entry from the server.
|
|
166
|
+
|
|
167
|
+
- [#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
|
|
168
|
+
while the site is deployed no longer stops you with a dialog you can only
|
|
169
|
+
answer by reloading. Instead:
|
|
170
|
+
|
|
171
|
+
- **On Val's hosting**, the Studio takes the new build's fields in where you
|
|
172
|
+
are, without reloading: a field the deploy added can be filled in at once,
|
|
173
|
+
and the assistant's chat, the page you were on and your unsaved edits stay
|
|
174
|
+
as they were. Each build now carries its content schemas as a small file of
|
|
175
|
+
its own beside its scripts, which the Studio loads.
|
|
176
|
+
- **Anywhere else** (a Next.js site, or a TanStack Start site hosted
|
|
177
|
+
somewhere else), the Studio reloads itself a few seconds after the deploy,
|
|
178
|
+
once everything you typed has been saved. Nothing is lost: where you were is
|
|
179
|
+
in the address, and every edit is on the server.
|
|
180
|
+
- **In local development** nothing changes: your dev server's hot reload
|
|
181
|
+
brings the new fields, as before.
|
|
182
|
+
|
|
183
|
+
When a deploy upgrades Val itself, the Studio reloads itself the same way,
|
|
184
|
+
since its own code changed too.
|
|
185
|
+
|
|
186
|
+
- [#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
|
|
187
|
+
them, and a few cases that showed something different from what Publish would
|
|
188
|
+
save are fixed:
|
|
189
|
+
|
|
190
|
+
- A field you emptied to `null`, `""`, `0` or `false` no longer jumps back to
|
|
191
|
+
its published value at your next edit.
|
|
192
|
+
- When an edit cannot be applied, later edits to `.jsonValues()` entries stop
|
|
193
|
+
there too, instead of showing an entry the page will never get.
|
|
194
|
+
- An image or file added to a `.jsonValues()` entry no longer fails the whole
|
|
195
|
+
entry when the upload comes before the field in the edit.
|
|
196
|
+
- Clearing a nullable `.jsonValues()` record removes its entries from drafts
|
|
197
|
+
as well.
|
|
198
|
+
|
|
199
|
+
Long chains of unpublished edits are also much faster to read: a draft with
|
|
200
|
+
650 edits went from about 580 ms to about 110 ms.
|
|
201
|
+
|
|
202
|
+
- [#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
|
|
203
|
+
of on a timer.
|
|
204
|
+
|
|
205
|
+
- **The page settles faster, and without the 10 second fallback.** Content your
|
|
206
|
+
page reads on the server (a TanStack Start loader, a Next.js server component)
|
|
207
|
+
is refreshed when the editor's change has been saved, once per saved change.
|
|
208
|
+
It used to be refreshed the moment you typed — before the change was saved,
|
|
209
|
+
so the refresh often came back without it — and then again every 10 seconds
|
|
210
|
+
for half a minute in case it had. That safety refresh is gone, and so are the
|
|
211
|
+
extra requests it made while you edited. Another editor's change refreshes
|
|
212
|
+
the page too, once the server has it. While a deploy rolls out, a Studio of
|
|
213
|
+
the previous release (which never says it has saved) still refreshes the
|
|
214
|
+
page as each change arrives, as before.
|
|
215
|
+
- **Next.js: `ValProvider` takes an optional `draft` prop**, as
|
|
216
|
+
`@valbuild/tanstack`'s does: the editor's draft, read on the server for the
|
|
217
|
+
request. With it, the server renders the draft and the browser hydrates the
|
|
218
|
+
same thing, so a draft page no longer shows the published text first, and a
|
|
219
|
+
page that exists only as an unpublished change is found on the first render
|
|
220
|
+
instead of answering 404. Without it, nothing changes. See "The `draft` prop"
|
|
221
|
+
in the `@valbuild/next` README.
|
|
222
|
+
- **Next.js: `initValRsc` returns `fetchValDraft`**, which reads that draft:
|
|
223
|
+
pass `draft={await fetchValDraft()}` to `ValProvider` in your root layout. It
|
|
224
|
+
returns `null` unless the request is in draft mode, after one `draftMode()`
|
|
225
|
+
lookup and no other work, so visitors pay nothing and a static page stays
|
|
226
|
+
static. It reads the draft the way `@valbuild/tanstack/server`'s
|
|
227
|
+
`fetchValDraft` does and returns the same type, `ValDraft | null`, which
|
|
228
|
+
is now exported from `@valbuild/next` and `@valbuild/next/rsc` too.
|
|
229
|
+
- **`suspend` waits for the editor's changes properly.** With `suspend` on
|
|
230
|
+
`ValProvider`, a page could be told it had everything before the editor had
|
|
231
|
+
sent the pending change it needed, and render the published content first —
|
|
232
|
+
for a page that exists only as an unpublished change, a 404. It now waits
|
|
233
|
+
until the change is there.
|
|
234
|
+
- A draft page whose draft was discarded or published before the editor's
|
|
235
|
+
overlay or canvas connected now shows what the editor has, instead of keeping
|
|
236
|
+
the draft it was rendered with -- an edit inside a `.jsonValues()` entry
|
|
237
|
+
included.
|
|
238
|
+
- Turning draft mode on or off refreshes the page once. In development (React's
|
|
239
|
+
`StrictMode`) it could refresh twice, and Next.js could log "Cannot call
|
|
240
|
+
startTransition while rendering" while the page refreshed.
|
|
241
|
+
|
|
242
|
+
- [#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
|
|
243
|
+
precondition: "only apply this patch if the value at this path is still
|
|
244
|
+
this". Val used to accept every `test` op without checking it, so a patch
|
|
245
|
+
that should have been refused was applied anyway.
|
|
246
|
+
|
|
247
|
+
Now a `test` op fails its patch when the path does not exist, or when the
|
|
248
|
+
value there is not deeply equal to the one given (objects and arrays are
|
|
249
|
+
compared all the way down, and `0`, `""`, `false` and `null` are all
|
|
250
|
+
different from each other). The ops after it are not applied. This holds in
|
|
251
|
+
every place Val applies a patch -- the Studio's drafts, a draft page, the
|
|
252
|
+
content tools for MCP, and Publish -- so a patch a draft shows is a patch
|
|
253
|
+
Publish accepts.
|
|
254
|
+
|
|
255
|
+
Nothing in the Studio, the CLI or the content tools writes `test` ops of
|
|
256
|
+
its own, so this only changes anything for a patch you, or an agent through
|
|
257
|
+
the MCP `create_patch` tool, wrote with a `test` op in it: one whose test
|
|
258
|
+
does not hold is now refused with `Test failed` (or, for a path that does
|
|
259
|
+
not exist, `Path refers to non-existing object/array`) instead of applied.
|
|
260
|
+
|
|
261
|
+
- [#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`,
|
|
262
|
+
`useVal`, the key and route readers, on the server and in the browser — now
|
|
263
|
+
loads content the same way, so they can no longer disagree about which content
|
|
264
|
+
wins. Nothing you call changes. What you may notice:
|
|
265
|
+
|
|
266
|
+
- `useValRoute` on a `.jsonValues()` router loads only the entry for the
|
|
267
|
+
current route. It used to load every entry of the record first.
|
|
268
|
+
`useValRouteUrl` and `fetchValRouteUrl` load none at all: a URL does not need
|
|
269
|
+
them.
|
|
270
|
+
- In development, an edited `*.val.json` entry shows its new content after a
|
|
271
|
+
hot reload. The hooks kept the entry they had loaded before it.
|
|
272
|
+
- Next.js: `useValKey` no longer shows the published entry of a nullable
|
|
273
|
+
`.jsonValues()` record that a draft has set to `null`, nor anything for an
|
|
274
|
+
entry named like a built-in object property (such as `toString`) that the
|
|
275
|
+
draft does not have.
|
|
276
|
+
- With `suspend` on `ValProvider`, `useValKey` now waits for draft mode and the
|
|
277
|
+
editor's changes too, as `useVal` and `useValRoute` already did.
|
|
278
|
+
- When one entry of a `.jsonValues()` record cannot be loaded, `useVal` logs
|
|
279
|
+
the error and renders the others, as `fetchVal` already did, instead of
|
|
280
|
+
failing the whole component.
|
|
281
|
+
|
|
282
|
+
- [#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
|
|
283
|
+
saved with the assistant's next change, without waiting for the proposal to be
|
|
284
|
+
built.
|
|
285
|
+
|
|
286
|
+
The Studio already let you type into a field that only the assistant's staged
|
|
287
|
+
code has. But the save that runs before the assistant's next change applied
|
|
288
|
+
your edit to the content as the proposal's last build had it -- without the new
|
|
289
|
+
field -- so it failed, and the assistant's next change was refused ("the
|
|
290
|
+
changes waiting to be saved could not be saved first") until someone pressed
|
|
291
|
+
Build.
|
|
292
|
+
|
|
293
|
+
Val's server at the proposal's address now learns which staged code the build
|
|
294
|
+
it runs was made of (the platform hands it over beside the build), and saves a
|
|
295
|
+
module whose code was staged after that build from the staged `.val.ts` itself.
|
|
296
|
+
A page at the address keeps reading such a module as its build has it until a
|
|
297
|
+
build of the new code serves it, so it never shows content made for code it
|
|
298
|
+
does not have.
|
|
299
|
+
|
|
300
|
+
When the server cannot read a staged module's content without running it --
|
|
301
|
+
its content is built by code, or it is a `.jsonValues()` record -- the edit is
|
|
302
|
+
kept, and the assistant's change is refused saying the proposal has to be built
|
|
303
|
+
first, rather than failing with no reason.
|
|
304
|
+
|
|
305
|
+
`@valbuild/tanstack-build` rewrites the proposal block of a `val.server.ts`
|
|
306
|
+
generated before this, so a site picks it up at its next build.
|
|
307
|
+
|
|
308
|
+
- [#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.
|
|
309
|
+
|
|
310
|
+
- **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.
|
|
311
|
+
- **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.
|
|
312
|
+
- **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.
|
|
313
|
+
- **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.
|
|
314
|
+
- **When the editor opens on a page that already shows your changes,** the Studio no longer sends them to the page again.
|
|
315
|
+
|
|
316
|
+
- [#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.
|
|
317
|
+
- 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)]:
|
|
318
|
+
- @valbuild/ui@0.151.0
|
|
319
|
+
- @valbuild/shared@0.151.0
|
|
320
|
+
- @valbuild/core@0.151.0
|
|
321
|
+
|
|
322
|
+
## 0.150.23
|
|
323
|
+
|
|
324
|
+
### Patch Changes
|
|
325
|
+
|
|
326
|
+
- Updated dependencies [[`41b73af`](https://github.com/valbuild/val/commit/41b73af5db02ec2fef3f8b3884be453712d9ada3), [`e46c34a`](https://github.com/valbuild/val/commit/e46c34a7eb6080e2286a85cc70f1e98d3989b8a9), [`1970507`](https://github.com/valbuild/val/commit/19705071884f8dddabd0a1319a8a4bdb4b9cdfed)]:
|
|
327
|
+
- @valbuild/ui@0.150.23
|
|
328
|
+
|
|
3
329
|
## 0.150.22
|
|
4
330
|
|
|
5
331
|
### Patch Changes
|
|
@@ -2,148 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
require('
|
|
5
|
+
var inTabFetch = require('../../dist/inTabFetch-49db354b.cjs.dev.js');
|
|
6
|
+
require('@valbuild/core');
|
|
7
|
+
require('../../dist/ValRouterCore-0921fe9c.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
|
|
6
|
-
|
|
7
|
-
require('
|
|
5
|
+
var inTabFetch = require('../../dist/inTabFetch-35cf5698.cjs.prod.js');
|
|
6
|
+
require('@valbuild/core');
|
|
7
|
+
require('../../dist/ValRouterCore-eb1f53f5.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;
|