@valbuild/core 0.102.0 → 0.105.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 +13 -11
- package/dist/declarations/src/initSchema.d.ts +27 -14
- package/dist/declarations/src/initVal.d.ts +0 -6
- package/dist/declarations/src/module.d.ts +1 -4
- package/dist/declarations/src/preview.d.ts +98 -0
- package/dist/declarations/src/render.d.ts +29 -93
- package/dist/declarations/src/schema/array.d.ts +22 -23
- package/dist/declarations/src/schema/boolean.d.ts +2 -2
- package/dist/declarations/src/schema/color.d.ts +2 -2
- package/dist/declarations/src/schema/date.d.ts +2 -2
- package/dist/declarations/src/schema/datetime.d.ts +2 -2
- package/dist/declarations/src/schema/file.d.ts +19 -19
- package/dist/declarations/src/schema/image.d.ts +17 -8
- package/dist/declarations/src/schema/index.d.ts +7 -7
- package/dist/declarations/src/schema/keyOf.d.ts +2 -2
- package/dist/declarations/src/schema/literal.d.ts +2 -2
- package/dist/declarations/src/schema/number.d.ts +2 -2
- package/dist/declarations/src/schema/object.d.ts +2 -2
- package/dist/declarations/src/schema/record.d.ts +19 -31
- package/dist/declarations/src/schema/remote.d.ts +0 -10
- package/dist/declarations/src/schema/richtext.d.ts +2 -2
- package/dist/declarations/src/schema/route.d.ts +2 -2
- package/dist/declarations/src/schema/string.d.ts +28 -17
- package/dist/declarations/src/schema/union.d.ts +2 -2
- package/dist/declarations/src/selector/SelectorProxy.d.ts +9 -2
- package/dist/declarations/src/selector/index.d.ts +3 -7
- package/dist/declarations/src/source/file.d.ts +6 -24
- package/dist/declarations/src/source/index.d.ts +3 -7
- package/dist/declarations/src/source/json.d.ts +1 -1
- package/dist/declarations/src/source/media.d.ts +98 -0
- package/dist/declarations/src/source/remote.d.ts +0 -14
- package/dist/declarations/src/source/richtext.d.ts +5 -7
- package/dist/declarations/src/val/index.d.ts +2 -5
- package/dist/{index-30ecb49c.cjs.dev.js → index-730a5254.cjs.dev.js} +980 -901
- package/dist/{index-796fd204.esm.js → index-d7cc2231.esm.js} +980 -900
- package/dist/{index-ca1bbeb2.cjs.prod.js → index-e990b6ad.cjs.prod.js} +980 -901
- package/dist/{result-4bd63123.esm.js → result-daff1cae.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +3 -4
- package/dist/valbuild-core.cjs.prod.js +3 -4
- package/dist/valbuild-core.esm.js +2 -2
- package/fp/dist/valbuild-core-fp.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 +3 -3
- package/dist/declarations/src/selector/file.d.ts +0 -10
- package/dist/declarations/src/selector/image.d.ts +0 -3
- package/dist/declarations/src/source/image.d.ts +0 -19
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ImageSource } from "../source/image.js";
|
|
2
|
+
import { GalleryImageSource, ImageSource } from "../source/media.js";
|
|
4
3
|
import { ModulePath, SourcePath } from "../val/index.js";
|
|
5
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
6
5
|
import { ValModule } from "../index.js";
|
|
7
|
-
import {
|
|
8
|
-
import { ReifiedRender } from "../render.js";
|
|
6
|
+
import { ReifiedPreview } from "../preview.js";
|
|
9
7
|
import { ImagesEntryMetadata } from "./images.js";
|
|
10
8
|
export type ImageOptions = {
|
|
11
9
|
ext?: ["jpg"] | ["webp"];
|
|
@@ -34,7 +32,7 @@ export type ImageMetadata = {
|
|
|
34
32
|
y: number;
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
|
-
export declare class ImageSchema<Src extends
|
|
35
|
+
export declare class ImageSchema<Src extends ImageSource | null> extends Schema<Src> {
|
|
38
36
|
private readonly options?;
|
|
39
37
|
private readonly opt;
|
|
40
38
|
protected readonly isRemote: boolean;
|
|
@@ -45,15 +43,26 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefine
|
|
|
45
43
|
private readonly description?;
|
|
46
44
|
constructor(options?: ImageOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], moduleMetadata?: Record<ModulePath, Record<string, ImagesEntryMetadata>>, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
|
|
47
45
|
describe(description: string | null): ImageSchema<Src>;
|
|
48
|
-
remote(): ImageSchema<Src
|
|
46
|
+
remote(): ImageSchema<Src>;
|
|
49
47
|
validate(validationFunction: CustomValidateFunction<Src>): ImageSchema<Src>;
|
|
50
48
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
49
|
+
/**
|
|
50
|
+
* The entries of the gallery this field points at, or null when it is a
|
|
51
|
+
* standalone field.
|
|
52
|
+
*/
|
|
53
|
+
private galleryEntries;
|
|
51
54
|
protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
|
52
55
|
nullable(): ImageSchema<Src | null>;
|
|
53
56
|
readonly(): ImageSchema<Src>;
|
|
54
57
|
hidden(): ImageSchema<Src>;
|
|
55
58
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
56
59
|
protected executeSerialize(): SerializedSchema;
|
|
57
|
-
protected
|
|
60
|
+
protected executePreview(): ReifiedPreview;
|
|
58
61
|
}
|
|
59
|
-
|
|
62
|
+
/**
|
|
63
|
+
* An image picked from a gallery. Its dimensions and mime type live in the
|
|
64
|
+
* gallery, so the field carries only what a person typed.
|
|
65
|
+
*/
|
|
66
|
+
export declare function image(galleryModule: ValModule<Record<string, ImagesEntryMetadata>>): ImageSchema<GalleryImageSource>;
|
|
67
|
+
/** An image of its own, carrying its own dimensions and mime type. */
|
|
68
|
+
export declare function image(options?: ImageOptions): ImageSchema<ImageSource>;
|
|
@@ -17,9 +17,9 @@ import { SerializedDateSchema } from "./date.js";
|
|
|
17
17
|
import { SerializedDateTimeSchema } from "./datetime.js";
|
|
18
18
|
import { SerializedRouteSchema } from "./route.js";
|
|
19
19
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
20
|
-
import { FileSource } from "../source/
|
|
20
|
+
import { FileSource } from "../source/media.js";
|
|
21
21
|
import { GenericRichTextSourceNode, RichTextSource } from "../source/richtext.js";
|
|
22
|
-
import {
|
|
22
|
+
import { ReifiedPreview, PreviewScope } from "../preview.js";
|
|
23
23
|
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedDateSchema | SerializedDateTimeSchema | SerializedColorSchema | SerializedRouteSchema | SerializedImageSchema;
|
|
24
24
|
type Primitives = number | string | boolean | null | FileSource;
|
|
25
25
|
export type AssertError = {
|
|
@@ -107,13 +107,13 @@ export declare abstract class Schema<Src extends SelectorSource> {
|
|
|
107
107
|
abstract hidden(): Schema<Src>;
|
|
108
108
|
protected abstract executeSerialize(): SerializedSchema;
|
|
109
109
|
/**
|
|
110
|
-
* @param scope Which paths the caller needs a
|
|
110
|
+
* @param scope Which paths the caller needs a preview for. Absent means the
|
|
111
111
|
* whole module, which is what every caller passed before scoping existed.
|
|
112
|
-
* See {@link
|
|
113
|
-
* wanted, and
|
|
114
|
-
* items are — which is the single-visible-row case.
|
|
112
|
+
* See {@link PreviewScope}: a container prunes recursion where nothing is
|
|
113
|
+
* wanted, and previews a WINDOW when its own path is not wanted but some of
|
|
114
|
+
* its items are — which is the single-visible-row case.
|
|
115
115
|
*/
|
|
116
|
-
protected abstract
|
|
116
|
+
protected abstract executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
117
117
|
/** MUTATES! since internal and perf sensitive */
|
|
118
118
|
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown, schemaError?: boolean): ValidationErrors;
|
|
119
119
|
/**
|
|
@@ -5,7 +5,7 @@ import { Source, SourceObject } from "../source/index.js";
|
|
|
5
5
|
import { SourcePath } from "../val/index.js";
|
|
6
6
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
7
7
|
import { RawString } from "./string.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ReifiedPreview } from "../preview.js";
|
|
9
9
|
export type SerializedKeyOfSchema = {
|
|
10
10
|
type: "keyOf";
|
|
11
11
|
path: SourcePath;
|
|
@@ -44,7 +44,7 @@ export declare class KeyOfSchema<Sel extends GenericSelector<SourceObject>, Src
|
|
|
44
44
|
hidden(): KeyOfSchema<Sel, Src>;
|
|
45
45
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
46
46
|
protected executeSerialize(): SerializedSchema;
|
|
47
|
-
protected
|
|
47
|
+
protected executePreview(): ReifiedPreview;
|
|
48
48
|
}
|
|
49
49
|
export declare const keyOf: <Src extends GenericSelector<SourceObject> & ValModuleBrand>(valModule: Src) => KeyOfSchema<Src, KeyOfSelector<Src>>;
|
|
50
50
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
export type SerializedLiteralSchema = {
|
|
@@ -28,6 +28,6 @@ export declare class LiteralSchema<Src extends string | null> extends Schema<Src
|
|
|
28
28
|
hidden(): LiteralSchema<Src>;
|
|
29
29
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
30
30
|
protected executeSerialize(): SerializedSchema;
|
|
31
|
-
protected
|
|
31
|
+
protected executePreview(): ReifiedPreview;
|
|
32
32
|
}
|
|
33
33
|
export declare const literal: <T extends string>(value: T) => LiteralSchema<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
type NumberOptions = {
|
|
@@ -34,7 +34,7 @@ export declare class NumberSchema<Src extends number | null> extends Schema<Src>
|
|
|
34
34
|
min(min: number): NumberSchema<Src>;
|
|
35
35
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
36
36
|
protected executeSerialize(): SerializedSchema;
|
|
37
|
-
protected
|
|
37
|
+
protected executePreview(): ReifiedPreview;
|
|
38
38
|
}
|
|
39
39
|
export declare const number: (options?: NumberOptions) => NumberSchema<number>;
|
|
40
40
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
3
|
import { SelectorSource } from "../selector/index.js";
|
|
4
4
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -52,7 +52,7 @@ export declare class ObjectSchema<Props extends ObjectSchemaProps, Src extends O
|
|
|
52
52
|
hidden(): ObjectSchema<Props, Src>;
|
|
53
53
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
54
54
|
protected executeSerialize(): SerializedSchema;
|
|
55
|
-
protected
|
|
55
|
+
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
56
56
|
}
|
|
57
57
|
export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => ObjectSchema<Props, ObjectSchemaSrcOf<Props>>;
|
|
58
58
|
export {};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PreviewItem, PreviewSelector, ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
3
|
import { ValRouter } from "../router.js";
|
|
4
4
|
import { SelectorSource } from "../selector/index.js";
|
|
5
|
-
import { ImageSource } from "../source/image.js";
|
|
6
5
|
import { JsonOf, JsonSource } from "../source/json.js";
|
|
7
|
-
import { RemoteSource } from "../source/remote.js";
|
|
8
6
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
9
|
-
import { ImageMetadata } from "./image.js";
|
|
10
7
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
11
8
|
type MediaOptions = {
|
|
12
9
|
type: "files" | "images";
|
|
@@ -20,8 +17,8 @@ export type SerializedRecordSchema = {
|
|
|
20
17
|
item: SerializedSchema;
|
|
21
18
|
key?: SerializedSchema;
|
|
22
19
|
opt: boolean;
|
|
23
|
-
/** Set when this schema declares a `
|
|
24
|
-
|
|
20
|
+
/** Set when this schema declares a `preview`. See `SerializedArraySchema`. */
|
|
21
|
+
preview?: true;
|
|
25
22
|
router?: string;
|
|
26
23
|
customValidate?: boolean;
|
|
27
24
|
mediaType?: "files" | "images";
|
|
@@ -48,17 +45,10 @@ export type SerializedRecordSchema = {
|
|
|
48
45
|
* authoring.
|
|
49
46
|
*/
|
|
50
47
|
export type JsonValuesRecordSrc<T extends Schema<SelectorSource>, K extends Schema<string>> = Record<SelectorOfSchema<K>, JsonSource<JsonOf<SelectorOfSchema<T>>> | SelectorOfSchema<T>>;
|
|
51
|
-
type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
val: RenderSelector<T>;
|
|
56
|
-
}) => {
|
|
57
|
-
title: string;
|
|
58
|
-
subtitle?: string | null;
|
|
59
|
-
image?: ImageSource | RemoteSource<ImageMetadata> | null;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
48
|
+
type RecordPreviewInput<T extends Schema<SelectorSource>> = (input: {
|
|
49
|
+
key: string;
|
|
50
|
+
val: PreviewSelector<T>;
|
|
51
|
+
}) => PreviewItem;
|
|
62
52
|
export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Schema<string>, Src extends Record<SelectorOfSchema<K>, SelectorOfSchema<T>> | JsonValuesRecordSrc<T, K> | null> extends Schema<Src> {
|
|
63
53
|
private readonly item;
|
|
64
54
|
private readonly opt;
|
|
@@ -71,10 +61,10 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
71
61
|
private readonly description?;
|
|
72
62
|
/** When true, entry values are lazily loaded {@link JsonSource} thunks. */
|
|
73
63
|
private readonly isJsonValues;
|
|
74
|
-
private readonly
|
|
64
|
+
private readonly previewInput;
|
|
75
65
|
constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], currentRouter?: ValRouter | null, keySchema?: Schema<string> | null, mediaOptions?: MediaOptions | undefined, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined,
|
|
76
66
|
/** When true, entry values are lazily loaded {@link JsonSource} thunks. */
|
|
77
|
-
isJsonValues?: boolean,
|
|
67
|
+
isJsonValues?: boolean, previewInput?: RecordPreviewInput<T> | null);
|
|
78
68
|
describe(description: string | null): RecordSchema<T, K, Src>;
|
|
79
69
|
validate(validationFunction: (src: Src) => false | string): RecordSchema<T, K, Src>;
|
|
80
70
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -115,18 +105,16 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
115
105
|
* defers).
|
|
116
106
|
*/
|
|
117
107
|
validateJsonEntryContent(path: SourcePath, content: SelectorSource): ValidationErrors;
|
|
118
|
-
protected
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
-
}): RecordSchema<T, K, Src>;
|
|
108
|
+
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
109
|
+
/**
|
|
110
|
+
* What the editor shows for each ENTRY of this record: a title, and optionally
|
|
111
|
+
* a subtitle and an image.
|
|
112
|
+
*
|
|
113
|
+
* `select` is your own code over the entry's key and source, so it is run on
|
|
114
|
+
* demand for the entries that are actually being looked at — see
|
|
115
|
+
* `PreviewScope`.
|
|
116
|
+
*/
|
|
117
|
+
preview(select: RecordPreviewInput<T>): RecordSchema<T, K, Src>;
|
|
130
118
|
}
|
|
131
119
|
export declare function record<K extends Schema<string>, S extends Schema<SelectorSource>>(key: K, schema: S): RecordSchema<S, K, Record<SelectorOfSchema<K>, SelectorOfSchema<S>>>;
|
|
132
120
|
export declare function record<S extends Schema<SelectorSource>>(schema: S): RecordSchema<S, Schema<string>, Record<string, SelectorOfSchema<S>>>;
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import { Json } from "../index.js";
|
|
2
|
-
import { RemoteSource } from "../source/remote.js";
|
|
3
1
|
export declare const DEFAULT_VAL_REMOTE_HOST = "https://remote.val.build";
|
|
4
|
-
export declare function convertRemoteSource<Metadata extends {
|
|
5
|
-
readonly [key: string]: Json;
|
|
6
|
-
} | undefined = {
|
|
7
|
-
readonly [key: string]: Json;
|
|
8
|
-
} | undefined>(src: RemoteSource<Metadata>): {
|
|
9
|
-
url: string;
|
|
10
|
-
metadata?: Metadata;
|
|
11
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { RichTextSource, RichTextOptions, SerializedRichTextOptions } from "../source/richtext.js";
|
|
4
4
|
import { SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -37,7 +37,7 @@ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichT
|
|
|
37
37
|
hidden(): RichTextSchema<O, Src>;
|
|
38
38
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
39
39
|
protected executeSerialize(): SerializedSchema;
|
|
40
|
-
protected
|
|
40
|
+
protected executePreview(): ReifiedPreview;
|
|
41
41
|
}
|
|
42
42
|
export declare const richtext: <O extends RichTextOptions>(options?: O) => RichTextSchema<O, RichTextSource<O>>;
|
|
43
43
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
2
|
import { SourcePath } from "../val/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ReifiedPreview } from "../preview.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
type RouteOptions = {
|
|
6
6
|
include?: RegExp;
|
|
@@ -68,7 +68,7 @@ export declare class RouteSchema<Src extends string | null> extends Schema<Src>
|
|
|
68
68
|
hidden(): RouteSchema<Src>;
|
|
69
69
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
70
70
|
protected executeSerialize(): SerializedSchema;
|
|
71
|
-
protected
|
|
71
|
+
protected executePreview(): ReifiedPreview;
|
|
72
72
|
}
|
|
73
73
|
export declare const route: <T extends string>(options?: Record<string, never>) => RouteSchema<T>;
|
|
74
74
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
|
+
import { StringRender } from "../render.js";
|
|
4
|
+
import { SourcePath } from "../val/index.js";
|
|
4
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
6
|
type StringOptions = {
|
|
6
7
|
maxLength?: number;
|
|
@@ -10,8 +11,16 @@ type StringOptions = {
|
|
|
10
11
|
};
|
|
11
12
|
export type SerializedStringSchema = {
|
|
12
13
|
type: "string";
|
|
13
|
-
/**
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* How this field is laid out in the editor, carried WHOLE rather than as a
|
|
16
|
+
* marker.
|
|
17
|
+
*
|
|
18
|
+
* A render is static configuration — no closure, no dependency on source — so
|
|
19
|
+
* unlike a `preview` it serializes in full, and the editor reads it straight
|
|
20
|
+
* off the schema it already has. See `render.ts` for what that assumption
|
|
21
|
+
* buys, and what to do if a render ever needs to stop being static.
|
|
22
|
+
*/
|
|
23
|
+
render?: StringRender;
|
|
15
24
|
options?: {
|
|
16
25
|
maxLength?: number;
|
|
17
26
|
minLength?: number;
|
|
@@ -42,12 +51,7 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
|
|
|
42
51
|
private readonly isReadonly;
|
|
43
52
|
private readonly isHidden;
|
|
44
53
|
private readonly description?;
|
|
45
|
-
constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], renderInput?:
|
|
46
|
-
as: "textarea";
|
|
47
|
-
} | {
|
|
48
|
-
as: "code";
|
|
49
|
-
language: CodeLanguage;
|
|
50
|
-
} | null, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
|
|
54
|
+
constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], renderInput?: StringRender | null, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
|
|
51
55
|
describe(description: string | null): StringSchema<Src>;
|
|
52
56
|
/**
|
|
53
57
|
* @deprecated Use `minLength` instead
|
|
@@ -69,13 +73,20 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
|
|
|
69
73
|
raw(): StringSchema<Src extends null ? RawString | null : RawString>;
|
|
70
74
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
71
75
|
protected executeSerialize(): SerializedSchema;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
/**
|
|
77
|
+
* How this field is laid out in the editor: a textarea, or a code editor for
|
|
78
|
+
* the given language.
|
|
79
|
+
*
|
|
80
|
+
* Static configuration, not a callback — see `render.ts`. What a CONTAINER
|
|
81
|
+
* shows for its items is a `preview`, which is a different thing entirely.
|
|
82
|
+
*/
|
|
83
|
+
render(input: StringRender): StringSchema<Src>;
|
|
84
|
+
/**
|
|
85
|
+
* Nothing: a string has no items, so there is nothing to preview. Its layout
|
|
86
|
+
* is a `render`, which travels in the serialized schema instead of through
|
|
87
|
+
* this pipeline.
|
|
88
|
+
*/
|
|
89
|
+
protected executePreview(): ReifiedPreview;
|
|
79
90
|
}
|
|
80
91
|
export declare const string: <T extends string>(options?: Record<string, never>) => StringSchema<T>;
|
|
81
92
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
3
|
import { SelectorSource } from "../selector/index.js";
|
|
4
4
|
import { SourceObject } from "../source/index.js";
|
|
5
5
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
@@ -57,7 +57,7 @@ export declare class UnionSchema<Key extends string | Schema<string>, T extends
|
|
|
57
57
|
private matchedVariant;
|
|
58
58
|
protected executeSerialize(): SerializedSchema;
|
|
59
59
|
constructor(key: Key, items: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
|
|
60
|
-
protected
|
|
60
|
+
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
61
61
|
}
|
|
62
62
|
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>>;
|
|
63
63
|
export {};
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { GenericSelector } from "./index.js";
|
|
2
2
|
import { Source } from "../source/index.js";
|
|
3
|
-
import { ModulePath, SourcePath } from "../val/index.js";
|
|
3
|
+
import { ModuleFilePath, ModulePath, SourcePath } from "../val/index.js";
|
|
4
4
|
export declare function isSelector(source: any): source is GenericSelector<Source>;
|
|
5
5
|
export declare function newSelectorProxy(source: any, path?: SourcePath, moduleSchema?: any): any;
|
|
6
|
-
export declare function createValPathOfItem(
|
|
6
|
+
export declare function createValPathOfItem(
|
|
7
|
+
/**
|
|
8
|
+
* `ModuleFilePath` is accepted because the no-separator branch below is
|
|
9
|
+
* exactly that case: a path with no `?p=` yet gets one, and the key becomes
|
|
10
|
+
* the first module-path segment. Callers walking a module from its root had
|
|
11
|
+
* to widen the type themselves, and hand-rolled the concatenation instead.
|
|
12
|
+
*/
|
|
13
|
+
arrayPath: SourcePath | ModulePath | ModuleFilePath | undefined, prop: string | number | symbol): SourcePath | undefined;
|
|
7
14
|
export declare function unsafeCreateSourcePath(path: string, itemKey: string | number | symbol): SourcePath;
|
|
8
15
|
export declare function selectorToVal(s: any): any;
|
|
@@ -4,22 +4,18 @@ import { Selector as NumberSelector } from "./number.js";
|
|
|
4
4
|
import { Selector as StringSelector } from "./string.js";
|
|
5
5
|
import { Selector as BooleanSelector } from "./boolean.js";
|
|
6
6
|
import { Selector as PrimitiveSelector } from "./primitive.js";
|
|
7
|
-
import { FileSelector } from "./file.js";
|
|
8
7
|
import { SourcePath } from "../val/index.js";
|
|
9
8
|
import { Source, SourceArray, SourceObject, SourcePrimitive } from "../source/index.js";
|
|
10
9
|
import { Schema } from "../schema/index.js";
|
|
11
10
|
import type { A } from "ts-toolbelt";
|
|
12
|
-
import {
|
|
11
|
+
import { MediaSource } from "../source/media.js";
|
|
13
12
|
import { AllRichTextOptions, RichTextSource } from "../source/richtext.js";
|
|
14
|
-
import { ImageSelector } from "./image.js";
|
|
15
13
|
import { RichTextSelector } from "./richtext.js";
|
|
16
|
-
import { ImageSource } from "../source/image.js";
|
|
17
|
-
import { RemoteSource } from "../source/remote.js";
|
|
18
14
|
import { JsonSource } from "../source/json.js";
|
|
19
|
-
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends
|
|
15
|
+
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends MediaSource ? GenericSelector<T> : 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;
|
|
20
16
|
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
|
21
17
|
[key: string]: SelectorSource;
|
|
22
|
-
} |
|
|
18
|
+
} | MediaSource | JsonSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
|
|
23
19
|
/**
|
|
24
20
|
* @internal
|
|
25
21
|
*/
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import { VAL_EXTENSION } from "./index.js";
|
|
2
|
-
import { ValConfig } from "../initVal.js";
|
|
3
|
-
import { Json } from "../Json.js";
|
|
4
|
-
export declare const FILE_REF_PROP: "_ref";
|
|
5
|
-
export declare const FILE_REF_SUBTYPE_TAG: "_tag";
|
|
6
|
-
export type FileMetadata = {
|
|
7
|
-
mimeType?: string;
|
|
8
|
-
};
|
|
9
1
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* It will be resolved into a Asset object.
|
|
2
|
+
* What Val computes from a file's bytes.
|
|
13
3
|
*
|
|
4
|
+
* Not part of the source any more — a media source carries these fields
|
|
5
|
+
* directly — but still the unit the upload and `--fix` pipelines work in:
|
|
6
|
+
* "here is what reading this file told us".
|
|
14
7
|
*/
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
readonly [VAL_EXTENSION]: "file";
|
|
18
|
-
readonly [FILE_REF_SUBTYPE_TAG]?: string;
|
|
19
|
-
readonly metadata?: Metadata;
|
|
20
|
-
readonly patch_id?: string;
|
|
21
|
-
};
|
|
22
|
-
export declare const initFile: (config?: ValConfig) => {
|
|
23
|
-
<Metadata extends {
|
|
24
|
-
readonly [key: string]: Json;
|
|
25
|
-
}>(ref: `${import("../initVal.js").ConfigDirectory}/${string}`, metadata: Metadata): FileSource<Metadata>;
|
|
26
|
-
(ref: `${import("../initVal.js").ConfigDirectory}/${string}`, metadata?: undefined): FileSource<undefined>;
|
|
8
|
+
export type FileMetadata = {
|
|
9
|
+
mimeType?: string;
|
|
27
10
|
};
|
|
28
|
-
export declare function isFile(obj: unknown): obj is FileSource;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { FileSource } from "./file.js";
|
|
2
|
-
import { ImageSource } from "./image.js";
|
|
3
1
|
import { JsonSource } from "./json.js";
|
|
4
|
-
import {
|
|
2
|
+
import { MediaSource } from "./media.js";
|
|
5
3
|
import { RichTextOptions, RichTextSource } from "./richtext.js";
|
|
6
|
-
export type Source = SourcePrimitive | SourceObject | SourceArray |
|
|
4
|
+
export type Source = SourcePrimitive | SourceObject | SourceArray | MediaSource | JsonSource | RichTextSource<RichTextOptions>;
|
|
7
5
|
export type SourceObject = {
|
|
8
6
|
[key in string]: Source;
|
|
9
7
|
} & {
|
|
@@ -14,8 +12,6 @@ export type SourceObject = {
|
|
|
14
12
|
/** Reserved name */
|
|
15
13
|
andThen?: never;
|
|
16
14
|
/** Reserved name */
|
|
17
|
-
_ref?: never;
|
|
18
|
-
/** Reserved name */
|
|
19
15
|
_type?: never;
|
|
20
16
|
/** Reserved name */
|
|
21
17
|
val?: never;
|
|
@@ -25,7 +21,7 @@ export type SourceObject = {
|
|
|
25
21
|
export type SourceArray = readonly Source[];
|
|
26
22
|
export type SourcePrimitive = string | number | boolean | null;
|
|
27
23
|
export declare const VAL_EXTENSION: "_type";
|
|
28
|
-
export declare function getValExtension(source: Source): false | "" | 0 | "
|
|
24
|
+
export declare function getValExtension(source: Source): false | "" | 0 | "json" | null | undefined;
|
|
29
25
|
/**
|
|
30
26
|
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
|
31
27
|
*
|
|
@@ -30,7 +30,7 @@ export type JsonImportThunk<T = unknown> = () => Promise<{
|
|
|
30
30
|
*/
|
|
31
31
|
export type JsonSource<T = unknown> = {
|
|
32
32
|
readonly [VAL_EXTENSION]: typeof JSON_VAL_EXTENSION_TAG;
|
|
33
|
-
/** Set on uncommitted/draft entries (mirrors
|
|
33
|
+
/** Set on uncommitted/draft entries (mirrors a media source's). */
|
|
34
34
|
readonly patch_id?: string;
|
|
35
35
|
} & PhantomType<T>;
|
|
36
36
|
export declare function json<T = Json>(importThunk: JsonImportThunk<T>): JsonSource<T>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media — images and files — is a plain object carrying a `path`.
|
|
3
|
+
*
|
|
4
|
+
* There is no marker on the value: nothing may decide "this is an image" by
|
|
5
|
+
* looking at it. The **schema** says so (`type === "image" | "file"`), which is
|
|
6
|
+
* what lets the same object be written in a `.val.ts` and in a `*.val.json`
|
|
7
|
+
* entry, where a function call cannot be written at all.
|
|
8
|
+
*
|
|
9
|
+
* `path` is a plain `string` rather than a `` `/public/${string}` `` template so
|
|
10
|
+
* a field can move between local and remote without a type error. Remote-ness
|
|
11
|
+
* is read off the path: anything not under `/public` is remote.
|
|
12
|
+
*/
|
|
13
|
+
/** What must stay in frame when a page crops an image. */
|
|
14
|
+
export type MediaHotspot = {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The authored fields of a gallery-backed image (`s.image(galleryModule)`):
|
|
20
|
+
* `width`/`height`/`mimeType` live in the gallery, so they are not repeated
|
|
21
|
+
* here. One place per fact.
|
|
22
|
+
*/
|
|
23
|
+
export type GalleryImageSource = {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly alt?: string;
|
|
26
|
+
readonly hotspot?: MediaHotspot;
|
|
27
|
+
/**
|
|
28
|
+
* Set on a source whose bytes are not committed yet. Injected server-side and
|
|
29
|
+
* consumed only by {@link mediaUrl} — never written to a `.val.ts`.
|
|
30
|
+
*/
|
|
31
|
+
readonly patch_id?: string;
|
|
32
|
+
};
|
|
33
|
+
export type ImageSource = GalleryImageSource & {
|
|
34
|
+
readonly width?: number;
|
|
35
|
+
readonly height?: number;
|
|
36
|
+
readonly mimeType?: string;
|
|
37
|
+
};
|
|
38
|
+
export type GalleryFileSource = {
|
|
39
|
+
readonly path: string;
|
|
40
|
+
readonly patch_id?: string;
|
|
41
|
+
};
|
|
42
|
+
export type FileSource = GalleryFileSource & {
|
|
43
|
+
readonly mimeType?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The structural supertype of every media source.
|
|
47
|
+
*
|
|
48
|
+
* It is a named member of the `Source` / `SelectorSource` unions rather than
|
|
49
|
+
* "just an object" because `SourceObject` is `{[key: string]: Source}` and
|
|
50
|
+
* `Source` excludes `undefined` — an object with optional properties does not
|
|
51
|
+
* satisfy it.
|
|
52
|
+
*/
|
|
53
|
+
export type MediaSource = ImageSource;
|
|
54
|
+
/** A path is remote unless it is under `/public`. */
|
|
55
|
+
export declare function isRemoteMediaPath(path: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Where the bytes of a media source are actually served from.
|
|
58
|
+
*
|
|
59
|
+
* Two states, and conflating them is the recurring bug: uncommitted bytes live
|
|
60
|
+
* in the patch directory and are served by the API with the `patch_id` that put
|
|
61
|
+
* them there; committed bytes live at the path itself, with `/public` stripped.
|
|
62
|
+
*/
|
|
63
|
+
export declare function mediaUrl(src: {
|
|
64
|
+
readonly path: string;
|
|
65
|
+
readonly patch_id?: string;
|
|
66
|
+
}): string;
|
|
67
|
+
/**
|
|
68
|
+
* A media source plus the URL its bytes are served from.
|
|
69
|
+
*
|
|
70
|
+
* `url` is the only generated field: everything else the consumer sees was
|
|
71
|
+
* either authored or filled in from the gallery.
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveMedia<S extends {
|
|
74
|
+
readonly path: string;
|
|
75
|
+
}>(src: S): S & {
|
|
76
|
+
url: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Fill in what a gallery-backed field does not carry itself.
|
|
80
|
+
*
|
|
81
|
+
* `s.image(galleryModule)` stores only `{path, alt?, hotspot?}` — the
|
|
82
|
+
* dimensions and mime type live in the gallery module, keyed by path. This is
|
|
83
|
+
* the single implementation of that lookup; core, stega/RSC and the Studio all
|
|
84
|
+
* call it rather than each rolling their own.
|
|
85
|
+
*
|
|
86
|
+
* `alt` is filled in too, because a gallery holds the alt text an editor typed
|
|
87
|
+
* once for a file used in several places — but only when the field does not
|
|
88
|
+
* have its own, so a per-image override wins. A gallery whose `alt` schema is a
|
|
89
|
+
* locale record holds an object rather than a string; that is left alone rather
|
|
90
|
+
* than copied into a field typed `string`, and making the override
|
|
91
|
+
* locale-shaped is a separate change.
|
|
92
|
+
*
|
|
93
|
+
* The double lookup is load-bearing: a remote gallery keys its entries by the
|
|
94
|
+
* remote URL while the file itself stays on disk under its local path.
|
|
95
|
+
*/
|
|
96
|
+
export declare function fillFromGallery<S extends {
|
|
97
|
+
readonly path: string;
|
|
98
|
+
}>(src: S, schema: unknown, getModuleSource: (modulePath: string) => unknown): S;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
import { VAL_EXTENSION } from "./index.js";
|
|
2
|
-
import { ValConfig } from "../initVal.js";
|
|
3
|
-
import { ImageMetadata } from "../schema/image.js";
|
|
4
|
-
import { FILE_REF_PROP, FileMetadata } from "./file.js";
|
|
5
|
-
/**
|
|
6
|
-
* A remote source represents data that is not stored locally.
|
|
7
|
-
*/
|
|
8
|
-
export type RemoteSource<Metadata extends FileMetadata | undefined = FileMetadata | undefined> = {
|
|
9
|
-
readonly [FILE_REF_PROP]: string;
|
|
10
|
-
readonly [VAL_EXTENSION]: "remote";
|
|
11
|
-
readonly metadata?: Metadata;
|
|
12
|
-
readonly patch_id?: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const initRemote: (config?: ValConfig) => <Metadata extends FileMetadata | ImageMetadata>(ref: RemoteRef, metadata?: Metadata) => RemoteSource<Metadata>;
|
|
15
1
|
export type RemoteRef = `${string}/file/p/${string}/b/${string}/v/${string}/h/${string}/f/${string}/p/public/${string}`;
|
|
16
2
|
export declare function createRemoteRef(remoteHost: string, { publicProjectId, coreVersion, validationHash, fileHash, filePath, bucket, }: {
|
|
17
3
|
publicProjectId: string;
|