@valbuild/shared 0.146.4 → 0.148.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 CHANGED
@@ -1,5 +1,133 @@
1
1
  # @valbuild/shared
2
2
 
3
+ ## 0.148.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#818](https://github.com/valbuild/val/pull/818) [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1) Thanks [@freekh](https://github.com/freekh)! - Remote files are now addressed on the host the project's settings name. For a
8
+ project hosted by Val, that is the project's own address, and its remote images
9
+ and files are served from there rather than from `remote.val.build`. Every other
10
+ project is unchanged.
11
+
12
+ - The Studio, `val validate --fix` and the MCP image tool all take the host from
13
+ the project's settings, falling back to `remote.val.build` as before.
14
+ - Re-reading a remote file whose recorded size or type is out of date keeps it
15
+ on the host it was on.
16
+ - When a remote file's host cannot be reached, tooling downloads it from the
17
+ project's permanent `<id>.valstart.dev` address instead, and keeps it only if
18
+ its bytes match the file the address names.
19
+
20
+ - [#818](https://github.com/valbuild/val/pull/818) [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1) Thanks [@freekh](https://github.com/freekh)! - Remote files served from a project's own site (addresses like
21
+ `https://www.acme.no/_val/file/…`) are now checked for whether that address
22
+ still serves the project. When a custom domain has been removed or moved to
23
+ another project, the image or file is reported, and **Fix** on the Studio's
24
+ Validate page — or `val validate --fix` — points it at the project's permanent
25
+ `<id>.valstart.dev` address. Nothing is uploaded or downloaded: only the address
26
+ changes.
27
+
28
+ Remote file addresses with a `/_val` prefix after the host are now recognised.
29
+
30
+ - [#818](https://github.com/valbuild/val/pull/818) [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1) Thanks [@freekh](https://github.com/freekh)! - Fix existing remote images in rich text being saved as `/publichttps://…`.
31
+
32
+ Editing a rich text field could rewrite every remote image already in it into a
33
+ broken path when the field was not set up to upload remote images itself — for
34
+ example before the project's remote file settings had loaded, or when the
35
+ field's image schema is not `.remote()`. A published remote image is now kept
36
+ as it is, whatever host it is on.
37
+
38
+ - [#818](https://github.com/valbuild/val/pull/818) [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1) Thanks [@freekh](https://github.com/freekh)! - **Check everything** on the Studio's Validate page now checks media directories
39
+ (`s.imagedir()`, `s.filedir()`, `s.fontdir()` and `s.videodir()`) by the files
40
+ they list:
41
+
42
+ - An entry whose file is gone has a **Fix** that removes it from the directory.
43
+ - An image or file entry whose recorded size or type does not match its file has
44
+ a **Fix** that corrects it from the file, keeping its alt text.
45
+ - A video entry whose file is gone is reported, and is removed by hand: its
46
+ posters and captions may still be in use.
47
+ - A remote entry is checked with its host, like any remote file.
48
+
49
+ `val validate --fix` fixes media directories exactly as before.
50
+
51
+ - [#818](https://github.com/valbuild/val/pull/818) [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1) Thanks [@freekh](https://github.com/freekh)! - **Check everything** on the Studio's Validate page now checks remote images and
52
+ files too.
53
+
54
+ - A remote image or file whose address no longer matches what is recorded about
55
+ it (its size, type or the schema's options changed since it was uploaded) has
56
+ a **Fix**, which re-reads the file and corrects it, as `val validate --fix`
57
+ does.
58
+ - A remote host that does not answer is shown once, at the top of the page, with
59
+ how many files it holds and a **Try again**, rather than as an error on every
60
+ image.
61
+ - A file its host no longer has is shown at the image or file that uses it.
62
+
63
+ Images and files in your unpublished changes are not asked about until they are
64
+ published; the check makes sure the change still has them.
65
+
66
+ - [#818](https://github.com/valbuild/val/pull/818) [`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1) Thanks [@freekh](https://github.com/freekh)! - Two new Studio API routes for the full content check, not yet used by the
67
+ Studio's UI:
68
+
69
+ - `POST /api/val/validate` checks one module — its content against its schema,
70
+ and its local images and files against their bytes — on the content the
71
+ Studio is showing.
72
+ - `POST /api/val/validate/fix` returns the patch that fixes one of those errors,
73
+ for the Studio to add as a pending change. It builds only the fixes that need
74
+ no disk or remote host: image, file and video metadata, and a view pointing at
75
+ the wrong module.
76
+
77
+ Also fixed: an API route whose name started with another route's name could be
78
+ answered by the other route.
79
+
80
+ - Updated dependencies [[`562d032`](https://github.com/valbuild/val/commit/562d03280c3fcf97a80562e8b017dd2125ac4ad1)]:
81
+ - @valbuild/core@0.148.0
82
+
83
+ ## 0.147.0
84
+
85
+ ### Minor Changes
86
+
87
+ - [#816](https://github.com/valbuild/val/pull/816) [`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b) Thanks [@freekh](https://github.com/freekh)! - Routers can give each route parameter a schema, and a URL can say which language a page is in.
88
+
89
+ - **`s.router(router, params, item)`** takes a schema per route parameter, by the name the route file gives it (`$slug`, `[slug]`, `{-$locale}`). Each key's parameters are validated against them, and a name the route does not have is a schema error.
90
+
91
+ ```ts
92
+ s.router(tanstackRouter, { locale: urlLocale, slug: s.string() }, item);
93
+ ```
94
+
95
+ - **`s.enum(...).locales({ ... })`** says which of the project's languages each value means, so `/nb/…` can mean `nb-NO`. The tags are checked against `locales.available` in the settings module, like `s.locale()`. On a nullable enum, a second argument names the language of a URL that leaves the segment out, which only a router parameter may use:
96
+
97
+ ```ts
98
+ const urlLocale = s
99
+ .enum("nb")
100
+ .nullable()
101
+ .locales({ nb: "nb-NO" }, { null: "en-US" });
102
+ ```
103
+
104
+ A router with a locale parameter makes each page a locale scope, so the Studio and validation know which language every page is in.
105
+
106
+ - **A route's language segment can no longer be forgotten.** In a project that declares `locales.available`, a page route with a `locale` or `lang` segment (`{-$locale}`, `[lang]`) whose module gives that parameter no schema is reported, saying what to add. Any schema answers it, so a `$lang` that is not a language is silenced with its own, e.g. `{ lang: s.enum("typescript", "python") }`. It is an ordinary validation error: the Studio still opens and `val validate` lists it, but a project that already has such a route will see it after upgrading, and it blocks publishing until the parameter has a schema.
107
+ - **The Studio's new-page form offers a language as a list.** A route parameter whose schema is a locale is picked from the project's languages, each named in its own language, with "no prefix" where the URL may leave the segment out. Other enum parameters get a list of their values, and every parameter's description is shown under it. The URL row previews what the choice puts there.
108
+ - **TanStack optional segments (`{-$param}`)** are now understood: route validation, `useValRoute` and the Studio's new-page form accept keys with and without the segment.
109
+
110
+ - [#876](https://github.com/valbuild/val/pull/876) [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd) Thanks [@freekh](https://github.com/freekh)! - Demo mode: run the Val Studio with no account and no backend (TanStack Start).
111
+
112
+ `<ValApp demo>` starts Val's own server in the visitor's browser tab, and the Studio talks to it there instead of to `/api/val`. Edits show up in the page as they are typed and are held in the tab's memory: nothing is sent anywhere, and a reload starts over. Images and videos can be uploaded too: a small service worker, served by `initValDemoServer()`, hands the upload and the unpublished files to the server in the tab, so an uploaded photo or video shows in the page with nothing leaving the browser. Uploads are capped by their size after encoding. Pair `<ValApp demo>` with `<ValProvider demo>` on the site and `initValDemoServer()` from the new `@valbuild/tanstack/demo` entry on the API route. In a demo the Studio opens with a guided tour, Publish explains what it would do instead of publishing, and Preview in a new tab is shown but disabled.
113
+
114
+ Also:
115
+
116
+ - `@valbuild/server/browser` is a new entry: Val's request handling, bundleable for a browser. The TypeScript compiler, which only publishing and history need, is loaded when they ask for it, so a browser bundle of the server is about 140 KB rather than 3.6 MB.
117
+ - `s.image({ encode })` now scales an image down in browsers that cannot write WebP (Safari), as a JPEG or PNG in the image's own format, instead of uploading it at full size.
118
+ - `GET /profiles` answers with no profiles, rather than an error, when edits are stored locally and no project is configured.
119
+
120
+ ### Patch Changes
121
+
122
+ - [#876](https://github.com/valbuild/val/pull/876) [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd) Thanks [@freekh](https://github.com/freekh)! - `s.image({ encode: { type: "webp" } })` now produces WebP in Safari too, including on iPhone and iPad.
123
+
124
+ Safari's canvas cannot write WebP, so the Studio used to fall back to a JPEG (or a PNG) there, or to the original file when `accept` allowed only WebP. Now it encodes those images with libwebp, compiled to WebAssembly, at the same quality and size as everywhere else. The encoder is downloaded only by a browser that needs it, once per page, from `content.val.build`, the same place the Studio's bundler is served from. Browsers that can already write WebP never download it. If it cannot be loaded, uploads still work: the image is scaled down as a JPEG or PNG as before, or the original is uploaded.
125
+
126
+ A deployment that cannot reach `content.val.build` can serve the encoder itself and point the Studio at it with `globalThis.__VAL_WEBP_SIMD_WASM_URL__` and `globalThis.__VAL_WEBP_WASM_URL__`, the same way `__VAL_ROLLDOWN_WASM_URL__` works for the bundler.
127
+
128
+ - Updated dependencies [[`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b)]:
129
+ - @valbuild/core@0.147.0
130
+
3
131
  ## 0.146.4
4
132
 
5
133
  ### Patch Changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var getSitemapTree = require('../../dist/getSitemapTree-95b00d3f.cjs.dev.js');
5
+ var getSitemapTree = require('../../dist/getSitemapTree-f6254b32.cjs.dev.js');
6
6
  require('@valbuild/core');
7
7
 
8
8
 
@@ -14,6 +14,7 @@ exports.VAL_CANVAS_MESSAGE = getSitemapTree.VAL_CANVAS_MESSAGE;
14
14
  exports.VAL_CANVAS_PARAM = getSitemapTree.VAL_CANVAS_PARAM;
15
15
  exports.VAL_CONFIG_SESSION_STORAGE_KEY = getSitemapTree.VAL_CONFIG_SESSION_STORAGE_KEY;
16
16
  exports.VAL_THEME_SESSION_STORAGE_KEY = getSitemapTree.VAL_THEME_SESSION_STORAGE_KEY;
17
+ exports.formatRoutePattern = getSitemapTree.formatRoutePattern;
17
18
  exports.getNextAppRouterSourceFolder = getSitemapTree.getNextAppRouterSourceFolder;
18
19
  exports.getPageRouterSitemapTree = getSitemapTree.getPageRouterSitemapTree;
19
20
  exports.getPageRouterSourceFolder = getSitemapTree.getPageRouterSourceFolder;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var getSitemapTree = require('../../dist/getSitemapTree-b8dce0e2.cjs.prod.js');
5
+ var getSitemapTree = require('../../dist/getSitemapTree-109be3b8.cjs.prod.js');
6
6
  require('@valbuild/core');
7
7
 
8
8
 
@@ -14,6 +14,7 @@ exports.VAL_CANVAS_MESSAGE = getSitemapTree.VAL_CANVAS_MESSAGE;
14
14
  exports.VAL_CANVAS_PARAM = getSitemapTree.VAL_CANVAS_PARAM;
15
15
  exports.VAL_CONFIG_SESSION_STORAGE_KEY = getSitemapTree.VAL_CONFIG_SESSION_STORAGE_KEY;
16
16
  exports.VAL_THEME_SESSION_STORAGE_KEY = getSitemapTree.VAL_THEME_SESSION_STORAGE_KEY;
17
+ exports.formatRoutePattern = getSitemapTree.formatRoutePattern;
17
18
  exports.getNextAppRouterSourceFolder = getSitemapTree.getNextAppRouterSourceFolder;
18
19
  exports.getPageRouterSitemapTree = getSitemapTree.getPageRouterSitemapTree;
19
20
  exports.getPageRouterSourceFolder = getSitemapTree.getPageRouterSourceFolder;
@@ -1,2 +1,2 @@
1
- export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, h as getNextAppRouterSourceFolder, m as getPageRouterSitemapTree, k as getPageRouterSourceFolder, n as getPatternFromModuleFilePath, j as getTanStackRouterSourceFolder, l as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, p as parseRoutePattern, w as withValCanvasParam } from '../../dist/getSitemapTree-e65acefe.esm.js';
1
+ export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, h as formatRoutePattern, j as getNextAppRouterSourceFolder, n as getPageRouterSitemapTree, l as getPageRouterSourceFolder, o as getPatternFromModuleFilePath, k as getTanStackRouterSourceFolder, m as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, p as parseRoutePattern, w as withValCanvasParam } from '../../dist/getSitemapTree-c70ea145.esm.js';
2
2
  import '@valbuild/core';
@@ -328,6 +328,7 @@ export declare const Api: {
328
328
  remoteFileBuckets: z.ZodArray<z.ZodObject<{
329
329
  bucket: z.ZodString;
330
330
  }, z.core.$strip>>;
331
+ remoteHost: z.ZodOptional<z.ZodString>;
331
332
  }, z.core.$strip>;
332
333
  }, z.core.$strip>, z.ZodObject<{
333
334
  status: z.ZodLiteral<400>;
@@ -1024,6 +1025,153 @@ export declare const Api: {
1024
1025
  }, z.core.$strip>]>;
1025
1026
  };
1026
1027
  };
1028
+ /**
1029
+ * The Studio's full check, one module per request: its sources against its
1030
+ * schema and its local files against their bytes, on the content the caller
1031
+ * is looking at. See `docs/plans/studio-validate.md`.
1032
+ */
1033
+ "/validate": {
1034
+ POST: {
1035
+ req: {
1036
+ body: z.ZodObject<{
1037
+ moduleFilePath: z.ZodString & z.ZodType<ModuleFilePath, string, z.core.$ZodTypeInternals<ModuleFilePath, string>>;
1038
+ patchIds: z.ZodOptional<z.ZodArray<z.ZodString & z.ZodType<PatchIdT, string, z.core.$ZodTypeInternals<PatchIdT, string>>>>;
1039
+ }, z.core.$strip>;
1040
+ cookies: {
1041
+ val_session: z.ZodOptional<z.ZodString>;
1042
+ };
1043
+ };
1044
+ res: z.ZodUnion<readonly [z.ZodObject<{
1045
+ status: z.ZodLiteral<401>;
1046
+ json: z.ZodObject<{
1047
+ message: z.ZodString;
1048
+ }, z.core.$strip>;
1049
+ }, z.core.$strip>, z.ZodObject<{
1050
+ status: z.ZodLiteral<404>;
1051
+ json: z.ZodObject<{
1052
+ message: z.ZodString;
1053
+ }, z.core.$strip>;
1054
+ }, z.core.$strip>, z.ZodObject<{
1055
+ status: z.ZodLiteral<500>;
1056
+ json: z.ZodObject<{
1057
+ message: z.ZodString;
1058
+ }, z.core.$strip>;
1059
+ }, z.core.$strip>, z.ZodObject<{
1060
+ status: z.ZodLiteral<501>;
1061
+ json: z.ZodObject<{
1062
+ message: z.ZodString;
1063
+ }, z.core.$strip>;
1064
+ }, z.core.$strip>, z.ZodObject<{
1065
+ status: z.ZodLiteral<200>;
1066
+ json: z.ZodObject<{
1067
+ moduleFilePath: z.ZodString & z.ZodType<ModuleFilePath, string, z.core.$ZodTypeInternals<ModuleFilePath, string>>;
1068
+ errors: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
1069
+ message: z.ZodString;
1070
+ value: z.ZodOptional<z.ZodUnknown>;
1071
+ fatal: z.ZodOptional<z.ZodBoolean>;
1072
+ fixes: z.ZodOptional<z.ZodArray<z.ZodType<ValidationFix, unknown, z.core.$ZodTypeInternals<ValidationFix, unknown>>>>;
1073
+ }, z.core.$strip>>>;
1074
+ invalidSource: z.ZodOptional<z.ZodString>;
1075
+ remoteHosts: z.ZodOptional<z.ZodArray<z.ZodObject<{
1076
+ host: z.ZodString;
1077
+ status: z.ZodUnion<readonly [z.ZodLiteral<"missing">, z.ZodLiteral<"unreachable">]>;
1078
+ details: z.ZodString;
1079
+ sourcePaths: z.ZodArray<z.ZodType<SourcePathT, unknown, z.core.$ZodTypeInternals<SourcePathT, unknown>>>;
1080
+ }, z.core.$strip>>>;
1081
+ }, z.core.$strip>;
1082
+ }, z.core.$strip>]>;
1083
+ };
1084
+ };
1085
+ /**
1086
+ * The patch that fixes one error the full check reported. The server finds
1087
+ * the error again rather than trusting the caller's copy, and builds only the
1088
+ * fixes `STUDIO_FIXES` lists. The patch is returned, not applied: the Studio
1089
+ * adds it as a pending change like any edit.
1090
+ */
1091
+ "/validate/fix": {
1092
+ POST: {
1093
+ req: {
1094
+ body: z.ZodObject<{
1095
+ moduleFilePath: z.ZodString & z.ZodType<ModuleFilePath, string, z.core.$ZodTypeInternals<ModuleFilePath, string>>;
1096
+ sourcePath: z.ZodType<SourcePathT, unknown, z.core.$ZodTypeInternals<SourcePathT, unknown>>;
1097
+ fix: z.ZodType<ValidationFix, unknown, z.core.$ZodTypeInternals<ValidationFix, unknown>>;
1098
+ patchIds: z.ZodOptional<z.ZodArray<z.ZodString & z.ZodType<PatchIdT, string, z.core.$ZodTypeInternals<PatchIdT, string>>>>;
1099
+ }, z.core.$strip>;
1100
+ cookies: {
1101
+ val_session: z.ZodOptional<z.ZodString>;
1102
+ };
1103
+ };
1104
+ res: z.ZodUnion<readonly [z.ZodObject<{
1105
+ status: z.ZodLiteral<401>;
1106
+ json: z.ZodObject<{
1107
+ message: z.ZodString;
1108
+ }, z.core.$strip>;
1109
+ }, z.core.$strip>, z.ZodObject<{
1110
+ status: z.ZodLiteral<404>;
1111
+ json: z.ZodObject<{
1112
+ message: z.ZodString;
1113
+ }, z.core.$strip>;
1114
+ }, z.core.$strip>, z.ZodObject<{
1115
+ status: z.ZodLiteral<400>;
1116
+ json: z.ZodObject<{
1117
+ message: z.ZodString;
1118
+ }, z.core.$strip>;
1119
+ }, z.core.$strip>, z.ZodObject<{
1120
+ status: z.ZodLiteral<500>;
1121
+ json: z.ZodObject<{
1122
+ message: z.ZodString;
1123
+ }, z.core.$strip>;
1124
+ }, z.core.$strip>, z.ZodObject<{
1125
+ status: z.ZodLiteral<501>;
1126
+ json: z.ZodObject<{
1127
+ message: z.ZodString;
1128
+ }, z.core.$strip>;
1129
+ }, z.core.$strip>, z.ZodObject<{
1130
+ status: z.ZodLiteral<200>;
1131
+ json: z.ZodObject<{
1132
+ patch: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1133
+ op: z.ZodLiteral<"add">;
1134
+ path: z.ZodArray<z.ZodString>;
1135
+ value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
1136
+ }, z.core.$strict>, z.ZodObject<{
1137
+ op: z.ZodLiteral<"remove">;
1138
+ path: z.ZodTuple<[z.ZodString], z.ZodString>;
1139
+ }, z.core.$strict>, z.ZodObject<{
1140
+ op: z.ZodLiteral<"replace">;
1141
+ path: z.ZodArray<z.ZodString>;
1142
+ value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
1143
+ }, z.core.$strict>, z.ZodObject<{
1144
+ op: z.ZodLiteral<"move">;
1145
+ from: z.ZodTuple<[z.ZodString], z.ZodString>;
1146
+ path: z.ZodArray<z.ZodString>;
1147
+ }, z.core.$strict>, z.ZodObject<{
1148
+ op: z.ZodLiteral<"copy">;
1149
+ from: z.ZodArray<z.ZodString>;
1150
+ path: z.ZodArray<z.ZodString>;
1151
+ }, z.core.$strict>, z.ZodObject<{
1152
+ op: z.ZodLiteral<"test">;
1153
+ path: z.ZodArray<z.ZodString>;
1154
+ value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
1155
+ }, z.core.$strict>, z.ZodObject<{
1156
+ op: z.ZodLiteral<"file">;
1157
+ path: z.ZodArray<z.ZodString>;
1158
+ filePath: z.ZodString;
1159
+ value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
1160
+ remote: z.ZodBoolean;
1161
+ nestedFilePath: z.ZodOptional<z.ZodArray<z.ZodString>>;
1162
+ metadata: z.ZodOptional<z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>>;
1163
+ }, z.core.$strict>], "op">>;
1164
+ remainingErrors: z.ZodArray<z.ZodObject<{
1165
+ message: z.ZodString;
1166
+ value: z.ZodOptional<z.ZodUnknown>;
1167
+ fatal: z.ZodOptional<z.ZodBoolean>;
1168
+ fixes: z.ZodOptional<z.ZodArray<z.ZodType<ValidationFix, unknown, z.core.$ZodTypeInternals<ValidationFix, unknown>>>>;
1169
+ sourcePath: z.ZodOptional<z.ZodString>;
1170
+ }, z.core.$strip>>;
1171
+ }, z.core.$strip>;
1172
+ }, z.core.$strip>]>;
1173
+ };
1174
+ };
1027
1175
  "/publish-job-prepare": {
1028
1176
  POST: {
1029
1177
  req: {
@@ -1,4 +1,14 @@
1
1
  import { Api, ClientOf } from "./ApiRoutes.js";
2
2
  import { SharedValConfig } from "./SharedValConfig.js";
3
3
  export type ValClient = ClientOf<Api>;
4
- export declare const createValClient: (host: string, config: SharedValConfig | null) => ValClient;
4
+ export declare const createValClient: (host: string, config: SharedValConfig | null, // We want to use this in the future
5
+ options?: {
6
+ /**
7
+ * What sends a request. The network's `fetch` unless given.
8
+ *
9
+ * The demo passes one that hands the `Request` to Val's server running in
10
+ * the same tab (`@valbuild/server/browser`), so everything on both sides
11
+ * of the call is the real thing and only the network is gone.
12
+ */
13
+ fetch?: (input: string, init: RequestInit) => Promise<Response>;
14
+ }) => ValClient;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * A Val demo, as the page hands it to the Studio.
3
+ *
4
+ * In a demo the Studio talks to Val's own server running in the same tab
5
+ * (`@valbuild/server/browser`) instead of to an API route, and the page that
6
+ * starts that server is the app's (`<ValApp demo>`) while the Studio is a
7
+ * separate bundle loaded by a script tag. A window property is how the two
8
+ * meet, the same way `window.__VAL_MODULES__` hands the Studio the project's
9
+ * modules. See `docs/plans/demo-mode.md`.
10
+ */
11
+ export type ValDemoRuntime = {
12
+ /**
13
+ * Sends a Studio request to the in-tab server. Passed to `createValClient`.
14
+ *
15
+ * The server holds its edits in memory, so starting the demo over is
16
+ * reloading the page: there is nothing stored to clear.
17
+ */
18
+ fetch: (input: string, init: RequestInit) => Promise<Response>;
19
+ /**
20
+ * Whether uploads work here. They need the demo's service worker, which
21
+ * relays the upload and the unpublished files to this tab's server, and a
22
+ * service worker needs a secure context. Where it cannot run the Studio
23
+ * refuses uploads before sending anything, and says why.
24
+ */
25
+ uploads: boolean;
26
+ };
27
+ declare global {
28
+ var __VAL_DEMO__: ValDemoRuntime | undefined;
29
+ }
30
+ /** The demo this page was started with, or null outside a demo. */
31
+ export declare function getValDemo(): ValDemoRuntime | null;
@@ -3,6 +3,7 @@ export * from "./richtext/richTextImages.js";
3
3
  export * from "./server/types.js";
4
4
  export * from "./server/requestScopedMemo.js";
5
5
  export * from "./ValClient.js";
6
+ export * from "./demo.js";
6
7
  export * from "./ValUrls.js";
7
8
  export * from "./ApiRoutes.js";
8
9
  export * from "./schema/compatibility.js";
@@ -29,6 +30,7 @@ export * from "./aiTools/aiImageToolPatches.js";
29
30
  export * from "./aiTools/aiSourceToolPatches.js";
30
31
  export * from "./validation/partitionValidationErrors.js";
31
32
  export * from "./validation/blockingValidationErrors.js";
33
+ export * from "./validation/studioFixes.js";
32
34
  export * from "./media/encodeImageDecisions.js";
33
35
  export * from "./search/searchIndex.js";
34
36
  export * from "./search/traverseSchemaSource.js";
@@ -1,11 +1,12 @@
1
- import { type SourcePath } from "@valbuild/core";
1
+ import { type SerializedEnumSchema, type SerializedSchema, type SourcePath } from "@valbuild/core";
2
2
  import { type SchemaSourceSnapshot } from "./resolveSchemaSourceFixes.js";
3
3
  /**
4
4
  * Which of the project's languages governs a path, or `null` for none.
5
5
  *
6
6
  * THE question the whole feature turns on. A locale scope is a subtree in one
7
7
  * language, and three things open one: a `locale` field on an object, a record
8
- * keyed by `s.locale()`, and a locale segment in a segmented key. Once this can
8
+ * keyed by `s.locale()`, and a locale parameter in a router's key
9
+ * (`s.router(router, { locale: … }, item)`, where the URL names the language). Once this can
9
10
  * be answered from the schema and the source alone, everything downstream falls
10
11
  * out of it — the Studio's locale filter, deep links, `<html lang>`, and knowing
11
12
  * what to translate from and into.
@@ -17,3 +18,29 @@ import { type SchemaSourceSnapshot } from "./resolveSchemaSourceFixes.js";
17
18
  * in most projects, and for every project that has not declared any languages.
18
19
  */
19
20
  export declare function localeAt(path: SourcePath, snapshot: SchemaSourceSnapshot): string | null;
21
+ /**
22
+ * The language a locale schema's value MEANS, or `null` if it means none of
23
+ * the project's.
24
+ *
25
+ * `s.locale()` stores the tag itself. An enum with `.locales(...)` stores a
26
+ * value that stands for one — `nb` for `nb-NO` — and, on a router parameter,
27
+ * `null` for a URL that left the segment out, which `{ null: tag }` names.
28
+ * Anything else is not a locale and means nothing here.
29
+ *
30
+ * Callers reading a FIELD pass only strings: a field that holds `null` has no
31
+ * language, whatever its schema says about URLs.
32
+ */
33
+ export declare function localeMeantBy(schema: SerializedSchema, value: string | null, available: readonly string[]): string | null;
34
+ /**
35
+ * The tag an enum's `.locales(...)` maps a value to, as written — `null` is
36
+ * the `{ null }` mapping — or `undefined` where it maps none.
37
+ *
38
+ * An own property: a plain object inherits `toString` and the rest, and an
39
+ * enum value is allowed to be spelled like one.
40
+ */
41
+ export declare function enumLocaleTag(schema: SerializedEnumSchema, value: string | null): string | undefined;
42
+ /**
43
+ * Whether a schema is a locale: `s.locale()`, or an enum `.locales(...)` made
44
+ * one.
45
+ */
46
+ export declare function isLocaleSchema(schema: SerializedSchema): boolean;
@@ -65,6 +65,53 @@ export declare function fitWithin(width: number, height: number, maxWidth: numbe
65
65
  export declare function isMimeTypeAccepted(mimeType: string, accept: string | undefined): boolean;
66
66
  /** Formats left alone: the lossy list, plus the target type when it already fits. */
67
67
  export declare function isSkippedSource(sourceMimeType: string, targetMimeType: string, needsDownscale: boolean): boolean;
68
+ /**
69
+ * The types the Studio can write with WebAssembly when the canvas cannot.
70
+ *
71
+ * libwebp, compiled to WebAssembly (`@jsquash/webp`, loaded by
72
+ * `packages/ui/spa/utils/webpWasm.ts`). One entry because `encode` has one
73
+ * `type`; a second type is a second encoder to host, not a second string here.
74
+ */
75
+ export declare const WASM_ENCODED_MIME_TYPES: string[];
76
+ /**
77
+ * Whether to encode the canvas's pixels with WebAssembly, given what the
78
+ * canvas's own encoder handed back.
79
+ *
80
+ * `canvas.toBlob` answers a type it cannot write with a PNG instead of an error,
81
+ * and Safari -- the browser people take their photos in -- cannot write WebP.
82
+ * The pixels on that canvas are already decoded, oriented and scaled, so the
83
+ * only thing missing is the encoder, and libwebp in WebAssembly is that.
84
+ *
85
+ * Only then, and that is what keeps the WebAssembly lazy: a browser whose
86
+ * canvas wrote the type is never asked to download an encoder, even when its
87
+ * WebP then loses to the original on size -- a second encoder of the same
88
+ * format would lose for the same reason.
89
+ *
90
+ * `null` -- no blob at all -- is not "cannot write this type" either. It is a
91
+ * canvas that failed to serialize anything, under memory pressure for instance,
92
+ * and says nothing about WebP: a Chromium tab that hits it is still a browser
93
+ * that writes WebP, and must not start downloading an encoder because of it.
94
+ */
95
+ export declare function shouldEncodeWithWasm(input: {
96
+ targetMimeType: string;
97
+ canvasOutputType: string | null;
98
+ }): boolean;
99
+ /**
100
+ * What to scale an image down to when nothing could write the type asked for:
101
+ * the source's own format, when it is one every canvas can write.
102
+ *
103
+ * The second fallback, after {@link shouldEncodeWithWasm}: it is what a browser
104
+ * whose canvas cannot write WebP gets when the WebAssembly encoder could not be
105
+ * loaded either (offline, a blocked host, a failed instantiation). Without it,
106
+ * `chooseEncoded` would rightly refuse the canvas's PNG and upload the original
107
+ * -- every photo at the camera's full size, the one case `maxWidth` exists
108
+ * for. Scaling it down as a JPEG keeps the half of `encode` this browser can do.
109
+ *
110
+ * Only when a downscale is needed: re-encoding a JPEG that already fits, as a
111
+ * JPEG, is a second generation of loss for a few percent. And never into a
112
+ * type `accept` refuses, for the reason `isMimeTypeAccepted` gives.
113
+ */
114
+ export declare function fallbackMimeType(sourceMimeType: string, needsDownscale: boolean, accept: string | undefined): string | null;
68
115
  /**
69
116
  * Whether to upload what the encoder produced, or the file that was picked.
70
117
  *
@@ -11,3 +11,9 @@ export type RoutePattern = {
11
11
  optional: boolean;
12
12
  };
13
13
  export declare function parseRoutePattern(pattern: string): RoutePattern[];
14
+ /**
15
+ * A parsed pattern written back as segments: the inverse of
16
+ * {@link parseRoutePattern}, in the vocabulary core's `matchRoutePattern`
17
+ * reads.
18
+ */
19
+ export declare function formatRoutePattern(pattern: RoutePattern[]): string[];
@@ -26,3 +26,10 @@ export declare function partitionValidationErrors(validationErrors: Record<Sourc
26
26
  surfaced: Record<SourcePath, ValidationError[]>;
27
27
  skipped: Record<SourcePath, ValidationError[]>;
28
28
  };
29
+ /**
30
+ * Whether the Studio leaves this error to the server, which repairs it on
31
+ * save, rather than showing it and holding a publish back for it. One rule
32
+ * for every gate: `val publish` asks the same question, so the CLI does not
33
+ * refuse what the Studio would publish.
34
+ */
35
+ export declare function isRepairedOnSave(error: ValidationError): boolean;
@@ -0,0 +1,14 @@
1
+ import type { ValidationFix } from "@valbuild/core";
2
+ /**
3
+ * The fixes the Studio's full check offers a **Fix** button for.
4
+ *
5
+ * Each is one `createFixPatch` can build without a disk: it reads a file's
6
+ * bytes through `FixFiles`, or needs no bytes at all. The server refuses any
7
+ * other code on `/validate/fix`, and the Studio shows those errors with the
8
+ * command to run instead of a button — so a code is added here when its fix
9
+ * can run in http mode and on the platform, not before. See
10
+ * `docs/plans/studio-validate.md`, "Order of work".
11
+ */
12
+ export declare const STUDIO_FIXES: readonly ["image:add-metadata", "image:check-metadata", "file:add-metadata", "file:check-metadata", "video:add-metadata", "videos:add-metadata", "view:check-module", "image:check-remote", "file:check-remote", "images:check-all-files", "files:check-all-files", "remote:rewrite-host"];
13
+ export type StudioFix = (typeof STUDIO_FIXES)[number];
14
+ export declare function isStudioFix(fix: ValidationFix): fix is StudioFix;
@@ -193,6 +193,21 @@ function parseRoutePattern(pattern) {
193
193
  });
194
194
  }
195
195
 
196
+ /**
197
+ * A parsed pattern written back as segments: the inverse of
198
+ * {@link parseRoutePattern}, in the vocabulary core's `matchRoutePattern`
199
+ * reads.
200
+ */
201
+ function formatRoutePattern(pattern) {
202
+ return pattern.map(function (part) {
203
+ if (part.type === "literal") {
204
+ return part.name;
205
+ }
206
+ var inner = part.type === "string-param" ? part.paramName : "...".concat(part.paramName);
207
+ return part.optional ? "[[".concat(inner, "]]") : "[".concat(inner, "]");
208
+ });
209
+ }
210
+
196
211
  function getNextAppRouterSourceFolder(moduleFilePath) {
197
212
  if (moduleFilePath.startsWith("/app")) {
198
213
  return "/app";
@@ -509,6 +524,7 @@ exports._objectSpread2 = _objectSpread2;
509
524
  exports._toPropertyKey = _toPropertyKey;
510
525
  exports._typeof = _typeof;
511
526
  exports._unsupportedIterableToArray = _unsupportedIterableToArray;
527
+ exports.formatRoutePattern = formatRoutePattern;
512
528
  exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
513
529
  exports.getPageRouterSitemapTree = getPageRouterSitemapTree;
514
530
  exports.getPageRouterSourceFolder = getPageRouterSourceFolder;
@@ -191,6 +191,21 @@ function parseRoutePattern(pattern) {
191
191
  });
192
192
  }
193
193
 
194
+ /**
195
+ * A parsed pattern written back as segments: the inverse of
196
+ * {@link parseRoutePattern}, in the vocabulary core's `matchRoutePattern`
197
+ * reads.
198
+ */
199
+ function formatRoutePattern(pattern) {
200
+ return pattern.map(function (part) {
201
+ if (part.type === "literal") {
202
+ return part.name;
203
+ }
204
+ var inner = part.type === "string-param" ? part.paramName : "...".concat(part.paramName);
205
+ return part.optional ? "[[".concat(inner, "]]") : "[".concat(inner, "]");
206
+ });
207
+ }
208
+
194
209
  function getNextAppRouterSourceFolder(moduleFilePath) {
195
210
  if (moduleFilePath.startsWith("/app")) {
196
211
  return "/app";
@@ -493,4 +508,4 @@ function getPatternFromModuleFilePath(moduleFilePath, srcFolder) {
493
508
  .replace("/page.val.ts", "").replace("/page.val.js", "");
494
509
  }
495
510
 
496
- export { DEFAULT_CANVAS_SELECTION as D, VAL_CONFIG_SESSION_STORAGE_KEY as V, _createForOfIteratorHelper as _, VAL_THEME_SESSION_STORAGE_KEY as a, VAL_AI_SESSION_STORAGE_KEY as b, VAL_CANVAS_PARAM as c, VAL_CANVAS_MESSAGE as d, DEFAULT_CANVAS_SELECTION_SOFT as e, isValCanvasStudioMessage as f, isValCanvasFrame as g, getNextAppRouterSourceFolder as h, isValCanvasPageMessage as i, getTanStackRouterSourceFolder as j, getPageRouterSourceFolder as k, isTanStackRoutesFolder as l, getPageRouterSitemapTree as m, getPatternFromModuleFilePath as n, _objectSpread2 as o, parseRoutePattern as p, _arrayLikeToArray as q, _unsupportedIterableToArray as r, _typeof as s, _defineProperty as t, _toPropertyKey as u, withValCanvasParam as w };
511
+ export { DEFAULT_CANVAS_SELECTION as D, VAL_CONFIG_SESSION_STORAGE_KEY as V, _createForOfIteratorHelper as _, VAL_THEME_SESSION_STORAGE_KEY as a, VAL_AI_SESSION_STORAGE_KEY as b, VAL_CANVAS_PARAM as c, VAL_CANVAS_MESSAGE as d, DEFAULT_CANVAS_SELECTION_SOFT as e, isValCanvasStudioMessage as f, isValCanvasFrame as g, formatRoutePattern as h, isValCanvasPageMessage as i, getNextAppRouterSourceFolder as j, getTanStackRouterSourceFolder as k, getPageRouterSourceFolder as l, isTanStackRoutesFolder as m, getPageRouterSitemapTree as n, getPatternFromModuleFilePath as o, parseRoutePattern as p, _objectSpread2 as q, _arrayLikeToArray as r, _unsupportedIterableToArray as s, _typeof as t, _defineProperty as u, _toPropertyKey as v, withValCanvasParam as w };
@@ -193,6 +193,21 @@ function parseRoutePattern(pattern) {
193
193
  });
194
194
  }
195
195
 
196
+ /**
197
+ * A parsed pattern written back as segments: the inverse of
198
+ * {@link parseRoutePattern}, in the vocabulary core's `matchRoutePattern`
199
+ * reads.
200
+ */
201
+ function formatRoutePattern(pattern) {
202
+ return pattern.map(function (part) {
203
+ if (part.type === "literal") {
204
+ return part.name;
205
+ }
206
+ var inner = part.type === "string-param" ? part.paramName : "...".concat(part.paramName);
207
+ return part.optional ? "[[".concat(inner, "]]") : "[".concat(inner, "]");
208
+ });
209
+ }
210
+
196
211
  function getNextAppRouterSourceFolder(moduleFilePath) {
197
212
  if (moduleFilePath.startsWith("/app")) {
198
213
  return "/app";
@@ -509,6 +524,7 @@ exports._objectSpread2 = _objectSpread2;
509
524
  exports._toPropertyKey = _toPropertyKey;
510
525
  exports._typeof = _typeof;
511
526
  exports._unsupportedIterableToArray = _unsupportedIterableToArray;
527
+ exports.formatRoutePattern = formatRoutePattern;
512
528
  exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
513
529
  exports.getPageRouterSitemapTree = getPageRouterSitemapTree;
514
530
  exports.getPageRouterSourceFolder = getPageRouterSourceFolder;