@valbuild/core 0.124.0 → 0.126.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 (37) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/dist/declarations/src/getSourcePathFromRoute.d.ts +12 -3
  3. package/dist/declarations/src/index.d.ts +7 -3
  4. package/dist/declarations/src/initSchema.d.ts +46 -15
  5. package/dist/declarations/src/initVal.d.ts +108 -0
  6. package/dist/declarations/src/render.d.ts +5 -4
  7. package/dist/declarations/src/router.d.ts +45 -0
  8. package/dist/declarations/src/schema/array.d.ts +65 -0
  9. package/dist/declarations/src/schema/boolean.d.ts +44 -0
  10. package/dist/declarations/src/schema/code.d.ts +63 -0
  11. package/dist/declarations/src/schema/color.d.ts +54 -0
  12. package/dist/declarations/src/schema/date.d.ts +64 -2
  13. package/dist/declarations/src/schema/datetime.d.ts +87 -2
  14. package/dist/declarations/src/schema/discriminatedUnion.d.ts +166 -0
  15. package/dist/declarations/src/schema/enum.d.ts +122 -0
  16. package/dist/declarations/src/schema/file.d.ts +77 -0
  17. package/dist/declarations/src/schema/image.d.ts +102 -0
  18. package/dist/declarations/src/schema/index.d.ts +42 -2
  19. package/dist/declarations/src/schema/keyOf.d.ts +50 -0
  20. package/dist/declarations/src/schema/literal.d.ts +46 -0
  21. package/dist/declarations/src/schema/number.d.ts +58 -0
  22. package/dist/declarations/src/schema/object.d.ts +63 -0
  23. package/dist/declarations/src/schema/record.d.ts +136 -0
  24. package/dist/declarations/src/schema/richtext.d.ts +78 -0
  25. package/dist/declarations/src/schema/route.d.ts +44 -0
  26. package/dist/declarations/src/schema/string.d.ts +99 -0
  27. package/dist/declarations/src/schema/union.d.ts +54 -91
  28. package/dist/{index-22a40d42.cjs.prod.js → index-6db78f3c.cjs.prod.js} +2161 -423
  29. package/dist/{index-fcd087bd.cjs.dev.js → index-b41b638f.cjs.dev.js} +2161 -423
  30. package/dist/{index-9c14df37.esm.js → index-cd25c2dc.esm.js} +2155 -423
  31. package/dist/valbuild-core.cjs.dev.js +8 -2
  32. package/dist/valbuild-core.cjs.prod.js +8 -2
  33. package/dist/valbuild-core.esm.js +1 -1
  34. package/package.json +1 -1
  35. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  36. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  37. 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 {};