@valbuild/shared 0.133.0 → 0.134.1

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,79 @@
1
1
  # @valbuild/shared
2
2
 
3
+ ## 0.134.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#709](https://github.com/valbuild/val/pull/709) [`821e789`](https://github.com/valbuild/val/commit/821e789c1af47510af5d23eb96384ff78ddd7646) Thanks [@freekh](https://github.com/freekh)! - Show the reason behind a content-service error instead of just "Internal Server
8
+ Error".
9
+
10
+ `content.val.build` answers a handler that threw with `{ message: "Internal
11
+ Server Error", details: "<the actual cause>" }`. Val was reading `message` and
12
+ dropping `details`, so a failed save put exactly this in front of an editor —
13
+ and the same text in the app's own logs, because Val was relaying it:
14
+
15
+ ```json
16
+ { "type": "patch-error", "message": "Internal Server Error", "errors": { … } }
17
+ ```
18
+
19
+ A string `details` is now appended to the message (capped at 500 characters).
20
+ A structured one is not: that is what a _refusal_ carries, and its summary is
21
+ already the message.
22
+
23
+ ## 0.134.0
24
+
25
+ ### Minor Changes
26
+
27
+ - [#680](https://github.com/valbuild/val/pull/680) [`eaa265e`](https://github.com/valbuild/val/commit/eaa265e78d9f6d2a1b685c38901612b8a3704eed) Thanks [@freekh](https://github.com/freekh)! - Add `s.view()`: point at another module, so editors can reach it from the page it belongs to.
28
+
29
+ Content that has to live in its own module — a `keyOf` target, shared settings, a route-keyed record — is invisible from the page an editor thinks of it as part of. A view field puts a row on that page's screen that leads to it:
30
+
31
+ ```ts
32
+ import employeesVal from "../data/employees.val";
33
+
34
+ const schema = s.object({
35
+ title: s.string(),
36
+ employees: s.view(employeesVal),
37
+ });
38
+
39
+ export default c.define("/app/menneskene/page.val.ts", schema, {
40
+ title: "Våre folk",
41
+ employees: { view: "/data/employees.val.ts" },
42
+ });
43
+ ```
44
+
45
+ The source is a pointer and nothing else. The module it names keeps its own source, patches, validation and address, and an editor who follows the row lands on that module's own screen — so it is clear they are changing something other pages use too.
46
+
47
+ A few things worth knowing:
48
+
49
+ - **The path autocompletes, and a wrong one does not compile.** A module now carries its own id in its type, so the source type of the field above is the literal `{ view: "/data/employees.val.ts" }`.
50
+ - **It is not readable in code.** `useVal(pageVal).employees` is a `ValView<…>` — an opaque pointer with no fields on it. Read the module it names directly, as before.
51
+ - **`view` is now a reserved object key**, like `_type` and `patch_id`: `s.object({ view: ... })` no longer compiles. A single `view: string` key is what a view pointer looks like, and an ordinary object with that shape would be indistinguishable from one.
52
+ - **Views may not form a cycle.** `A → B → A`, and a module viewing itself, are reported as module errors by `val validate` and in the Studio.
53
+ - **A pointer that disagrees with its schema is repaired automatically.** It can only happen in hand-written JSON, and the schema is the authority, so `val validate --fix` and saving in the Studio both write the module the schema names.
54
+ - **A view's `hidden` and `readonly` are its own, never the module's it points at.** A view whose target is hidden is still shown, and still leads there.
55
+
56
+ That last one comes with a change to what `hidden()` means on a **module's own schema**, which is the other half of making a shared module usable:
57
+
58
+ ```ts
59
+ // Not in the nav, and on exactly one page.
60
+ export default c.define("/data/employees.val.ts", s.record(...).hidden(), { ... });
61
+ ```
62
+
63
+ It now means the nav does not list the module — the Explorer for an ordinary module, Media for a gallery — and nothing more. Previously it also blanked the module's own page, so a module you had hidden was still in the nav and showed nothing when opened. A hidden module is now reached from an `s.view()` row, from search or from a validation error, and renders in full when you get there.
64
+
65
+ One gap worth naming rather than leaving to be discovered: a view pointing at a
66
+ module the project does not have is reported by the FIELD — the row says the
67
+ target is missing — but not by `val validate`. The schema check compares the
68
+ pointer against the schema, and the cycle check deliberately skips a target that
69
+ is not a module of the project, so neither catches it. A project-level check
70
+ belongs with them and is not here yet.
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [[`16c49ea`](https://github.com/valbuild/val/commit/16c49ea6dd97c7a96bbfdf211af9bab5884579e2), [`eaa265e`](https://github.com/valbuild/val/commit/eaa265e78d9f6d2a1b685c38901612b8a3704eed)]:
75
+ - @valbuild/core@0.134.0
76
+
3
77
  ## 0.133.0
4
78
 
5
79
  ### Minor Changes
@@ -956,7 +956,7 @@ export declare const Api: {
956
956
  message: z.ZodString;
957
957
  value: z.ZodOptional<z.ZodUnknown>;
958
958
  fatal: z.ZodOptional<z.ZodBoolean>;
959
- fixes: z.ZodOptional<z.ZodArray<z.ZodType<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "images:check-remote" | "images:upload-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "files:check-remote" | "files:upload-remote" | "keyof:check-keys" | "router:check-route" | "locale:check-locale" | "images:check-unique-folder" | "files:check-unique-folder" | "images:check-all-files" | "files:check-all-files" | "jsonValues:extract-entry" | "record:fill-keys" | "external:upload", unknown, z.core.$ZodTypeInternals<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "images:check-remote" | "images:upload-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "files:check-remote" | "files:upload-remote" | "keyof:check-keys" | "router:check-route" | "locale:check-locale" | "images:check-unique-folder" | "files:check-unique-folder" | "images:check-all-files" | "files:check-all-files" | "jsonValues:extract-entry" | "record:fill-keys" | "external:upload", unknown>>>>;
959
+ fixes: z.ZodOptional<z.ZodArray<z.ZodType<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "images:check-remote" | "images:upload-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "files:check-remote" | "files:upload-remote" | "keyof:check-keys" | "router:check-route" | "locale:check-locale" | "images:check-unique-folder" | "files:check-unique-folder" | "images:check-all-files" | "files:check-all-files" | "jsonValues:extract-entry" | "record:fill-keys" | "external:upload" | "view:check-module", unknown, z.core.$ZodTypeInternals<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "images:check-remote" | "images:upload-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "files:check-remote" | "files:upload-remote" | "keyof:check-keys" | "router:check-route" | "locale:check-locale" | "images:check-unique-folder" | "files:check-unique-folder" | "images:check-all-files" | "files:check-all-files" | "jsonValues:extract-entry" | "record:fill-keys" | "external:upload" | "view:check-module", unknown>>>>;
960
960
  }, z.core.$strip>>>>;
961
961
  }, z.core.$strip>>;
962
962
  }, z.core.$strip>;
@@ -76,4 +76,23 @@ export declare const SerializedCodeSchema: z.ZodType<SerializedCodeSchemaT>;
76
76
  export declare const SerializedLocaleSchema: z.ZodType<SerializedLocaleSchemaT>;
77
77
  export declare const SerializedRouteSchema: z.ZodType<SerializedRouteSchemaT>;
78
78
  export declare const SerializedSettingsSchema: z.ZodType<SerializedSettingsSchemaT>;
79
+ /**
80
+ * A view field shows another module and stores nothing of its own.
81
+ *
82
+ * Nothing in the type system forces this member to exist: `SerializedSchema` is
83
+ * declared as `z.ZodType<SerializedSchemaT>`, so a missing member is not a type
84
+ * error — it is a runtime parse failure of the WHOLE module's schema, since the
85
+ * containing object fails with it.
86
+ */
87
+ export declare const SerializedValViewSchema: z.ZodObject<{
88
+ type: z.ZodLiteral<"view">;
89
+ render: z.ZodOptional<z.ZodOptional<z.ZodObject<{
90
+ as: z.ZodLiteral<"inline">;
91
+ }, z.core.$strip>>>;
92
+ moduleFilePath: z.ZodType<import("@valbuild/core").ModuleFilePath, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").ModuleFilePath, unknown>>;
93
+ opt: z.ZodLiteral<false>;
94
+ readonly: z.ZodOptional<z.ZodBoolean>;
95
+ hidden: z.ZodOptional<z.ZodBoolean>;
96
+ description: z.ZodOptional<z.ZodString>;
97
+ }, z.core.$strip>;
79
98
  export declare const SerializedSchema: z.ZodType<SerializedSchemaT>;
@@ -923,6 +923,10 @@ var SourcePath = zod.z.string().transform(function (path) {
923
923
  return path;
924
924
  });
925
925
 
926
+ var ModuleFilePath$1 = zod.z.string().transform(function (path) {
927
+ return path;
928
+ });
929
+
926
930
  var _excluded = ["directory"];
927
931
 
928
932
  // A render is static config, so unlike a `preview` it travels WHOLE — this
@@ -1216,7 +1220,25 @@ var SerializedSettingsSchema = zod.z.lazy(function () {
1216
1220
  section: zod.z.string().optional()
1217
1221
  }));
1218
1222
  });
1219
- var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedLocaleSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema]);
1223
+
1224
+ /**
1225
+ * A view field shows another module and stores nothing of its own.
1226
+ *
1227
+ * Nothing in the type system forces this member to exist: `SerializedSchema` is
1228
+ * declared as `z.ZodType<SerializedSchemaT>`, so a missing member is not a type
1229
+ * error — it is a runtime parse failure of the WHOLE module's schema, since the
1230
+ * containing object fails with it.
1231
+ */
1232
+ var SerializedValViewSchema = zod.z.object({
1233
+ type: zod.z.literal("view"),
1234
+ render: FieldRender.optional(),
1235
+ moduleFilePath: ModuleFilePath$1,
1236
+ opt: zod.z.literal(false),
1237
+ readonly: zod.z["boolean"]().optional(),
1238
+ hidden: zod.z["boolean"]().optional(),
1239
+ description: zod.z.string().optional()
1240
+ });
1241
+ var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedLocaleSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema, SerializedValViewSchema]);
1220
1242
 
1221
1243
  var ValCommit = zod.z.object({
1222
1244
  commitSha: zod.z.string(),
@@ -1402,7 +1424,7 @@ var ValConfig = zod.z.object({
1402
1424
  gitCommit: zod.z.string().optional(),
1403
1425
  gitBranch: zod.z.string().optional()
1404
1426
  });
1405
- var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("images:check-remote"), zod.z.literal("images:upload-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("files:check-remote"), zod.z.literal("files:upload-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("router:check-route"), zod.z.literal("locale:check-locale"), zod.z.literal("record:fill-keys"), zod.z.literal("images:check-unique-folder"), zod.z.literal("files:check-unique-folder"), zod.z.literal("images:check-all-files"), zod.z.literal("files:check-all-files"), zod.z.literal("jsonValues:extract-entry")]);
1427
+ var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("images:check-remote"), zod.z.literal("images:upload-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("files:check-remote"), zod.z.literal("files:upload-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("router:check-route"), zod.z.literal("locale:check-locale"), zod.z.literal("record:fill-keys"), zod.z.literal("images:check-unique-folder"), zod.z.literal("files:check-unique-folder"), zod.z.literal("images:check-all-files"), zod.z.literal("files:check-all-files"), zod.z.literal("jsonValues:extract-entry"), zod.z.literal("view:check-module")]);
1406
1428
  var ValidationError = zod.z.object({
1407
1429
  message: zod.z.string(),
1408
1430
  value: zod.z.unknown().optional(),
@@ -3035,12 +3057,59 @@ var Api = {
3035
3057
  // `number` is allowed because the client stringifies every query value before it
3036
3058
  // goes on the URL (see createValClient), so a numeric param round-trips fine.
3037
3059
 
3060
+ /**
3061
+ * How long an appended `details` may be before it is cut.
3062
+ *
3063
+ * A thrown DAL error in the content service quotes the whole offending ROW back
3064
+ * — which for a patch is every op the editor just made — so an uncapped append
3065
+ * puts kilobytes of JSON in a dialog. The head is where the cause is; the tail
3066
+ * is the evidence, and it belongs in the service's own logs.
3067
+ */
3068
+ var MAX_DETAILS_LENGTH = 500;
3038
3069
  function getErrorMessageFromUnknownJson(json, fallback) {
3039
3070
  if (getSitemapTree._typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
3040
- return json.message;
3071
+ var details = detailsOf(json);
3072
+ if (details === null || details === json.message) {
3073
+ return json.message;
3074
+ }
3075
+ return "".concat(json.message, ": ").concat(details);
3041
3076
  }
3042
3077
  return fallback;
3043
3078
  }
3079
+
3080
+ /**
3081
+ * The cause the content service put beside its message, when it wrote one a
3082
+ * person can read.
3083
+ *
3084
+ * `HttpError` in `home` is `{ statusCode, message?, details? }`, and `details`
3085
+ * is filled in two quite different ways. Where a handler REFUSED, it holds the
3086
+ * structured zod error whose summary is already the `message` — repeating it
3087
+ * adds nothing. Where a handler THREW, `sendResult` writes `message:
3088
+ * "Internal Server Error"` and puts the exception's own message in `details` —
3089
+ * so there the message says nothing and the details say everything.
3090
+ *
3091
+ * Which is why the test is the TYPE rather than the status code: a string
3092
+ * `details` is prose meant to be read, an object is a payload meant to be
3093
+ * parsed. This takes the first and leaves the second.
3094
+ *
3095
+ * It was written after an hour was lost to the second case. A patch save
3096
+ * against a content service that threw showed the Studio exactly
3097
+ * `"Internal Server Error"` and nothing else, in a dialog with no other clue,
3098
+ * while the service's answer had been carrying the reason the whole time.
3099
+ */
3100
+ function detailsOf(json) {
3101
+ if (!("details" in json) || typeof json.details !== "string") {
3102
+ return null;
3103
+ }
3104
+ var details = json.details.trim();
3105
+ if (details === "") {
3106
+ return null;
3107
+ }
3108
+ if (details.length <= MAX_DETAILS_LENGTH) {
3109
+ return details;
3110
+ }
3111
+ return "".concat(details.slice(0, MAX_DETAILS_LENGTH), "\u2026");
3112
+ }
3044
3113
  var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
3045
3114
 
3046
3115
  var createValClient = function createValClient(host, config // We want to use this in the future
@@ -4751,6 +4820,13 @@ function emptyOf(schema, context) {
4751
4820
  }, (_schema$options$forma = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.format) !== null && _schema$options$forma !== void 0 ? _schema$options$forma : core.DEFAULT_COLOR_FORMAT);
4752
4821
  } else if (schema.type === "code") {
4753
4822
  return ""; // An empty editor: no language has a sensible starting snippet
4823
+ } else if (schema.type === "view") {
4824
+ // The pointer IS the empty value: a view has exactly one valid source, and
4825
+ // the schema knows it. A new page with a view field gets the same pointer
4826
+ // every other page's has.
4827
+ return {
4828
+ view: schema.moduleFilePath
4829
+ };
4754
4830
  }
4755
4831
  var _exhaustiveCheck = schema;
4756
4832
  throw Error("Unexpected schema type: " + JSON.stringify(_exhaustiveCheck));
@@ -5398,6 +5474,8 @@ function isSkippableFixCode(fix) {
5398
5474
  case "files:check-unique-folder":
5399
5475
  case "images:check-all-files":
5400
5476
  case "files:check-all-files":
5477
+ case "view:check-module":
5478
+ // schema is code: nothing for an editor to do
5401
5479
  return true;
5402
5480
  case "keyof:check-keys":
5403
5481
  case "router:check-route":
@@ -5879,6 +5957,12 @@ function traverseSchemaSource(source, schema, path, callback) {
5879
5957
  }
5880
5958
  return;
5881
5959
  }
5960
+ if (schema.type === "view") {
5961
+ // The source here is a pointer — a module file path, not content. Indexing
5962
+ // it would make every view a hit for its target's filename, and the target
5963
+ // is already indexed under its own path.
5964
+ return;
5965
+ }
5882
5966
 
5883
5967
  // Exhaustive check
5884
5968
  var exhaustiveCheck = schema;
@@ -6760,6 +6844,7 @@ exports.SerializedRouteSchema = SerializedRouteSchema;
6760
6844
  exports.SerializedSchema = SerializedSchema;
6761
6845
  exports.SerializedSettingsSchema = SerializedSettingsSchema;
6762
6846
  exports.SerializedStringSchema = SerializedStringSchema;
6847
+ exports.SerializedValViewSchema = SerializedValViewSchema;
6763
6848
  exports.SharedValConfig = SharedValConfig;
6764
6849
  exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
6765
6850
  exports.VAL_GREEN_RAMP = VAL_GREEN_RAMP;
@@ -923,6 +923,10 @@ var SourcePath = zod.z.string().transform(function (path) {
923
923
  return path;
924
924
  });
925
925
 
926
+ var ModuleFilePath$1 = zod.z.string().transform(function (path) {
927
+ return path;
928
+ });
929
+
926
930
  var _excluded = ["directory"];
927
931
 
928
932
  // A render is static config, so unlike a `preview` it travels WHOLE — this
@@ -1216,7 +1220,25 @@ var SerializedSettingsSchema = zod.z.lazy(function () {
1216
1220
  section: zod.z.string().optional()
1217
1221
  }));
1218
1222
  });
1219
- var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedLocaleSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema]);
1223
+
1224
+ /**
1225
+ * A view field shows another module and stores nothing of its own.
1226
+ *
1227
+ * Nothing in the type system forces this member to exist: `SerializedSchema` is
1228
+ * declared as `z.ZodType<SerializedSchemaT>`, so a missing member is not a type
1229
+ * error — it is a runtime parse failure of the WHOLE module's schema, since the
1230
+ * containing object fails with it.
1231
+ */
1232
+ var SerializedValViewSchema = zod.z.object({
1233
+ type: zod.z.literal("view"),
1234
+ render: FieldRender.optional(),
1235
+ moduleFilePath: ModuleFilePath$1,
1236
+ opt: zod.z.literal(false),
1237
+ readonly: zod.z["boolean"]().optional(),
1238
+ hidden: zod.z["boolean"]().optional(),
1239
+ description: zod.z.string().optional()
1240
+ });
1241
+ var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedLocaleSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema, SerializedValViewSchema]);
1220
1242
 
1221
1243
  var ValCommit = zod.z.object({
1222
1244
  commitSha: zod.z.string(),
@@ -1402,7 +1424,7 @@ var ValConfig = zod.z.object({
1402
1424
  gitCommit: zod.z.string().optional(),
1403
1425
  gitBranch: zod.z.string().optional()
1404
1426
  });
1405
- var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("images:check-remote"), zod.z.literal("images:upload-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("files:check-remote"), zod.z.literal("files:upload-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("router:check-route"), zod.z.literal("locale:check-locale"), zod.z.literal("record:fill-keys"), zod.z.literal("images:check-unique-folder"), zod.z.literal("files:check-unique-folder"), zod.z.literal("images:check-all-files"), zod.z.literal("files:check-all-files"), zod.z.literal("jsonValues:extract-entry")]);
1427
+ var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("images:check-remote"), zod.z.literal("images:upload-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("files:check-remote"), zod.z.literal("files:upload-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("router:check-route"), zod.z.literal("locale:check-locale"), zod.z.literal("record:fill-keys"), zod.z.literal("images:check-unique-folder"), zod.z.literal("files:check-unique-folder"), zod.z.literal("images:check-all-files"), zod.z.literal("files:check-all-files"), zod.z.literal("jsonValues:extract-entry"), zod.z.literal("view:check-module")]);
1406
1428
  var ValidationError = zod.z.object({
1407
1429
  message: zod.z.string(),
1408
1430
  value: zod.z.unknown().optional(),
@@ -3035,12 +3057,59 @@ var Api = {
3035
3057
  // `number` is allowed because the client stringifies every query value before it
3036
3058
  // goes on the URL (see createValClient), so a numeric param round-trips fine.
3037
3059
 
3060
+ /**
3061
+ * How long an appended `details` may be before it is cut.
3062
+ *
3063
+ * A thrown DAL error in the content service quotes the whole offending ROW back
3064
+ * — which for a patch is every op the editor just made — so an uncapped append
3065
+ * puts kilobytes of JSON in a dialog. The head is where the cause is; the tail
3066
+ * is the evidence, and it belongs in the service's own logs.
3067
+ */
3068
+ var MAX_DETAILS_LENGTH = 500;
3038
3069
  function getErrorMessageFromUnknownJson(json, fallback) {
3039
3070
  if (getSitemapTree._typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
3040
- return json.message;
3071
+ var details = detailsOf(json);
3072
+ if (details === null || details === json.message) {
3073
+ return json.message;
3074
+ }
3075
+ return "".concat(json.message, ": ").concat(details);
3041
3076
  }
3042
3077
  return fallback;
3043
3078
  }
3079
+
3080
+ /**
3081
+ * The cause the content service put beside its message, when it wrote one a
3082
+ * person can read.
3083
+ *
3084
+ * `HttpError` in `home` is `{ statusCode, message?, details? }`, and `details`
3085
+ * is filled in two quite different ways. Where a handler REFUSED, it holds the
3086
+ * structured zod error whose summary is already the `message` — repeating it
3087
+ * adds nothing. Where a handler THREW, `sendResult` writes `message:
3088
+ * "Internal Server Error"` and puts the exception's own message in `details` —
3089
+ * so there the message says nothing and the details say everything.
3090
+ *
3091
+ * Which is why the test is the TYPE rather than the status code: a string
3092
+ * `details` is prose meant to be read, an object is a payload meant to be
3093
+ * parsed. This takes the first and leaves the second.
3094
+ *
3095
+ * It was written after an hour was lost to the second case. A patch save
3096
+ * against a content service that threw showed the Studio exactly
3097
+ * `"Internal Server Error"` and nothing else, in a dialog with no other clue,
3098
+ * while the service's answer had been carrying the reason the whole time.
3099
+ */
3100
+ function detailsOf(json) {
3101
+ if (!("details" in json) || typeof json.details !== "string") {
3102
+ return null;
3103
+ }
3104
+ var details = json.details.trim();
3105
+ if (details === "") {
3106
+ return null;
3107
+ }
3108
+ if (details.length <= MAX_DETAILS_LENGTH) {
3109
+ return details;
3110
+ }
3111
+ return "".concat(details.slice(0, MAX_DETAILS_LENGTH), "\u2026");
3112
+ }
3044
3113
  var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
3045
3114
 
3046
3115
  var createValClient = function createValClient(host, config // We want to use this in the future
@@ -4751,6 +4820,13 @@ function emptyOf(schema, context) {
4751
4820
  }, (_schema$options$forma = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.format) !== null && _schema$options$forma !== void 0 ? _schema$options$forma : core.DEFAULT_COLOR_FORMAT);
4752
4821
  } else if (schema.type === "code") {
4753
4822
  return ""; // An empty editor: no language has a sensible starting snippet
4823
+ } else if (schema.type === "view") {
4824
+ // The pointer IS the empty value: a view has exactly one valid source, and
4825
+ // the schema knows it. A new page with a view field gets the same pointer
4826
+ // every other page's has.
4827
+ return {
4828
+ view: schema.moduleFilePath
4829
+ };
4754
4830
  }
4755
4831
  var _exhaustiveCheck = schema;
4756
4832
  throw Error("Unexpected schema type: " + JSON.stringify(_exhaustiveCheck));
@@ -5398,6 +5474,8 @@ function isSkippableFixCode(fix) {
5398
5474
  case "files:check-unique-folder":
5399
5475
  case "images:check-all-files":
5400
5476
  case "files:check-all-files":
5477
+ case "view:check-module":
5478
+ // schema is code: nothing for an editor to do
5401
5479
  return true;
5402
5480
  case "keyof:check-keys":
5403
5481
  case "router:check-route":
@@ -5879,6 +5957,12 @@ function traverseSchemaSource(source, schema, path, callback) {
5879
5957
  }
5880
5958
  return;
5881
5959
  }
5960
+ if (schema.type === "view") {
5961
+ // The source here is a pointer — a module file path, not content. Indexing
5962
+ // it would make every view a hit for its target's filename, and the target
5963
+ // is already indexed under its own path.
5964
+ return;
5965
+ }
5882
5966
 
5883
5967
  // Exhaustive check
5884
5968
  var exhaustiveCheck = schema;
@@ -6760,6 +6844,7 @@ exports.SerializedRouteSchema = SerializedRouteSchema;
6760
6844
  exports.SerializedSchema = SerializedSchema;
6761
6845
  exports.SerializedSettingsSchema = SerializedSettingsSchema;
6762
6846
  exports.SerializedStringSchema = SerializedStringSchema;
6847
+ exports.SerializedValViewSchema = SerializedValViewSchema;
6763
6848
  exports.SharedValConfig = SharedValConfig;
6764
6849
  exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
6765
6850
  exports.VAL_GREEN_RAMP = VAL_GREEN_RAMP;
@@ -916,6 +916,10 @@ var SourcePath = z.string().transform(function (path) {
916
916
  return path;
917
917
  });
918
918
 
919
+ var ModuleFilePath$1 = z.string().transform(function (path) {
920
+ return path;
921
+ });
922
+
919
923
  var _excluded = ["directory"];
920
924
 
921
925
  // A render is static config, so unlike a `preview` it travels WHOLE — this
@@ -1209,7 +1213,25 @@ var SerializedSettingsSchema = z.lazy(function () {
1209
1213
  section: z.string().optional()
1210
1214
  }));
1211
1215
  });
1212
- var SerializedSchema = z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedLocaleSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema]);
1216
+
1217
+ /**
1218
+ * A view field shows another module and stores nothing of its own.
1219
+ *
1220
+ * Nothing in the type system forces this member to exist: `SerializedSchema` is
1221
+ * declared as `z.ZodType<SerializedSchemaT>`, so a missing member is not a type
1222
+ * error — it is a runtime parse failure of the WHOLE module's schema, since the
1223
+ * containing object fails with it.
1224
+ */
1225
+ var SerializedValViewSchema = z.object({
1226
+ type: z.literal("view"),
1227
+ render: FieldRender.optional(),
1228
+ moduleFilePath: ModuleFilePath$1,
1229
+ opt: z.literal(false),
1230
+ readonly: z["boolean"]().optional(),
1231
+ hidden: z["boolean"]().optional(),
1232
+ description: z.string().optional()
1233
+ });
1234
+ var SerializedSchema = z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedLocaleSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema, SerializedValViewSchema]);
1213
1235
 
1214
1236
  var ValCommit = z.object({
1215
1237
  commitSha: z.string(),
@@ -1395,7 +1417,7 @@ var ValConfig = z.object({
1395
1417
  gitCommit: z.string().optional(),
1396
1418
  gitBranch: z.string().optional()
1397
1419
  });
1398
- var ValidationFixZ = z.union([z.literal("image:add-metadata"), z.literal("image:check-metadata"), z.literal("image:check-remote"), z.literal("image:upload-remote"), z.literal("image:download-remote"), z.literal("images:check-remote"), z.literal("images:upload-remote"), z.literal("file:add-metadata"), z.literal("file:check-metadata"), z.literal("file:check-remote"), z.literal("file:upload-remote"), z.literal("file:download-remote"), z.literal("files:check-remote"), z.literal("files:upload-remote"), z.literal("keyof:check-keys"), z.literal("router:check-route"), z.literal("locale:check-locale"), z.literal("record:fill-keys"), z.literal("images:check-unique-folder"), z.literal("files:check-unique-folder"), z.literal("images:check-all-files"), z.literal("files:check-all-files"), z.literal("jsonValues:extract-entry")]);
1420
+ var ValidationFixZ = z.union([z.literal("image:add-metadata"), z.literal("image:check-metadata"), z.literal("image:check-remote"), z.literal("image:upload-remote"), z.literal("image:download-remote"), z.literal("images:check-remote"), z.literal("images:upload-remote"), z.literal("file:add-metadata"), z.literal("file:check-metadata"), z.literal("file:check-remote"), z.literal("file:upload-remote"), z.literal("file:download-remote"), z.literal("files:check-remote"), z.literal("files:upload-remote"), z.literal("keyof:check-keys"), z.literal("router:check-route"), z.literal("locale:check-locale"), z.literal("record:fill-keys"), z.literal("images:check-unique-folder"), z.literal("files:check-unique-folder"), z.literal("images:check-all-files"), z.literal("files:check-all-files"), z.literal("jsonValues:extract-entry"), z.literal("view:check-module")]);
1399
1421
  var ValidationError = z.object({
1400
1422
  message: z.string(),
1401
1423
  value: z.unknown().optional(),
@@ -3028,12 +3050,59 @@ var Api = {
3028
3050
  // `number` is allowed because the client stringifies every query value before it
3029
3051
  // goes on the URL (see createValClient), so a numeric param round-trips fine.
3030
3052
 
3053
+ /**
3054
+ * How long an appended `details` may be before it is cut.
3055
+ *
3056
+ * A thrown DAL error in the content service quotes the whole offending ROW back
3057
+ * — which for a patch is every op the editor just made — so an uncapped append
3058
+ * puts kilobytes of JSON in a dialog. The head is where the cause is; the tail
3059
+ * is the evidence, and it belongs in the service's own logs.
3060
+ */
3061
+ var MAX_DETAILS_LENGTH = 500;
3031
3062
  function getErrorMessageFromUnknownJson(json, fallback) {
3032
3063
  if (_typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
3033
- return json.message;
3064
+ var details = detailsOf(json);
3065
+ if (details === null || details === json.message) {
3066
+ return json.message;
3067
+ }
3068
+ return "".concat(json.message, ": ").concat(details);
3034
3069
  }
3035
3070
  return fallback;
3036
3071
  }
3072
+
3073
+ /**
3074
+ * The cause the content service put beside its message, when it wrote one a
3075
+ * person can read.
3076
+ *
3077
+ * `HttpError` in `home` is `{ statusCode, message?, details? }`, and `details`
3078
+ * is filled in two quite different ways. Where a handler REFUSED, it holds the
3079
+ * structured zod error whose summary is already the `message` — repeating it
3080
+ * adds nothing. Where a handler THREW, `sendResult` writes `message:
3081
+ * "Internal Server Error"` and puts the exception's own message in `details` —
3082
+ * so there the message says nothing and the details say everything.
3083
+ *
3084
+ * Which is why the test is the TYPE rather than the status code: a string
3085
+ * `details` is prose meant to be read, an object is a payload meant to be
3086
+ * parsed. This takes the first and leaves the second.
3087
+ *
3088
+ * It was written after an hour was lost to the second case. A patch save
3089
+ * against a content service that threw showed the Studio exactly
3090
+ * `"Internal Server Error"` and nothing else, in a dialog with no other clue,
3091
+ * while the service's answer had been carrying the reason the whole time.
3092
+ */
3093
+ function detailsOf(json) {
3094
+ if (!("details" in json) || typeof json.details !== "string") {
3095
+ return null;
3096
+ }
3097
+ var details = json.details.trim();
3098
+ if (details === "") {
3099
+ return null;
3100
+ }
3101
+ if (details.length <= MAX_DETAILS_LENGTH) {
3102
+ return details;
3103
+ }
3104
+ return "".concat(details.slice(0, MAX_DETAILS_LENGTH), "\u2026");
3105
+ }
3037
3106
  var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
3038
3107
 
3039
3108
  var createValClient = function createValClient(host, config // We want to use this in the future
@@ -4744,6 +4813,13 @@ function emptyOf(schema, context) {
4744
4813
  }, (_schema$options$forma = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.format) !== null && _schema$options$forma !== void 0 ? _schema$options$forma : DEFAULT_COLOR_FORMAT);
4745
4814
  } else if (schema.type === "code") {
4746
4815
  return ""; // An empty editor: no language has a sensible starting snippet
4816
+ } else if (schema.type === "view") {
4817
+ // The pointer IS the empty value: a view has exactly one valid source, and
4818
+ // the schema knows it. A new page with a view field gets the same pointer
4819
+ // every other page's has.
4820
+ return {
4821
+ view: schema.moduleFilePath
4822
+ };
4747
4823
  }
4748
4824
  var _exhaustiveCheck = schema;
4749
4825
  throw Error("Unexpected schema type: " + JSON.stringify(_exhaustiveCheck));
@@ -5391,6 +5467,8 @@ function isSkippableFixCode(fix) {
5391
5467
  case "files:check-unique-folder":
5392
5468
  case "images:check-all-files":
5393
5469
  case "files:check-all-files":
5470
+ case "view:check-module":
5471
+ // schema is code: nothing for an editor to do
5394
5472
  return true;
5395
5473
  case "keyof:check-keys":
5396
5474
  case "router:check-route":
@@ -5872,6 +5950,12 @@ function traverseSchemaSource(source, schema, path, callback) {
5872
5950
  }
5873
5951
  return;
5874
5952
  }
5953
+ if (schema.type === "view") {
5954
+ // The source here is a pointer — a module file path, not content. Indexing
5955
+ // it would make every view a hit for its target's filename, and the target
5956
+ // is already indexed under its own path.
5957
+ return;
5958
+ }
5875
5959
 
5876
5960
  // Exhaustive check
5877
5961
  var exhaustiveCheck = schema;
@@ -6671,4 +6755,4 @@ function resolvePairGround(ground, ramp) {
6671
6755
  return typeof ground === "number" ? ramp[ground] : ground;
6672
6756
  }
6673
6757
 
6674
- export { AA_LARGE, AA_TEXT, Api, BRAND_CONTRAST_PAIRS, BinaryFileRef, CodeOptions, ColorOptions, DEFAULT_ERROR_MESSAGE, DateOptions, ENCODE_DEFAULTS, ENCODE_MIME_TYPE_OF, FileOptions, HistoricalCommit, HistoricalModule, HistoricalPatchSet, HistoryError, ImageEncodeOption, ImageOptions, JSONValue, JSON_ENTRIES_BATCH_MAX, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchGroup, PatchId, PatchJSON, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedLocaleSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValCommit, ValDeployment, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isMimeTypeAccepted, isRemoteSchema, isSchemaSourceFixError, isSkippedSource, keyOfRecordPath, levenshtein, localeAt, newestCommitSha, partitionValidationErrors, performSearch, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextToRemirror, safeParsePatch, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
6758
+ export { AA_LARGE, AA_TEXT, Api, BRAND_CONTRAST_PAIRS, BinaryFileRef, CodeOptions, ColorOptions, DEFAULT_ERROR_MESSAGE, DateOptions, ENCODE_DEFAULTS, ENCODE_MIME_TYPE_OF, FileOptions, HistoricalCommit, HistoricalModule, HistoricalPatchSet, HistoryError, ImageEncodeOption, ImageOptions, JSONValue, JSON_ENTRIES_BATCH_MAX, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchGroup, PatchId, PatchJSON, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedLocaleSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedValViewSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValCommit, ValDeployment, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isMimeTypeAccepted, isRemoteSchema, isSchemaSourceFixError, isSkippedSource, keyOfRecordPath, levenshtein, localeAt, newestCommitSha, partitionValidationErrors, performSearch, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextToRemirror, safeParsePatch, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.133.0",
3
+ "version": "0.134.1",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "flexsearch": "^0.8.212",
38
38
  "zod": "^4.4.3",
39
39
  "zod-validation-error": "^5.0.0",
40
- "@valbuild/core": "0.130.0"
40
+ "@valbuild/core": "0.134.0"
41
41
  },
42
42
  "files": [
43
43
  "CHANGELOG.md",