@valbuild/core 0.99.1 → 0.101.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/dist/declarations/src/index.d.ts +15 -0
- package/dist/declarations/src/initSchema.d.ts +21 -0
- package/dist/declarations/src/initVal.d.ts +2 -0
- package/dist/declarations/src/schema/array.d.ts +2 -1
- package/dist/declarations/src/schema/boolean.d.ts +2 -1
- package/dist/declarations/src/schema/color.d.ts +57 -0
- package/dist/declarations/src/schema/colorFormat.d.ts +83 -0
- package/dist/declarations/src/schema/date.d.ts +2 -1
- package/dist/declarations/src/schema/datetime.d.ts +2 -1
- package/dist/declarations/src/schema/file.d.ts +2 -1
- package/dist/declarations/src/schema/image.d.ts +2 -1
- package/dist/declarations/src/schema/index.d.ts +24 -1
- package/dist/declarations/src/schema/keyOf.d.ts +2 -1
- package/dist/declarations/src/schema/literal.d.ts +2 -1
- package/dist/declarations/src/schema/number.d.ts +2 -1
- package/dist/declarations/src/schema/object.d.ts +2 -1
- package/dist/declarations/src/schema/record.d.ts +46 -3
- package/dist/declarations/src/schema/richtext.d.ts +2 -1
- package/dist/declarations/src/schema/route.d.ts +2 -1
- package/dist/declarations/src/schema/string.d.ts +2 -1
- package/dist/declarations/src/schema/union.d.ts +9 -1
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/declarations/src/selector/index.d.ts +3 -2
- package/dist/declarations/src/source/index.d.ts +3 -2
- package/dist/declarations/src/source/json.d.ts +73 -0
- package/dist/{index-28d99c34.cjs.prod.js → index-049780fa.cjs.prod.js} +1238 -181
- package/dist/{index-b2601ac3.cjs.dev.js → index-3e2d700e.cjs.dev.js} +1238 -181
- package/dist/{index-204b5d78.esm.js → index-a18c24c2.esm.js} +1236 -182
- package/dist/valbuild-core.cjs.dev.js +4 -1
- package/dist/valbuild-core.cjs.prod.js +4 -1
- 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
|
@@ -5,7 +5,7 @@ import { SourceObject } from "../source/index.js";
|
|
|
5
5
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
6
6
|
import { SerializedLiteralSchema } from "./literal.js";
|
|
7
7
|
import { SerializedObjectSchema } from "./object.js";
|
|
8
|
-
import { ValidationErrors } from "./validation/ValidationError.js";
|
|
8
|
+
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
9
9
|
export type SerializedUnionSchema = SerializedStringUnionSchema | SerializedObjectUnionSchema;
|
|
10
10
|
export type SerializedStringUnionSchema = {
|
|
11
11
|
type: "union";
|
|
@@ -47,6 +47,14 @@ export declare class UnionSchema<Key extends string | Schema<string>, T extends
|
|
|
47
47
|
nullable(): UnionSchema<Key, T, Src | null>;
|
|
48
48
|
readonly(): UnionSchema<Key, T, Src>;
|
|
49
49
|
hidden(): UnionSchema<Key, T, Src>;
|
|
50
|
+
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
51
|
+
/**
|
|
52
|
+
* The variant schema a value takes, for a TAGGED union (string `key`). `null`
|
|
53
|
+
* for a literal union (its variants are leaves with nothing to descend into) or
|
|
54
|
+
* when the value matches none of them — a structural error `executeValidate`
|
|
55
|
+
* already reports.
|
|
56
|
+
*/
|
|
57
|
+
private matchedVariant;
|
|
50
58
|
protected executeSerialize(): SerializedSchema;
|
|
51
59
|
constructor(key: Key, items: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
|
|
52
60
|
protected executeRender(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedRender;
|
|
@@ -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"];
|
|
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"];
|
|
2
2
|
export type ValidationFix = (typeof ValidationFix)[number];
|
|
@@ -15,10 +15,11 @@ import { ImageSelector } from "./image.js";
|
|
|
15
15
|
import { RichTextSelector } from "./richtext.js";
|
|
16
16
|
import { ImageSource } from "../source/image.js";
|
|
17
17
|
import { RemoteSource } from "../source/remote.js";
|
|
18
|
-
|
|
18
|
+
import { JsonSource } from "../source/json.js";
|
|
19
|
+
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends ImageSource ? ImageSelector : T extends FileSource<infer M> ? FileSelector<M> : T extends JsonSource ? GenericSelector<JsonSource> : T extends RichTextSource<infer O> ? RichTextSelector<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
|
|
19
20
|
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
|
20
21
|
[key: string]: SelectorSource;
|
|
21
|
-
} | ImageSource | FileSource | RemoteSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
|
|
22
|
+
} | ImageSource | FileSource | RemoteSource | JsonSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
|
|
22
23
|
/**
|
|
23
24
|
* @internal
|
|
24
25
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FileSource } from "./file.js";
|
|
2
2
|
import { ImageSource } from "./image.js";
|
|
3
|
+
import { JsonSource } from "./json.js";
|
|
3
4
|
import { RemoteSource } from "./remote.js";
|
|
4
5
|
import { RichTextOptions, RichTextSource } from "./richtext.js";
|
|
5
|
-
export type Source = SourcePrimitive | SourceObject | SourceArray | RemoteSource | FileSource | ImageSource | RichTextSource<RichTextOptions>;
|
|
6
|
+
export type Source = SourcePrimitive | SourceObject | SourceArray | RemoteSource | FileSource | ImageSource | JsonSource | RichTextSource<RichTextOptions>;
|
|
6
7
|
export type SourceObject = {
|
|
7
8
|
[key in string]: Source;
|
|
8
9
|
} & {
|
|
@@ -24,7 +25,7 @@ export type SourceObject = {
|
|
|
24
25
|
export type SourceArray = readonly Source[];
|
|
25
26
|
export type SourcePrimitive = string | number | boolean | null;
|
|
26
27
|
export declare const VAL_EXTENSION: "_type";
|
|
27
|
-
export declare function getValExtension(source: Source): false | "" | 0 | "remote" | "file" | null | undefined;
|
|
28
|
+
export declare function getValExtension(source: Source): false | "" | 0 | "remote" | "file" | "json" | null | undefined;
|
|
28
29
|
/**
|
|
29
30
|
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
|
30
31
|
*
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PhantomType, Source, VAL_EXTENSION } from "./index.js";
|
|
2
|
+
import { Json } from "../Json.js";
|
|
3
|
+
/**
|
|
4
|
+
* The string used as the `_type` discriminator of a {@link JsonSource}.
|
|
5
|
+
*/
|
|
6
|
+
export declare const JSON_VAL_EXTENSION_TAG: "json";
|
|
7
|
+
/**
|
|
8
|
+
* The lazy import thunk a {@link JsonSource} carries at runtime. It is NOT part
|
|
9
|
+
* of the {@link JsonSource} type because `Source` must stay JSON-serializable
|
|
10
|
+
* (it is sent over the wire as `Json`); the thunk is a runtime-only detail,
|
|
11
|
+
* read via {@link getJsonImport}.
|
|
12
|
+
*/
|
|
13
|
+
export type JsonImportThunk<T = unknown> = () => Promise<{
|
|
14
|
+
default: T;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* A JSON source represents a record/router entry whose value is stored in a
|
|
18
|
+
* separate `*.val.json` file and loaded lazily via a dynamic `import()` thunk.
|
|
19
|
+
*
|
|
20
|
+
* This is what `c.json(() => import("./entry.val.json"))` returns.
|
|
21
|
+
*
|
|
22
|
+
* The *type* is a pure-JSON marker (`{ _type: "json", patch_id? }`) so that
|
|
23
|
+
* `Source` stays JSON-serializable. At runtime the value additionally carries a
|
|
24
|
+
* lazy import thunk (read via {@link getJsonImport}); over the wire only the
|
|
25
|
+
* marker is sent.
|
|
26
|
+
*
|
|
27
|
+
* The phantom type parameter `T` is the (loosened, see {@link JsonOf}) type of
|
|
28
|
+
* the value the JSON file resolves to. It is covariant: a `JsonSource` of a
|
|
29
|
+
* narrower value type is assignable to a `JsonSource` of a wider one.
|
|
30
|
+
*/
|
|
31
|
+
export type JsonSource<T = unknown> = {
|
|
32
|
+
readonly [VAL_EXTENSION]: typeof JSON_VAL_EXTENSION_TAG;
|
|
33
|
+
/** Set on uncommitted/draft entries (mirrors FileSource/RemoteSource). */
|
|
34
|
+
readonly patch_id?: string;
|
|
35
|
+
} & PhantomType<T>;
|
|
36
|
+
export declare function json<T = Json>(importThunk: JsonImportThunk<T>): JsonSource<T>;
|
|
37
|
+
export declare function isJson(obj: unknown): obj is JsonSource;
|
|
38
|
+
/**
|
|
39
|
+
* Reads the runtime-only lazy import thunk from a {@link JsonSource}. Returns
|
|
40
|
+
* `undefined` for a transport marker (sent over the wire without the thunk).
|
|
41
|
+
*/
|
|
42
|
+
export declare function getJsonImport(source: JsonSource): JsonImportThunk | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Recursively resolves every {@link JsonSource} marker in a source tree by
|
|
45
|
+
* invoking its lazy import thunk, returning a fully-inlined source. This backs
|
|
46
|
+
* the eager `fetchVal`/`useVal` path (load everything).
|
|
47
|
+
*
|
|
48
|
+
* Markers without a runtime thunk (transport markers received over the wire)
|
|
49
|
+
* are left as-is — there is nothing to load from them locally. Other branded
|
|
50
|
+
* leaf sources (file/image/remote/richtext) are returned untouched.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveJsonValues(source: Source): Promise<Source>;
|
|
53
|
+
/**
|
|
54
|
+
* Loosens a (strict) schema source type `T` into the type that a
|
|
55
|
+
* `resolveJsonModule` import of the backing `*.val.json` can actually satisfy.
|
|
56
|
+
*
|
|
57
|
+
* Why this is needed: TypeScript widens literals when it infers the type of a
|
|
58
|
+
* JSON module (e.g. `"a"` becomes `string`, `1` becomes `number`, and a branded
|
|
59
|
+
* `_type: "file"` becomes `_type: string`). A strict schema type (with literal
|
|
60
|
+
* unions, `RawString` brands, etc.) would therefore reject a perfectly valid
|
|
61
|
+
* JSON file. `JsonOf<T>` performs the same widening at the type level so the
|
|
62
|
+
* JSON content typechecks against the schema as strictly as JSON allows. Runtime
|
|
63
|
+
* validation enforces the rest.
|
|
64
|
+
*
|
|
65
|
+
* The transform distributes over unions and recurses through objects/arrays,
|
|
66
|
+
* preserving structure while widening every leaf literal. Val object-unions are
|
|
67
|
+
* always discriminated, so distribute-and-recurse is sufficient (the discriminant
|
|
68
|
+
* literal widens to its base type, but the per-variant shape stays distinct and a
|
|
69
|
+
* concrete JSON value still matches exactly one variant).
|
|
70
|
+
*/
|
|
71
|
+
export type JsonOf<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends null ? null : T extends undefined ? undefined : T extends readonly (infer E)[] ? JsonOf<E>[] : T extends object ? {
|
|
72
|
+
[K in keyof T]: JsonOf<T[K]>;
|
|
73
|
+
} : T;
|