@valbuild/core 0.102.0 → 0.103.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 +11 -10
- 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/render.d.ts +3 -5
- package/dist/declarations/src/schema/array.d.ts +1 -1
- package/dist/declarations/src/schema/file.d.ts +17 -17
- package/dist/declarations/src/schema/image.d.ts +15 -6
- package/dist/declarations/src/schema/index.d.ts +1 -1
- package/dist/declarations/src/schema/record.d.ts +3 -5
- package/dist/declarations/src/schema/remote.d.ts +0 -10
- 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-796fd204.esm.js → index-267a8e9c.esm.js} +847 -804
- package/dist/{index-30ecb49c.cjs.dev.js → index-2e40f2ae.cjs.dev.js} +845 -804
- package/dist/{index-ca1bbeb2.cjs.prod.js → index-3572060f.cjs.prod.js} +845 -804
- package/dist/{result-4bd63123.esm.js → result-daff1cae.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +1 -3
- package/dist/valbuild-core.cjs.prod.js +1 -3
- 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
|
@@ -8,18 +8,18 @@ export type { ImageMetadata } from "./schema/image.js";
|
|
|
8
8
|
export type { FileMetadata } from "./schema/file.js";
|
|
9
9
|
export type { ValModule, SerializedModule, InferValModuleType } from "./module.js";
|
|
10
10
|
export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
|
|
11
|
-
export type { FileSource } from "./source/
|
|
11
|
+
export type { FileSource } from "./source/media.js";
|
|
12
12
|
export type { JsonSource, JsonOf, JsonImportThunk } from "./source/json.js";
|
|
13
|
-
export type {
|
|
13
|
+
export type { RemoteRef } from "./source/remote.js";
|
|
14
14
|
export { DEFAULT_VAL_REMOTE_HOST } from "./schema/remote.js";
|
|
15
15
|
export type { RawString } from "./schema/string.js";
|
|
16
|
-
export type { ImageSource } from "./source/
|
|
16
|
+
export type { ImageSource } from "./source/media.js";
|
|
17
|
+
export type { MediaHotspot, MediaSource, GalleryImageSource, GalleryFileSource, } from "./source/media.js";
|
|
17
18
|
export type { AllRichTextOptions, Bold, Styles, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, LinkNode, OrderedListNode, ParagraphNode, BrNode, RichTextNode, RichTextOptions, SerializedRichTextOptions, RichTextSource, BlockNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
|
|
18
19
|
export { type Val, type SerializedVal, type ModuleFilePath, type PatchId, type ModulePath, type SourcePath, type JsonOfSource, type ParentPatchId, } from "./val/index.js";
|
|
19
20
|
export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json.js";
|
|
20
21
|
export type { ValidationError, ValidationErrors, } from "./schema/validation/ValidationError.js";
|
|
21
22
|
export type { ValidationFix } from "./schema/validation/ValidationFix.js";
|
|
22
|
-
export { FILE_REF_PROP, FILE_REF_SUBTYPE_TAG } from "./source/file.js";
|
|
23
23
|
export { VAL_EXTENSION, type SourceArray } from "./source/index.js";
|
|
24
24
|
export { derefPatch } from "./patch/deref.js";
|
|
25
25
|
export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector/index.js";
|
|
@@ -28,20 +28,18 @@ declare const ModuleFilePathSep = "?p=";
|
|
|
28
28
|
export { ModuleFilePathSep };
|
|
29
29
|
import { SelectorSource, getSchema } from "./selector/index.js";
|
|
30
30
|
import { ModulePath, SourcePath, getValPath, isVal } from "./val/index.js";
|
|
31
|
-
import { convertFileSource } from "./schema/file.js";
|
|
32
31
|
import { createValPathOfItem } from "./selector/SelectorProxy.js";
|
|
33
32
|
import { Operation } from "./patch/index.js";
|
|
34
33
|
import { initSchema } from "./initSchema.js";
|
|
35
34
|
import { getMimeType, mimeTypeToFileExt, filenameToMimeType } from "./mimeType/index.js";
|
|
36
35
|
import { type ImageMetadata } from "./schema/image.js";
|
|
37
36
|
import { type FileMetadata } from "./schema/file.js";
|
|
38
|
-
import { isFile } from "./source/file.js";
|
|
39
37
|
import { isJson, getJsonImport, resolveJsonValues } from "./source/json.js";
|
|
40
38
|
import { createRemoteRef } from "./source/remote.js";
|
|
41
39
|
import { getValidationBasis, getValidationHash } from "./remote/validationBasis.js";
|
|
42
40
|
import { getFileHash, hashToRemoteFileHash } from "./remote/fileHash.js";
|
|
43
41
|
import { splitRemoteRef } from "./remote/splitRemoteRef.js";
|
|
44
|
-
import {
|
|
42
|
+
import { fillFromGallery, isRemoteMediaPath, mediaUrl, resolveMedia } from "./source/media.js";
|
|
45
43
|
import { colorToHex, convertColor, detectColorFormat, formatColor, parseColor } from "./schema/colorFormat.js";
|
|
46
44
|
export { type SerializedArraySchema, ArraySchema } from "./schema/array.js";
|
|
47
45
|
export { type SerializedObjectSchema, ObjectSchema } from "./schema/object.js";
|
|
@@ -72,8 +70,12 @@ declare const Internal: {
|
|
|
72
70
|
VERSION: {
|
|
73
71
|
core: string | null;
|
|
74
72
|
};
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
mediaUrl: typeof mediaUrl;
|
|
74
|
+
resolveMedia: typeof resolveMedia;
|
|
75
|
+
isRemoteMediaPath: typeof isRemoteMediaPath;
|
|
76
|
+
media: {
|
|
77
|
+
fillFromGallery: typeof fillFromGallery;
|
|
78
|
+
};
|
|
77
79
|
getSchema: typeof getSchema;
|
|
78
80
|
getValPath: typeof getValPath;
|
|
79
81
|
getSource: typeof getSource;
|
|
@@ -100,7 +102,6 @@ declare const Internal: {
|
|
|
100
102
|
};
|
|
101
103
|
validate: (val: ValModule<SelectorSource>, path: SourcePath, src: unknown) => import("./schema/validation/ValidationError.js").ValidationErrors | undefined;
|
|
102
104
|
isVal: typeof isVal;
|
|
103
|
-
isFile: typeof isFile;
|
|
104
105
|
isJson: typeof isJson;
|
|
105
106
|
getJsonImport: typeof getJsonImport;
|
|
106
107
|
resolveJsonValues: typeof resolveJsonValues;
|
|
@@ -99,19 +99,28 @@ export type InitSchema = {
|
|
|
99
99
|
/**
|
|
100
100
|
* Define an image.
|
|
101
101
|
*
|
|
102
|
-
*
|
|
102
|
+
* An image is an object with a `path`. `width`, `height` and `mimeType` are
|
|
103
|
+
* read from the file — the VS Code extension fills them in as you type the
|
|
104
|
+
* path, and `npx val validate --fix` adds any that are missing. `alt` and
|
|
105
|
+
* `hotspot` are yours to set.
|
|
103
106
|
*
|
|
104
107
|
* @example
|
|
105
108
|
* const schema = s.image();
|
|
106
|
-
* export default c.define("/example.val.ts", schema,
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
109
|
+
* export default c.define("/example.val.ts", schema, {
|
|
110
|
+
* path: "/public/val/example.png",
|
|
111
|
+
* width: 100,
|
|
112
|
+
* height: 100,
|
|
113
|
+
* mimeType: "image/png",
|
|
114
|
+
* alt: "An example",
|
|
115
|
+
* hotspot: { x: 0.5, y: 0.5 },
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* // Backed by a gallery: width, height and mimeType live there.
|
|
120
|
+
* const schema = s.image(galleryVal);
|
|
121
|
+
* export default c.define("/example.val.ts", schema, {
|
|
122
|
+
* path: "/public/val/example.png",
|
|
123
|
+
* });
|
|
115
124
|
*
|
|
116
125
|
*/
|
|
117
126
|
readonly image: typeof image;
|
|
@@ -146,11 +155,15 @@ export type InitSchema = {
|
|
|
146
155
|
/**
|
|
147
156
|
* Define a file.
|
|
148
157
|
*
|
|
149
|
-
*
|
|
158
|
+
* A file is an object with a `path`. `mimeType` comes from the extension —
|
|
159
|
+
* `npx val validate --fix` adds it.
|
|
150
160
|
*
|
|
151
161
|
* @example
|
|
152
162
|
* const schema = s.file();
|
|
153
|
-
* export default c.define("/example.val.ts", schema,
|
|
163
|
+
* export default c.define("/example.val.ts", schema, {
|
|
164
|
+
* path: "/public/val/example.pdf",
|
|
165
|
+
* mimeType: "application/pdf",
|
|
166
|
+
* });
|
|
154
167
|
*
|
|
155
168
|
*/
|
|
156
169
|
readonly file: typeof file;
|
|
@@ -291,11 +304,11 @@ export declare function initSchema(): {
|
|
|
291
304
|
}) => import("./schema/number.js").NumberSchema<number>;
|
|
292
305
|
union: <Key extends string | import("./schema/index.js").Schema<string>, T extends import("./schema/index.js").Schema<Key extends string ? import("./source/index.js").SourceObject & { [k in Key]: string; } : Key extends import("./schema/index.js").Schema<string> ? string : unknown>[]>(key: Key, ...objects: T) => import("./schema/union.js").UnionSchema<Key, T, T extends import("./schema/index.js").Schema<infer S extends import("./selector/index.js").SelectorSource>[] ? S extends import("./selector/index.js").SelectorSource ? S | (Key extends import("./schema/index.js").Schema<infer K extends import("./selector/index.js").SelectorSource> ? K : never) : never : never>;
|
|
293
306
|
richtext: <O extends import("./index.js").RichTextOptions>(options?: O) => import("./schema/richtext.js").RichTextSchema<O, import("./index.js").RichTextSource<O>>;
|
|
294
|
-
image:
|
|
307
|
+
image: typeof image;
|
|
295
308
|
literal: <T extends string>(value: T) => import("./schema/literal.js").LiteralSchema<T>;
|
|
296
309
|
keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/keyOf.js").KeyOfSchema<Src, Src extends import("./selector/index.js").GenericSelector<infer S extends import("./source/index.js").Source, undefined> ? S extends readonly import("./source/index.js").Source[] ? number : S extends import("./source/index.js").SourceObject ? string extends keyof S ? import("./schema/string.js").RawString : keyof S : S extends Record<string, import("./source/index.js").Source> ? import("./schema/string.js").RawString : never : never>;
|
|
297
310
|
record: typeof record;
|
|
298
|
-
file:
|
|
311
|
+
file: typeof file;
|
|
299
312
|
files: (options: import("./schema/files.js").FilesOptions) => import("./schema/record.js").RecordSchema<import("./schema/object.js").ObjectSchema<{
|
|
300
313
|
mimeType: import("./schema/string.js").StringSchema<string>;
|
|
301
314
|
}, {
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { define } from "./module.js";
|
|
2
2
|
import { InitSchema } from "./initSchema.js";
|
|
3
3
|
import { getValPath as getPath } from "./val/index.js";
|
|
4
|
-
import { initFile } from "./source/file.js";
|
|
5
|
-
import { initImage } from "./source/image.js";
|
|
6
4
|
import { json } from "./source/json.js";
|
|
7
|
-
import { initRemote } from "./source/remote.js";
|
|
8
5
|
export type ContentConstructor = {
|
|
9
6
|
define: typeof define;
|
|
10
|
-
file: ReturnType<typeof initFile>;
|
|
11
|
-
image: ReturnType<typeof initImage>;
|
|
12
|
-
remote: ReturnType<typeof initRemote>;
|
|
13
7
|
json: typeof json;
|
|
14
8
|
};
|
|
15
9
|
export type ValConstructor = {
|
|
@@ -4,22 +4,19 @@ import { Source } from "./source/index.js";
|
|
|
4
4
|
import { ModuleFilePath, ModulePath, SourcePath } from "./val/index.js";
|
|
5
5
|
import { Json } from "./Json.js";
|
|
6
6
|
import { RawString } from "./schema/string.js";
|
|
7
|
-
import { ImageSelector } from "./selector/image.js";
|
|
8
|
-
import { ImageSource } from "./source/image.js";
|
|
9
7
|
declare const brand: unique symbol;
|
|
10
8
|
export type ValModule<T extends SelectorSource> = SelectorOf<T> & ValModuleBrand;
|
|
11
9
|
export type ValModuleBrand = {
|
|
12
10
|
[brand]: "ValModule";
|
|
13
11
|
};
|
|
14
12
|
export type InferValModuleType<T extends ValModule<SelectorSource>> = T extends GenericSelector<infer S> ? S : never;
|
|
15
|
-
export type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends
|
|
13
|
+
export type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends {
|
|
16
14
|
[key in string]: SelectorSource;
|
|
17
15
|
} ? {
|
|
18
16
|
[key in keyof T]: ReplaceRawStringWithString<T[key]>;
|
|
19
17
|
} : T extends SelectorSource[] ? ReplaceRawStringWithString<T[number]>[] : T;
|
|
20
18
|
export declare function define<T extends Schema<SelectorSource>>(id: string, // TODO: `/${string}`
|
|
21
19
|
schema: T, source: ReplaceRawStringWithString<SelectorOfSchema<T>>): ValModule<SelectorOfSchema<T>>;
|
|
22
|
-
export declare function enrichFileImageRemoteSourceWithMetadata<T extends SelectorSource>(source: T, schema: Schema<SelectorSource>): T;
|
|
23
20
|
export declare function getSource<T extends Source>(valModule: ValModule<T>): T;
|
|
24
21
|
export declare function splitModuleFilePathAndModulePath(path: SourcePath | ModuleFilePath): [moduleId: ModuleFilePath, path: ModulePath];
|
|
25
22
|
export declare function joinModuleFilePathAndModulePath(moduleFilePath: ModuleFilePath, modulePath: ModulePath): SourcePath;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Schema } from "./schema/index.js";
|
|
2
|
-
import { ImageMetadata } from "./schema/image.js";
|
|
3
2
|
import { SelectorSource } from "./selector/index.js";
|
|
4
|
-
import { ImageSource } from "./source/
|
|
5
|
-
import { RemoteSource } from "./source/remote.js";
|
|
3
|
+
import { ImageSource } from "./source/media.js";
|
|
6
4
|
import { ModuleFilePath, SourcePath } from "./val/index.js";
|
|
7
5
|
export type ListRecordRender = {
|
|
8
6
|
layout: "list";
|
|
@@ -12,7 +10,7 @@ export type ListRecordRender = {
|
|
|
12
10
|
value: {
|
|
13
11
|
title: string;
|
|
14
12
|
subtitle?: string | null;
|
|
15
|
-
image?: ImageSource |
|
|
13
|
+
image?: ImageSource | null;
|
|
16
14
|
}
|
|
17
15
|
][];
|
|
18
16
|
};
|
|
@@ -35,7 +33,7 @@ export type ListArrayRender = {
|
|
|
35
33
|
value: {
|
|
36
34
|
title: string;
|
|
37
35
|
subtitle?: string | null;
|
|
38
|
-
image?: ImageSource |
|
|
36
|
+
image?: ImageSource | null;
|
|
39
37
|
}
|
|
40
38
|
][];
|
|
41
39
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
2
|
import { RenderSelector, ReifiedRender, RenderScope } from "../render.js";
|
|
3
3
|
import { SelectorSource } from "../selector/index.js";
|
|
4
|
-
import { ImageSource } from "../source/
|
|
4
|
+
import { ImageSource } from "../source/media.js";
|
|
5
5
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
6
6
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
7
7
|
export type SerializedArraySchema = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { FileSource, GalleryFileSource } from "../source/media.js";
|
|
2
|
+
export type { FileMetadata } from "../source/file.js";
|
|
3
3
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
4
4
|
import { ModulePath, SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ValModule } from "../index.js";
|
|
7
7
|
import { ReifiedRender } from "../render.js";
|
|
8
8
|
import { FilesEntryMetadata } from "./files.js";
|
|
9
9
|
export type FileOptions = {
|
|
@@ -20,10 +20,7 @@ export type SerializedFileSchema = {
|
|
|
20
20
|
hidden?: boolean;
|
|
21
21
|
description?: string;
|
|
22
22
|
};
|
|
23
|
-
export
|
|
24
|
-
mimeType?: string;
|
|
25
|
-
};
|
|
26
|
-
export declare class FileSchema<Src extends FileSource<FileMetadata | undefined> | RemoteSource<FileMetadata | undefined> | null> extends Schema<Src> {
|
|
23
|
+
export declare class FileSchema<Src extends FileSource | null> extends Schema<Src> {
|
|
27
24
|
private readonly options?;
|
|
28
25
|
private readonly opt;
|
|
29
26
|
protected readonly isRemote: boolean;
|
|
@@ -34,9 +31,14 @@ export declare class FileSchema<Src extends FileSource<FileMetadata | undefined>
|
|
|
34
31
|
private readonly description?;
|
|
35
32
|
constructor(options?: FileOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], moduleMetadata?: Record<ModulePath, Record<string, FilesEntryMetadata>>, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
|
|
36
33
|
describe(description: string | null): FileSchema<Src>;
|
|
37
|
-
remote(): FileSchema<Src
|
|
34
|
+
remote(): FileSchema<Src>;
|
|
38
35
|
validate(validationFunction: CustomValidateFunction<Src>): FileSchema<Src>;
|
|
39
36
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
37
|
+
/**
|
|
38
|
+
* The entries of the gallery this field points at, or null when it is a
|
|
39
|
+
* standalone field.
|
|
40
|
+
*/
|
|
41
|
+
private galleryEntries;
|
|
40
42
|
protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
|
41
43
|
nullable(): FileSchema<Src | null>;
|
|
42
44
|
readonly(): FileSchema<Src>;
|
|
@@ -45,12 +47,10 @@ export declare class FileSchema<Src extends FileSource<FileMetadata | undefined>
|
|
|
45
47
|
protected executeSerialize(): SerializedSchema;
|
|
46
48
|
protected executeRender(): ReifiedRender;
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
metadata?: Metadata;
|
|
56
|
-
};
|
|
50
|
+
/**
|
|
51
|
+
* A file picked from a gallery. Its mime type lives in the gallery, so the
|
|
52
|
+
* field carries only the path.
|
|
53
|
+
*/
|
|
54
|
+
export declare function file(galleryModule: ValModule<Record<string, FilesEntryMetadata>>): FileSchema<GalleryFileSource>;
|
|
55
|
+
/** A file of its own, carrying its own mime type. */
|
|
56
|
+
export declare function file(options?: FileOptions): FileSchema<FileSource>;
|
|
@@ -1,10 +1,8 @@
|
|
|
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 { RemoteSource } from "../source/remote.js";
|
|
8
6
|
import { ReifiedRender } from "../render.js";
|
|
9
7
|
import { ImagesEntryMetadata } from "./images.js";
|
|
10
8
|
export type ImageOptions = {
|
|
@@ -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,9 +43,14 @@ 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>;
|
|
@@ -56,4 +59,10 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefine
|
|
|
56
59
|
protected executeSerialize(): SerializedSchema;
|
|
57
60
|
protected executeRender(): ReifiedRender;
|
|
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,7 +17,7 @@ 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
22
|
import { ReifiedRender, RenderScope } from "../render.js";
|
|
23
23
|
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedDateSchema | SerializedDateTimeSchema | SerializedColorSchema | SerializedRouteSchema | SerializedImageSchema;
|
|
@@ -2,11 +2,9 @@ import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, S
|
|
|
2
2
|
import { RenderSelector, ReifiedRender, RenderScope } from "../render.js";
|
|
3
3
|
import { ValRouter } from "../router.js";
|
|
4
4
|
import { SelectorSource } from "../selector/index.js";
|
|
5
|
-
import { ImageSource } from "../source/
|
|
5
|
+
import { ImageSource } from "../source/media.js";
|
|
6
6
|
import { JsonOf, JsonSource } from "../source/json.js";
|
|
7
|
-
import { RemoteSource } from "../source/remote.js";
|
|
8
7
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
9
|
-
import { ImageMetadata } from "./image.js";
|
|
10
8
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
11
9
|
type MediaOptions = {
|
|
12
10
|
type: "files" | "images";
|
|
@@ -56,7 +54,7 @@ type RecordRenderInput<T extends Schema<SelectorSource>> = {
|
|
|
56
54
|
}) => {
|
|
57
55
|
title: string;
|
|
58
56
|
subtitle?: string | null;
|
|
59
|
-
image?: ImageSource |
|
|
57
|
+
image?: ImageSource | null;
|
|
60
58
|
};
|
|
61
59
|
};
|
|
62
60
|
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> {
|
|
@@ -124,7 +122,7 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
124
122
|
}) => {
|
|
125
123
|
title: string;
|
|
126
124
|
subtitle?: string | null;
|
|
127
|
-
image?: ImageSource |
|
|
125
|
+
image?: ImageSource | null;
|
|
128
126
|
};
|
|
129
127
|
}): RecordSchema<T, K, Src>;
|
|
130
128
|
}
|
|
@@ -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,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;
|