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