@valbuild/core 0.93.0 → 0.94.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/initSchema.d.ts +59 -2
- package/dist/declarations/src/module.d.ts +2 -1
- package/dist/declarations/src/schema/file.d.ts +7 -4
- package/dist/declarations/src/schema/files.d.ts +56 -0
- package/dist/declarations/src/schema/image.d.ts +11 -7
- package/dist/declarations/src/schema/images.d.ts +85 -0
- package/dist/declarations/src/schema/object.d.ts +2 -0
- package/dist/declarations/src/schema/record.d.ts +20 -1
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/declarations/src/selector/index.d.ts +1 -1
- package/dist/declarations/src/source/index.d.ts +3 -2
- package/dist/declarations/src/source/remote.d.ts +1 -1
- package/dist/declarations/src/source/richtext.d.ts +2 -2
- package/dist/{index-d1491224.esm.js → index-bfe08f16.esm.js} +569 -177
- package/dist/{index-fcce0216.cjs.dev.js → index-c9252d4a.cjs.dev.js} +568 -176
- package/dist/{index-4421cd12.cjs.prod.js → index-f8101689.cjs.prod.js} +568 -176
- package/dist/{result-daff1cae.esm.js → result-4bd63123.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +1 -1
- package/dist/valbuild-core.cjs.prod.js +1 -1
- 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 +2 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +2 -1
- package/patch/dist/valbuild-core-patch.esm.js +4 -3
|
@@ -10,9 +10,11 @@ import { literal } from "./schema/literal.js";
|
|
|
10
10
|
import { keyOf } from "./schema/keyOf.js";
|
|
11
11
|
import { record } from "./schema/record.js";
|
|
12
12
|
import { file } from "./schema/file.js";
|
|
13
|
+
import { files } from "./schema/files.js";
|
|
13
14
|
import { date } from "./schema/date.js";
|
|
14
15
|
import { route } from "./schema/route.js";
|
|
15
16
|
import { router } from "./schema/router.js";
|
|
17
|
+
import { images } from "./schema/images.js";
|
|
16
18
|
export type InitSchema = {
|
|
17
19
|
/**
|
|
18
20
|
* Define a string.
|
|
@@ -196,6 +198,44 @@ export type InitSchema = {
|
|
|
196
198
|
* @returns A RecordSchema configured as a router
|
|
197
199
|
*/
|
|
198
200
|
readonly router: typeof router;
|
|
201
|
+
/**
|
|
202
|
+
* Define a collection of images.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const schema = s.images({
|
|
207
|
+
* accept: "image/webp",
|
|
208
|
+
* directory: "/public/val/images",
|
|
209
|
+
* alt: s.string().minLength(4),
|
|
210
|
+
* });
|
|
211
|
+
* export default c.define("/content/images.val.ts", schema, {
|
|
212
|
+
* "/public/val/images/hero.webp": {
|
|
213
|
+
* width: 1920,
|
|
214
|
+
* height: 1080,
|
|
215
|
+
* mimeType: "image/webp",
|
|
216
|
+
* alt: "Hero image",
|
|
217
|
+
* },
|
|
218
|
+
* });
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
readonly images: typeof images;
|
|
222
|
+
/**
|
|
223
|
+
* Define a collection of files.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const schema = s.files({
|
|
228
|
+
* accept: "application/pdf",
|
|
229
|
+
* directory: "/public/val/documents",
|
|
230
|
+
* });
|
|
231
|
+
* export default c.define("/content/documents.val.ts", schema, {
|
|
232
|
+
* "/public/val/documents/report.pdf": {
|
|
233
|
+
* mimeType: "application/pdf",
|
|
234
|
+
* },
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
readonly files: typeof files;
|
|
199
239
|
};
|
|
200
240
|
export declare function initSchema(): {
|
|
201
241
|
string: <T extends string>(options?: Record<string, never>) => import("./schema/string.js").StringSchema<T>;
|
|
@@ -211,6 +251,7 @@ export declare function initSchema(): {
|
|
|
211
251
|
andThen?: never;
|
|
212
252
|
assert?: never;
|
|
213
253
|
fold?: never;
|
|
254
|
+
patch_id?: never;
|
|
214
255
|
}>(schema: Props) => import("./schema/object.js").ObjectSchema<Props, { [key in keyof Props]: import("./schema/index.js").SelectorOfSchema<Props[key]>; }>;
|
|
215
256
|
number: (options?: {
|
|
216
257
|
max?: number;
|
|
@@ -218,12 +259,28 @@ export declare function initSchema(): {
|
|
|
218
259
|
}) => import("./schema/number.js").NumberSchema<number>;
|
|
219
260
|
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>;
|
|
220
261
|
richtext: <O extends import("./index.js").RichTextOptions>(options?: O) => import("./schema/richtext.js").RichTextSchema<O, import("./index.js").RichTextSource<O>>;
|
|
221
|
-
image: (options?: import("./schema/image.js").ImageOptions) => import("./schema/image.js").ImageSchema<import("./index.js").ImageSource
|
|
262
|
+
image: (options?: import("./schema/image.js").ImageOptions | import("./module.js").ValModule<Record<string, import("./schema/images.js").ImagesEntryMetadata>>) => import("./schema/image.js").ImageSchema<import("./index.js").ImageSource | import("./index.js").RemoteSource<import("./schema/image.js").ImageMetadata | undefined>>;
|
|
222
263
|
literal: <T extends string>(value: T) => import("./schema/literal.js").LiteralSchema<T>;
|
|
223
264
|
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>;
|
|
224
265
|
record: typeof record;
|
|
225
|
-
file: (options?: import("./schema/file.js").FileOptions) => import("./schema/file.js").FileSchema<import("./index.js").FileSource<import("./schema/file.js").FileMetadata>>;
|
|
266
|
+
file: (options?: import("./schema/file.js").FileOptions | import("./module.js").ValModule<Record<string, import("./schema/files.js").FilesEntryMetadata>>) => import("./schema/file.js").FileSchema<import("./index.js").FileSource | import("./index.js").RemoteSource<import("./schema/file.js").FileMetadata | undefined>>;
|
|
267
|
+
files: (options: import("./schema/files.js").FilesOptions) => import("./schema/record.js").RecordSchema<import("./schema/object.js").ObjectSchema<{
|
|
268
|
+
mimeType: import("./schema/string.js").StringSchema<string>;
|
|
269
|
+
}, {
|
|
270
|
+
mimeType: string;
|
|
271
|
+
}>, import("./schema/index.js").Schema<string>, Record<string, import("./schema/files.js").FilesEntryMetadata>>;
|
|
226
272
|
date: (options?: Record<string, never>) => import("./schema/date.js").DateSchema<import("./schema/string.js").RawString>;
|
|
227
273
|
route: <T extends string>(options?: Record<string, never>) => import("./schema/route.js").RouteSchema<T>;
|
|
228
274
|
router: typeof router;
|
|
275
|
+
images: <Accept extends `image/${string}`>(options: import("./schema/images.js").ImagesOptions<Accept>) => import("./schema/record.js").RecordSchema<import("./schema/object.js").ObjectSchema<{
|
|
276
|
+
width: import("./schema/number.js").NumberSchema<number>;
|
|
277
|
+
height: import("./schema/number.js").NumberSchema<number>;
|
|
278
|
+
mimeType: import("./schema/string.js").StringSchema<string>;
|
|
279
|
+
alt: import("./schema/string.js").StringSchema<string | null>;
|
|
280
|
+
}, {
|
|
281
|
+
width: number;
|
|
282
|
+
height: number;
|
|
283
|
+
mimeType: string;
|
|
284
|
+
alt: string | null;
|
|
285
|
+
}>, import("./schema/index.js").Schema<string>, Record<string, import("./schema/images.js").ImagesEntryMetadata>>;
|
|
229
286
|
};
|
|
@@ -19,7 +19,8 @@ export type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSourc
|
|
|
19
19
|
} : T extends SelectorSource[] ? ReplaceRawStringWithString<T[number]>[] : T;
|
|
20
20
|
export declare function define<T extends Schema<SelectorSource>>(id: string, // TODO: `/${string}`
|
|
21
21
|
schema: T, source: ReplaceRawStringWithString<SelectorOfSchema<T>>): ValModule<SelectorOfSchema<T>>;
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function enrichFileImageRemoteSourceWithMetadata<T extends SelectorSource>(source: T, schema: Schema<SelectorSource>): T;
|
|
23
|
+
export declare function getSource<T extends Source>(valModule: ValModule<T>): T;
|
|
23
24
|
export declare function splitModuleFilePathAndModulePath(path: SourcePath | ModuleFilePath): [moduleId: ModuleFilePath, path: ModulePath];
|
|
24
25
|
export declare function joinModuleFilePathAndModulePath(moduleFilePath: ModuleFilePath, modulePath: ModulePath): SourcePath;
|
|
25
26
|
export declare function getSourceAtPath(modulePath: ModulePath, valModule: ValModule<SelectorSource> | Source): any;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Json } from "../Json.js";
|
|
2
2
|
import { FileSource } from "../source/file.js";
|
|
3
3
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
4
|
-
import { SourcePath } from "../val/index.js";
|
|
4
|
+
import { ModulePath, SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
|
6
|
-
import { RemoteSource } from "../index.js";
|
|
6
|
+
import { RemoteSource, ValModule } from "../index.js";
|
|
7
7
|
import { ReifiedRender } from "../render.js";
|
|
8
|
+
import { FilesEntryMetadata } from "./files.js";
|
|
8
9
|
export type FileOptions = {
|
|
9
10
|
accept?: string;
|
|
10
11
|
};
|
|
@@ -14,6 +15,7 @@ export type SerializedFileSchema = {
|
|
|
14
15
|
remote?: boolean;
|
|
15
16
|
opt: boolean;
|
|
16
17
|
customValidate?: boolean;
|
|
18
|
+
referencedModule?: string;
|
|
17
19
|
};
|
|
18
20
|
export type FileMetadata = {
|
|
19
21
|
mimeType?: string;
|
|
@@ -23,7 +25,8 @@ export declare class FileSchema<Src extends FileSource<FileMetadata | undefined>
|
|
|
23
25
|
private readonly opt;
|
|
24
26
|
protected readonly isRemote: boolean;
|
|
25
27
|
private readonly customValidateFunctions;
|
|
26
|
-
|
|
28
|
+
private readonly moduleMetadata;
|
|
29
|
+
constructor(options?: FileOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], moduleMetadata?: Record<ModulePath, Record<string, FilesEntryMetadata>>);
|
|
27
30
|
remote(): FileSchema<Src | RemoteSource<FileMetadata | undefined>>;
|
|
28
31
|
validate(validationFunction: CustomValidateFunction<Src>): FileSchema<Src>;
|
|
29
32
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -32,7 +35,7 @@ export declare class FileSchema<Src extends FileSource<FileMetadata | undefined>
|
|
|
32
35
|
protected executeSerialize(): SerializedSchema;
|
|
33
36
|
protected executeRender(): ReifiedRender;
|
|
34
37
|
}
|
|
35
|
-
export declare const file: (options?: FileOptions) => FileSchema<FileSource<FileMetadata>>;
|
|
38
|
+
export declare const file: (options?: FileOptions | ValModule<Record<string, FilesEntryMetadata>>) => FileSchema<FileSource | RemoteSource<FileMetadata | undefined>>;
|
|
36
39
|
export declare function convertFileSource<Metadata extends {
|
|
37
40
|
readonly [key: string]: Json;
|
|
38
41
|
} | undefined = {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Schema } from "./index.js";
|
|
2
|
+
import type { SerializedRecordSchema } from "./record.js";
|
|
3
|
+
import { RecordSchema } from "./record.js";
|
|
4
|
+
import { ObjectSchema } from "./object.js";
|
|
5
|
+
import { StringSchema } from "./string.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for s.files()
|
|
8
|
+
*/
|
|
9
|
+
export type FilesOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* The accepted mime type pattern (e.g., "application/pdf", "text/*", "*\/*")
|
|
12
|
+
*/
|
|
13
|
+
accept: string;
|
|
14
|
+
/**
|
|
15
|
+
* The directory where files should be stored.
|
|
16
|
+
* Must start with "/public" (e.g., "/public/val/files")
|
|
17
|
+
* @default "/public/val"
|
|
18
|
+
*/
|
|
19
|
+
directory?: "/public" | `/public/${string}`;
|
|
20
|
+
/**
|
|
21
|
+
* Whether remote files are allowed
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
remote?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Metadata for a file entry in the files record
|
|
28
|
+
*/
|
|
29
|
+
export type FilesEntryMetadata = {
|
|
30
|
+
mimeType: string;
|
|
31
|
+
};
|
|
32
|
+
export type SerializedFilesSchema = SerializedRecordSchema;
|
|
33
|
+
type FilesItemProps = {
|
|
34
|
+
mimeType: StringSchema<string>;
|
|
35
|
+
};
|
|
36
|
+
type FilesItemSrc = {
|
|
37
|
+
mimeType: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Define a collection of files.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const schema = s.files({
|
|
45
|
+
* accept: "application/pdf",
|
|
46
|
+
* directory: "/public/val/documents",
|
|
47
|
+
* });
|
|
48
|
+
* export default c.define("/content/documents.val.ts", schema, {
|
|
49
|
+
* "/public/val/documents/report.pdf": {
|
|
50
|
+
* mimeType: "application/pdf",
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const files: (options: FilesOptions) => RecordSchema<ObjectSchema<FilesItemProps, FilesItemSrc>, Schema<string>, Record<string, FilesEntryMetadata>>;
|
|
56
|
+
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
2
|
import { FileSource } from "../source/file.js";
|
|
3
3
|
import { ImageSource } from "../source/image.js";
|
|
4
|
-
import { SourcePath } from "../val/index.js";
|
|
4
|
+
import { ModulePath, SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ValModule } from "../index.js";
|
|
7
7
|
import { RemoteSource } from "../source/remote.js";
|
|
8
8
|
import { ReifiedRender } from "../render.js";
|
|
9
|
+
import { ImagesEntryMetadata } from "./images.js";
|
|
9
10
|
export type ImageOptions = {
|
|
10
11
|
ext?: ["jpg"] | ["webp"];
|
|
11
12
|
directory?: string;
|
|
@@ -18,10 +19,12 @@ export type SerializedImageSchema = {
|
|
|
18
19
|
opt: boolean;
|
|
19
20
|
remote?: boolean;
|
|
20
21
|
customValidate?: boolean;
|
|
22
|
+
referencedModule?: string;
|
|
21
23
|
};
|
|
22
|
-
export type ImageMetadata =
|
|
23
|
-
width
|
|
24
|
-
height
|
|
24
|
+
export type ImageMetadata = {
|
|
25
|
+
width?: number;
|
|
26
|
+
height?: number;
|
|
27
|
+
mimeType?: string;
|
|
25
28
|
alt?: string;
|
|
26
29
|
hotspot?: {
|
|
27
30
|
x: number;
|
|
@@ -33,7 +36,8 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefine
|
|
|
33
36
|
private readonly opt;
|
|
34
37
|
protected readonly isRemote: boolean;
|
|
35
38
|
private readonly customValidateFunctions;
|
|
36
|
-
|
|
39
|
+
private readonly moduleMetadata;
|
|
40
|
+
constructor(options?: ImageOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], moduleMetadata?: Record<ModulePath, Record<string, ImagesEntryMetadata>>);
|
|
37
41
|
remote(): ImageSchema<Src | RemoteSource<ImageMetadata | undefined>>;
|
|
38
42
|
validate(validationFunction: CustomValidateFunction<Src>): ImageSchema<Src>;
|
|
39
43
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -42,4 +46,4 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefine
|
|
|
42
46
|
protected executeSerialize(): SerializedSchema;
|
|
43
47
|
protected executeRender(): ReifiedRender;
|
|
44
48
|
}
|
|
45
|
-
export declare const image: (options?: ImageOptions) => ImageSchema<ImageSource
|
|
49
|
+
export declare const image: (options?: ImageOptions | ValModule<Record<string, ImagesEntryMetadata>>) => ImageSchema<ImageSource | RemoteSource<ImageMetadata | undefined>>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Schema } from "./index.js";
|
|
2
|
+
import type { SerializedRecordSchema } from "./record.js";
|
|
3
|
+
import { RecordSchema } from "./record.js";
|
|
4
|
+
import { ObjectSchema } from "./object.js";
|
|
5
|
+
import { StringSchema } from "./string.js";
|
|
6
|
+
import { NumberSchema } from "./number.js";
|
|
7
|
+
/**
|
|
8
|
+
* Alt schema type - can be a string, nullable string, or a record of locale to string
|
|
9
|
+
*/
|
|
10
|
+
export type AltSchema = StringSchema<string> | StringSchema<string | null> | RecordSchema<StringSchema<string>, Schema<string>, Record<string, string>>;
|
|
11
|
+
/**
|
|
12
|
+
* Options for s.images()
|
|
13
|
+
*/
|
|
14
|
+
export type ImagesOptions<Accept extends `image/${string}`> = {
|
|
15
|
+
/**
|
|
16
|
+
* The accepted mime type pattern. Must be an image type (e.g., "image/png", "image/webp", "image/*")
|
|
17
|
+
*/
|
|
18
|
+
accept: Accept;
|
|
19
|
+
/**
|
|
20
|
+
* The directory where images should be stored.
|
|
21
|
+
* Must start with "/public" (e.g., "/public/val/images")
|
|
22
|
+
* @default "/public/val"
|
|
23
|
+
*/
|
|
24
|
+
directory?: "/public" | `/public/${string}`;
|
|
25
|
+
/**
|
|
26
|
+
* Alt text schema. Can be:
|
|
27
|
+
* - s.string() for required alt text
|
|
28
|
+
* - s.string().nullable() for optional alt text (default)
|
|
29
|
+
* - s.record(s.string(), s.string()) for locale-based alt text
|
|
30
|
+
*/
|
|
31
|
+
alt?: AltSchema;
|
|
32
|
+
/**
|
|
33
|
+
* Whether remote images are allowed
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
remote?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Metadata for an image entry in the images record
|
|
40
|
+
*/
|
|
41
|
+
export type ImagesEntryMetadata = {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
mimeType: string;
|
|
45
|
+
alt: string | null;
|
|
46
|
+
hotspot?: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export type SerializedImagesSchema = SerializedRecordSchema;
|
|
52
|
+
type ImagesItemProps = {
|
|
53
|
+
width: NumberSchema<number>;
|
|
54
|
+
height: NumberSchema<number>;
|
|
55
|
+
mimeType: StringSchema<string>;
|
|
56
|
+
alt: StringSchema<string | null>;
|
|
57
|
+
};
|
|
58
|
+
type ImagesItemSrc = {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
mimeType: string;
|
|
62
|
+
alt: string | null;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Define a collection of images.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const schema = s.images({
|
|
70
|
+
* accept: "image/webp",
|
|
71
|
+
* directory: "/public/val/images",
|
|
72
|
+
* alt: s.string().minLength(4),
|
|
73
|
+
* });
|
|
74
|
+
* export default c.define("/content/images.val.ts", schema, {
|
|
75
|
+
* "/public/val/images/hero.webp": {
|
|
76
|
+
* width: 1920,
|
|
77
|
+
* height: 1080,
|
|
78
|
+
* mimeType: "image/webp",
|
|
79
|
+
* alt: "Hero image",
|
|
80
|
+
* },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare const images: <Accept extends `image/${string}`>(options: ImagesOptions<Accept>) => RecordSchema<ObjectSchema<ImagesItemProps, ImagesItemSrc>, Schema<string>, Record<string, ImagesEntryMetadata>>;
|
|
85
|
+
export {};
|
|
@@ -26,6 +26,8 @@ type ObjectSchemaProps = {
|
|
|
26
26
|
assert?: never;
|
|
27
27
|
/** Cannot create object with key: fold. It is a reserved name */
|
|
28
28
|
fold?: never;
|
|
29
|
+
/** Cannot create object with key: patch_id. It is a reserved name */
|
|
30
|
+
patch_id?: never;
|
|
29
31
|
};
|
|
30
32
|
type ObjectSchemaSrcOf<Props extends ObjectSchemaProps> = {
|
|
31
33
|
[key in keyof Props]: SelectorOfSchema<Props[key]>;
|
|
@@ -7,6 +7,13 @@ import { RemoteSource } from "../source/remote.js";
|
|
|
7
7
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
8
8
|
import { ImageMetadata } from "./image.js";
|
|
9
9
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
|
10
|
+
type MediaOptions = {
|
|
11
|
+
type: "files" | "images";
|
|
12
|
+
accept: string;
|
|
13
|
+
directory: string;
|
|
14
|
+
remote: boolean;
|
|
15
|
+
altSchema?: Schema<SelectorSource>;
|
|
16
|
+
};
|
|
10
17
|
export type SerializedRecordSchema = {
|
|
11
18
|
type: "record";
|
|
12
19
|
item: SerializedSchema;
|
|
@@ -14,6 +21,11 @@ export type SerializedRecordSchema = {
|
|
|
14
21
|
opt: boolean;
|
|
15
22
|
router?: string;
|
|
16
23
|
customValidate?: boolean;
|
|
24
|
+
mediaType?: "files" | "images";
|
|
25
|
+
accept?: string;
|
|
26
|
+
directory?: string;
|
|
27
|
+
remote?: boolean;
|
|
28
|
+
alt?: SerializedSchema;
|
|
17
29
|
};
|
|
18
30
|
export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Schema<string>, Src extends Record<SelectorOfSchema<K>, SelectorOfSchema<T>> | null> extends Schema<Src> {
|
|
19
31
|
private readonly item;
|
|
@@ -21,12 +33,18 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
21
33
|
private readonly customValidateFunctions;
|
|
22
34
|
private readonly currentRouter;
|
|
23
35
|
private readonly keySchema;
|
|
24
|
-
|
|
36
|
+
private readonly mediaOptions?;
|
|
37
|
+
constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], currentRouter?: ValRouter | null, keySchema?: Schema<string> | null, mediaOptions?: MediaOptions | undefined);
|
|
25
38
|
validate(validationFunction: (src: Src) => false | string): RecordSchema<T, K, Src>;
|
|
26
39
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
40
|
+
private isRemoteUrl;
|
|
41
|
+
private validateMediaKey;
|
|
42
|
+
private validateMediaEntry;
|
|
43
|
+
private validateMediaMimeType;
|
|
27
44
|
protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
|
28
45
|
nullable(): RecordSchema<T, K, Src | null>;
|
|
29
46
|
router(router: ValRouter): RecordSchema<T, K, Src>;
|
|
47
|
+
remote(): RecordSchema<T, K, Src>;
|
|
30
48
|
private getRouterValidations;
|
|
31
49
|
protected executeSerialize(): SerializedRecordSchema;
|
|
32
50
|
private renderInput;
|
|
@@ -45,3 +63,4 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
45
63
|
}
|
|
46
64
|
export declare function record<K extends Schema<string>, S extends Schema<SelectorSource>>(key: K, schema: S): RecordSchema<S, K, Record<SelectorOfSchema<K>, SelectorOfSchema<S>>>;
|
|
47
65
|
export declare function record<S extends Schema<SelectorSource>>(schema: S): RecordSchema<S, Schema<string>, Record<string, SelectorOfSchema<S>>>;
|
|
66
|
+
export {};
|
|
@@ -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", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "keyof:check-keys", "router:check-route"];
|
|
1
|
+
export declare const ValidationFix: readonly ["image:add-metadata", "image:check-metadata", "image:upload-remote", "image:download-remote", "image:check-remote", "images:check-remote", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "files:check-remote", "keyof:check-keys", "router:check-route", "images:check-unique-folder", "files:check-unique-folder", "images:check-all-files", "files:check-all-files"];
|
|
2
2
|
export type ValidationFix = (typeof ValidationFix)[number];
|
|
@@ -18,7 +18,7 @@ import { RemoteSource } from "../source/remote.js";
|
|
|
18
18
|
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends ImageSource ? ImageSelector : T extends FileSource<infer M> ? FileSelector<M> : 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
19
|
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
|
20
20
|
[key: string]: SelectorSource;
|
|
21
|
-
} | FileSource | RemoteSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
|
|
21
|
+
} | ImageSource | FileSource | RemoteSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
|
|
22
22
|
/**
|
|
23
23
|
* @internal
|
|
24
24
|
*/
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FileSource } from "./file.js";
|
|
2
|
+
import { ImageSource } from "./image.js";
|
|
2
3
|
import { RemoteSource } from "./remote.js";
|
|
3
4
|
import { RichTextOptions, RichTextSource } from "./richtext.js";
|
|
4
|
-
export type Source = SourcePrimitive | SourceObject | SourceArray | RemoteSource | FileSource | RichTextSource<RichTextOptions>;
|
|
5
|
+
export type Source = SourcePrimitive | SourceObject | SourceArray | RemoteSource | FileSource | ImageSource | RichTextSource<RichTextOptions>;
|
|
5
6
|
export type SourceObject = {
|
|
6
7
|
[key in string]: Source;
|
|
7
8
|
} & {
|
|
@@ -23,7 +24,7 @@ export type SourceObject = {
|
|
|
23
24
|
export type SourceArray = readonly Source[];
|
|
24
25
|
export type SourcePrimitive = string | number | boolean | null;
|
|
25
26
|
export declare const VAL_EXTENSION: "_type";
|
|
26
|
-
export declare function getValExtension(source: Source): false | "" | 0 | "
|
|
27
|
+
export declare function getValExtension(source: Source): false | "" | 0 | "remote" | "file" | null | undefined;
|
|
27
28
|
/**
|
|
28
29
|
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
|
29
30
|
*
|
|
@@ -11,7 +11,7 @@ export type RemoteSource<Metadata extends FileMetadata | undefined = FileMetadat
|
|
|
11
11
|
readonly metadata?: Metadata;
|
|
12
12
|
readonly patch_id?: string;
|
|
13
13
|
};
|
|
14
|
-
export declare const initRemote: (config?: ValConfig) => <Metadata extends FileMetadata | ImageMetadata>(ref: RemoteRef, metadata
|
|
14
|
+
export declare const initRemote: (config?: ValConfig) => <Metadata extends FileMetadata | ImageMetadata>(ref: RemoteRef, metadata?: Metadata) => RemoteSource<Metadata>;
|
|
15
15
|
export type RemoteRef = `${string}/file/p/${string}/v/${string}/h/${string}/f/${string}/p/public/val/${string}`;
|
|
16
16
|
export declare function createRemoteRef(remoteHost: string, { publicProjectId, coreVersion, validationHash, fileHash, filePath, bucket, }: {
|
|
17
17
|
publicProjectId: string;
|
|
@@ -22,7 +22,7 @@ export type RichTextOptions = Partial<{
|
|
|
22
22
|
}>;
|
|
23
23
|
inline: Partial<{
|
|
24
24
|
a: boolean | RouteSchema<string> | StringSchema<string>;
|
|
25
|
-
img: boolean | ImageSchema<ImageSource | RemoteSource<ImageMetadata>>;
|
|
25
|
+
img: boolean | ImageSchema<ImageSource> | ImageSchema<RemoteSource<ImageMetadata | undefined>> | ImageSchema<ImageSource | RemoteSource<ImageMetadata | undefined>>;
|
|
26
26
|
}>;
|
|
27
27
|
}>;
|
|
28
28
|
export type SerializedRichTextOptions = Partial<{
|
|
@@ -93,7 +93,7 @@ export type SpanNode<O extends RichTextOptions> = {
|
|
|
93
93
|
export type ImageNode<O extends RichTextOptions> = NonNullable<O["inline"]>["img"] extends true ? {
|
|
94
94
|
tag: "img";
|
|
95
95
|
src: ImageSource | RemoteSource<ImageMetadata>;
|
|
96
|
-
} : NonNullable<O["inline"]>["img"] extends ImageSchema<infer Src> ? Src extends RemoteSource | FileSource ? {
|
|
96
|
+
} : NonNullable<O["inline"]>["img"] extends ImageSchema<infer Src> ? Src extends RemoteSource | FileSource | ImageSource ? {
|
|
97
97
|
tag: "img";
|
|
98
98
|
src: Src;
|
|
99
99
|
} : never : never;
|