@valbuild/core 0.125.0 → 0.127.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +299 -0
  2. package/dist/declarations/src/index.d.ts +8 -2
  3. package/dist/declarations/src/initSchema.d.ts +62 -15
  4. package/dist/declarations/src/initVal.d.ts +108 -0
  5. package/dist/declarations/src/locale.d.ts +55 -0
  6. package/dist/declarations/src/render.d.ts +5 -4
  7. package/dist/declarations/src/schema/array.d.ts +69 -0
  8. package/dist/declarations/src/schema/boolean.d.ts +44 -0
  9. package/dist/declarations/src/schema/code.d.ts +63 -0
  10. package/dist/declarations/src/schema/color.d.ts +54 -0
  11. package/dist/declarations/src/schema/date.d.ts +64 -2
  12. package/dist/declarations/src/schema/datetime.d.ts +87 -2
  13. package/dist/declarations/src/schema/declaredKeys.d.ts +37 -0
  14. package/dist/declarations/src/schema/discriminatedUnion.d.ts +170 -0
  15. package/dist/declarations/src/schema/discriminatedUnionBranch.d.ts +20 -0
  16. package/dist/declarations/src/schema/enum.d.ts +131 -0
  17. package/dist/declarations/src/schema/file.d.ts +77 -0
  18. package/dist/declarations/src/schema/image.d.ts +102 -0
  19. package/dist/declarations/src/schema/index.d.ts +155 -2
  20. package/dist/declarations/src/schema/keyOf.d.ts +50 -0
  21. package/dist/declarations/src/schema/literal.d.ts +48 -0
  22. package/dist/declarations/src/schema/locale.d.ts +132 -0
  23. package/dist/declarations/src/schema/number.d.ts +58 -0
  24. package/dist/declarations/src/schema/object.d.ts +70 -0
  25. package/dist/declarations/src/schema/record.d.ts +187 -1
  26. package/dist/declarations/src/schema/richtext.d.ts +78 -0
  27. package/dist/declarations/src/schema/route.d.ts +44 -0
  28. package/dist/declarations/src/schema/settings.d.ts +54 -1
  29. package/dist/declarations/src/schema/string.d.ts +99 -0
  30. package/dist/declarations/src/schema/union.d.ts +54 -91
  31. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
  32. package/dist/declarations/src/source/settings.d.ts +51 -0
  33. package/dist/{index-915dd675.esm.js → index-5a6e6398.esm.js} +3057 -573
  34. package/dist/{index-daa122af.cjs.dev.js → index-889ac441.cjs.dev.js} +3064 -573
  35. package/dist/{index-a3846321.cjs.prod.js → index-d44deccb.cjs.prod.js} +3064 -573
  36. package/dist/valbuild-core.cjs.dev.js +9 -2
  37. package/dist/valbuild-core.cjs.prod.js +9 -2
  38. package/dist/valbuild-core.esm.js +1 -1
  39. package/package.json +1 -1
  40. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  41. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  42. package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -1,93 +1,56 @@
1
- import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
- import { ItemPreviewInput, PreviewItem, ReifiedPreview, PreviewScope } from "../preview.js";
3
- import { FieldRender } from "../render.js";
1
+ import { Schema } from "./index.js";
4
2
  import { SelectorSource } from "../selector/index.js";
5
- import { SourceObject } from "../source/index.js";
6
- import { ModuleFilePath, SourcePath } from "../val/index.js";
7
- import { SerializedLiteralSchema } from "./literal.js";
8
- import { SerializedObjectSchema } from "./object.js";
9
- import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
10
- export type SerializedUnionSchema = SerializedStringUnionSchema | SerializedObjectUnionSchema;
11
- export type SerializedStringUnionSchema = {
12
- type: "union";
13
- /** Static layout config, carried whole in the serialized schema — see `render.ts`. */
14
- render?: FieldRender;
15
- /** Set when this schema declares a `preview`. The closure itself cannot serialize. */
16
- preview?: true;
17
- key: SerializedLiteralSchema;
18
- items: SerializedLiteralSchema[];
19
- opt: boolean;
20
- customValidate?: boolean;
21
- readonly?: boolean;
22
- hidden?: boolean;
23
- description?: string;
24
- };
25
- export type SerializedObjectUnionSchema = {
26
- type: "union";
27
- /** Static layout config, carried whole in the serialized schema — see `render.ts`. */
28
- render?: FieldRender;
29
- /** Set when this schema declares a `preview`. The closure itself cannot serialize. */
30
- preview?: true;
31
- key: string;
32
- items: SerializedObjectSchema[];
33
- opt: boolean;
34
- customValidate?: boolean;
35
- readonly?: boolean;
36
- hidden?: boolean;
37
- description?: string;
38
- };
39
- type SourceOf<Key extends string | Schema<string>, T extends Schema<Key extends string ? SourceObject & {
40
- [k in Key]: string;
41
- } : Key extends Schema<string> ? string : unknown>[]> = T extends Schema<infer S>[] ? S extends SelectorSource ? S | (Key extends Schema<infer K> ? K : never) : never : never;
42
- export declare class UnionSchema<Key extends string | Schema<string>, T extends Schema<Key extends string ? SourceObject & {
43
- [k in Key]: string;
44
- } : Key extends Schema<string> ? string : unknown>[], Src extends SourceOf<Key, T> | null> extends Schema<Src> {
45
- private readonly key;
46
- private readonly items;
47
- private readonly opt;
48
- private readonly customValidateFunctions;
49
- private readonly isReadonly;
50
- private readonly isHidden;
51
- private readonly description?;
52
- private readonly renderInput;
53
- private readonly previewInput;
54
- describe(description: string | null): UnionSchema<Key, T, Src>;
55
- validate(validationFunction: (src: Src) => false | string): UnionSchema<Key, T, Src>;
56
- protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
57
- protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
58
- nullable(): UnionSchema<Key, T, Src | null>;
59
- readonly(isReadonly?: boolean): UnionSchema<Key, T, Src>;
60
- hidden(isHidden?: boolean): UnionSchema<Key, T, Src>;
61
- protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
62
- /**
63
- * The variant schema a value takes, for a TAGGED union (string `key`). `null`
64
- * for a literal union (its variants are leaves with nothing to descend into) or
65
- * when the value matches none of them — a structural error `executeValidate`
66
- * already reports.
67
- */
68
- private matchedVariant;
69
- /**
70
- * How this field is laid out in the editor when it is the item of an array
71
- * or record: `{ as: "inline" }` renders the field itself inside each row,
72
- * instead of a preview row that navigates to it.
73
- *
74
- * Static configuration, not a callback — see `render.ts`.
75
- */
76
- render(input: FieldRender): UnionSchema<Key, T, Src>;
77
- /**
78
- * How this VALUE is shown where a preview of it is needed — a row in a
79
- * sortable list, a reference dropdown, a search hit. Never how the field
80
- * itself is edited (that is `render`). See `preview.ts`.
81
- *
82
- * Without one of its own, a tagged union previews as the VARIANT the value
83
- * takes — declare `preview` on the member objects and the union dispatches.
84
- */
85
- preview(select: ItemPreviewInput<Src>): UnionSchema<Key, T, Src>;
86
- protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
87
- protected declaresItemPreview(): boolean;
88
- protected executeSerialize(): SerializedSchema;
89
- constructor(key: Key, items: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
90
- protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
91
- }
92
- export declare const union: <Key extends string | Schema<string>, T extends Schema<Key extends string ? SourceObject & { [k in Key]: string; } : Key extends Schema<string> ? string : unknown>[]>(key: Key, ...objects: T) => UnionSchema<Key, T, SourceOf<Key, T>>;
3
+ import { DiscriminatedUnionItems, DiscriminatedUnionSchema, DiscriminatedUnionSourceOf, SerializedDiscriminatedUnionSchema } from "./discriminatedUnion.js";
4
+ import { EnumSchema, SerializedEnumSchema } from "./enum.js";
5
+ /**
6
+ * @deprecated Use {@link SerializedDiscriminatedUnionSchema} or
7
+ * {@link SerializedEnumSchema}. A serialized union is now one or the other,
8
+ * distinguished by `type` rather than by the shape of `key`.
9
+ */
10
+ export type SerializedUnionSchema = SerializedDiscriminatedUnionSchema | SerializedEnumSchema;
11
+ /** @deprecated Use {@link SerializedEnumSchema}. */
12
+ export type SerializedStringUnionSchema = SerializedEnumSchema;
13
+ /** @deprecated Use {@link SerializedDiscriminatedUnionSchema}. */
14
+ export type SerializedObjectUnionSchema = SerializedDiscriminatedUnionSchema;
15
+ /**
16
+ * @deprecated There is no single union schema class any more: name
17
+ * {@link DiscriminatedUnionSchema} or {@link EnumSchema}. The type parameters
18
+ * are kept so existing annotations still compile, but only `Src` is used.
19
+ */
20
+ export type UnionSchema<_Key = unknown, _T = unknown, Src extends SelectorSource = SelectorSource> = Schema<Src>;
21
+ /**
22
+ * The value type of a list of literal schemas — how `s.union` typed a union of
23
+ * literals. Inferred from `Schema<infer S>` rather than `LiteralSchema<infer S>`
24
+ * because a `LiteralSchema` is invariant in its source (its custom validate
25
+ * functions put it in a parameter position), so `LiteralSchema<"a">` is not
26
+ * assignable to `LiteralSchema<"a" | "b">`.
27
+ */
28
+ type EnumSourceOf<T extends Schema<string>[]> = T extends Schema<infer S>[] ? S extends string ? S : never : never;
29
+ /**
30
+ * @deprecated Use `s.discriminatedUnion(key, ...objects)` for a tagged union of
31
+ * objects, or `s.enum("a", "b")` for one of a fixed set of strings.
32
+ *
33
+ * One thing does NOT survive the literal form: an enum's values are strings,
34
+ * so a member literal's own `.validate()` and `.describe()` are dropped rather
35
+ * than carried over. `s.union(s.literal("a").validate(...), ...)` ran that
36
+ * validator as part of deciding whether the value matched; `s.enum` has no
37
+ * member to run. A validator on a single-valued literal could only accept or
38
+ * reject that one value, which the enum's own value list already decides — but
39
+ * if you rely on one, keep it by validating the enum itself.
40
+ *
41
+ * @example
42
+ * // was: s.union("type", s.object({ type: s.literal("a"), a: s.string() }))
43
+ * const schema = s.discriminatedUnion(
44
+ * "type",
45
+ * s.object({ type: s.literal("a"), a: s.string() }),
46
+ * );
47
+ * export default c.define("/example.val.ts", schema, { type: "a", a: "one" });
48
+ *
49
+ * @example
50
+ * // was: s.union(s.literal("a"), s.literal("b"))
51
+ * const schema = s.enum("a", "b");
52
+ * export default c.define("/example.val.ts", schema, "a");
53
+ */
54
+ export declare function union<Key extends string, T extends DiscriminatedUnionItems<Key>>(key: Key, ...objects: T): DiscriminatedUnionSchema<Key, T, DiscriminatedUnionSourceOf<Key, T>>;
55
+ export declare function union<T extends Schema<string>[]>(...literals: T): EnumSchema<EnumSourceOf<T>>;
93
56
  export {};
@@ -1,2 +1,2 @@
1
- export declare const ValidationFix: readonly ["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", "images:check-unique-folder", "files:check-unique-folder", "images:check-all-files", "files:check-all-files", "jsonValues:extract-entry", "external:upload"];
1
+ export declare const ValidationFix: readonly ["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"];
2
2
  export type ValidationFix = (typeof ValidationFix)[number];
@@ -22,6 +22,41 @@
22
22
  */
23
23
  export type SettingsSource = {
24
24
  assistant?: AssistantSettingsSource;
25
+ locales?: LocalesSettingsSource;
26
+ };
27
+ /**
28
+ * The languages this project publishes.
29
+ *
30
+ * Content rather than configuration, and deliberately: which languages a site
31
+ * has is a decision the people who write it make, and under a build-time
32
+ * constant it took a developer and a deploy. It is the same move `assistant`
33
+ * makes with `enabled`.
34
+ *
35
+ * Val ships no list of its own. A project with no `locales` section has not
36
+ * said it is translated, and nothing about locales appears anywhere — no picker
37
+ * in the Studio, no checks, nothing.
38
+ *
39
+ * **This list is a decision with a blast radius.** Every locale in content is
40
+ * checked against it, so removing one invalidates the content that uses it, and
41
+ * adding one leaves every locale-keyed record short of a language until it is
42
+ * filled in. That is the intended behaviour — a language that is declared and
43
+ * missing everywhere is worth being told about — but it is why the Studio warns
44
+ * before saving a removal rather than treating this as an ordinary field.
45
+ *
46
+ * There is no default language, deliberately. Every locale-specific field asks
47
+ * which language it is in, and a default is exactly the answer that lets that
48
+ * question go unanswered — content ends up filed under a language nobody chose,
49
+ * which is the state translation is meant to make visible.
50
+ */
51
+ export type LocalesSettingsSource = {
52
+ /**
53
+ * The languages, as canonical BCP 47 tags: `en-US`, `nb-NO`.
54
+ *
55
+ * Order is the project's own, and it is kept: it decides the order of the
56
+ * Studio's picker and of the rows in a locale-keyed record, so a project can
57
+ * put the language it works in first.
58
+ */
59
+ available?: string[] | null;
25
60
  };
26
61
  /**
27
62
  * The assistant: whether editors have one, and what it is told about the
@@ -55,6 +90,22 @@ export type AssistantSettingsSource = {
55
90
  * `glossary`) rather than a field that looks like it should absorb them.
56
91
  */
57
92
  tone?: string | null;
93
+ /**
94
+ * How to translate into each language, keyed by language.
95
+ *
96
+ * Per language rather than one field, because translation rules are per
97
+ * language: bokmål or nynorsk, `du` or `De`, which product names stay in
98
+ * English. Only the target language's note is sent, so a French rule does not
99
+ * ride along in a Norwegian request.
100
+ *
101
+ * Keyed by language, so it holds every one of them once it exists at all —
102
+ * `null` where a language needs no special instruction, which is most of them.
103
+ * That is the same rule every locale-keyed record follows (see
104
+ * `declaredKeys.ts`): a gap you can count and see in a diff, rather than a key
105
+ * that is simply not there. A project with no notes at all leaves the whole
106
+ * field unset and nothing is required.
107
+ */
108
+ translation?: Record<string, string | null> | null;
58
109
  };
59
110
  /**
60
111
  * The cap on each of the assistant's prose fields, in characters.