@valbuild/core 0.79.4 → 0.80.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.
Files changed (27) hide show
  1. package/dist/declarations/src/index.d.ts +4 -3
  2. package/dist/declarations/src/initSchema.d.ts +4 -4
  3. package/dist/declarations/src/schema/array.d.ts +10 -7
  4. package/dist/declarations/src/schema/boolean.d.ts +11 -8
  5. package/dist/declarations/src/schema/date.d.ts +10 -7
  6. package/dist/declarations/src/schema/file.d.ts +11 -8
  7. package/dist/declarations/src/schema/image.d.ts +11 -8
  8. package/dist/declarations/src/schema/index.d.ts +7 -5
  9. package/dist/declarations/src/schema/keyOf.d.ts +13 -10
  10. package/dist/declarations/src/schema/literal.d.ts +11 -8
  11. package/dist/declarations/src/schema/number.d.ts +11 -8
  12. package/dist/declarations/src/schema/object.d.ts +12 -9
  13. package/dist/declarations/src/schema/record.d.ts +11 -8
  14. package/dist/declarations/src/schema/richtext.d.ts +11 -8
  15. package/dist/declarations/src/schema/string.d.ts +13 -7
  16. package/dist/declarations/src/schema/union.d.ts +14 -10
  17. package/dist/declarations/src/source/remote.d.ts +1 -1
  18. package/dist/{index-b03107f7.cjs.dev.js → index-5a7e1014.cjs.dev.js} +505 -284
  19. package/dist/{index-a2affd87.cjs.prod.js → index-74fe6f44.cjs.prod.js} +505 -284
  20. package/dist/{index-7ee9acb3.esm.js → index-bcc230b2.esm.js} +505 -284
  21. package/dist/valbuild-core.cjs.dev.js +1 -1
  22. package/dist/valbuild-core.cjs.prod.js +1 -1
  23. package/dist/valbuild-core.esm.js +1 -1
  24. package/package.json +1 -1
  25. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  26. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  27. package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -20,11 +20,11 @@ export { FILE_REF_PROP, FILE_REF_SUBTYPE_TAG } from "./source/file.js";
20
20
  export { VAL_EXTENSION, type SourceArray } from "./source/index.js";
21
21
  export { derefPatch } from "./patch/deref.js";
22
22
  export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector/index.js";
23
- import { getSource, splitModulePath, splitModuleFilePath, resolvePath, safeResolvePath, splitModuleFilePathAndModulePath, joinModuleFilePathAndModulePath, parentOfSourcePath, patchPathToModulePath, splitJoinedSourcePaths } from "./module.js";
23
+ import { getSource, splitModulePath, splitModuleFilePath, resolvePath, safeResolvePath, splitModuleFilePathAndModulePath, joinModuleFilePathAndModulePath, parentOfSourcePath, patchPathToModulePath, splitJoinedSourcePaths, type ValModule } from "./module.js";
24
24
  declare const ModuleFilePathSep = "?p=";
25
25
  export { ModuleFilePathSep };
26
- import { getSchema } from "./selector/index.js";
27
- import { ModulePath, getValPath, isVal } from "./val/index.js";
26
+ import { SelectorSource, getSchema } from "./selector/index.js";
27
+ import { ModulePath, SourcePath, getValPath, isVal } from "./val/index.js";
28
28
  import { convertFileSource } from "./schema/file.js";
29
29
  import { createValPathOfItem } from "./selector/SelectorProxy.js";
30
30
  import { Operation } from "./patch/index.js";
@@ -78,6 +78,7 @@ declare const Internal: {
78
78
  hashToRemoteFileHash: typeof hashToRemoteFileHash;
79
79
  splitRemoteRef: typeof splitRemoteRef;
80
80
  };
81
+ validate: (val: ValModule<SelectorSource>, path: SourcePath, src: unknown) => import("./schema/validation/ValidationError.js").ValidationErrors | undefined;
81
82
  isVal: typeof isVal;
82
83
  isFile: typeof isFile;
83
84
  createValPathOfItem: typeof createValPathOfItem;
@@ -46,7 +46,7 @@ export type InitSchema = {
46
46
  };
47
47
  export declare function initSchema(): {
48
48
  string: <T extends string>(options?: Record<string, never> | undefined) => import("./schema/string.js").StringSchema<T>;
49
- boolean: () => import("./schema/index.js").Schema<boolean>;
49
+ boolean: () => import("./schema/boolean.js").BooleanSchema<boolean>;
50
50
  array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/array.js").ArraySchema<S, import("./schema/index.js").SelectorOfSchema<S>[]>;
51
51
  object: <Props extends {
52
52
  [key: string]: import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>;
@@ -58,7 +58,7 @@ export declare function initSchema(): {
58
58
  andThen?: undefined;
59
59
  assert?: undefined;
60
60
  fold?: undefined;
61
- }>(schema: Props) => import("./schema/index.js").Schema<{ [key in keyof Props]: import("./schema/index.js").SelectorOfSchema<Props[key]>; }>;
61
+ }>(schema: Props) => import("./schema/object.js").ObjectSchema<Props, { [key in keyof Props]: import("./schema/index.js").SelectorOfSchema<Props[key]>; }>;
62
62
  number: (options?: {
63
63
  max?: number | undefined;
64
64
  min?: number | undefined;
@@ -73,7 +73,7 @@ export declare function initSchema(): {
73
73
  _type?: undefined;
74
74
  val?: undefined;
75
75
  valPath?: undefined;
76
- } & { [k in Key]: string; } : Key extends import("./schema/index.js").Schema<string> ? string : unknown>[]>(key: Key, ...objects: T_1) => import("./schema/index.js").Schema<T_1 extends import("./schema/index.js").Schema<infer S_1 extends import("./selector/index.js").SelectorSource>[] ? S_1 extends import("./selector/index.js").SelectorSource ? S_1 | (Key extends import("./schema/index.js").Schema<infer K extends import("./selector/index.js").SelectorSource> ? K : never) : never : never>;
76
+ } & { [k in Key]: string; } : Key extends import("./schema/index.js").Schema<string> ? string : unknown>[]>(key: Key, ...objects: T_1) => import("./schema/union.js").UnionSchema<Key, T_1, T_1 extends import("./schema/index.js").Schema<infer S_1 extends import("./selector/index.js").SelectorSource>[] ? S_1 extends import("./selector/index.js").SelectorSource ? S_1 | (Key extends import("./schema/index.js").Schema<infer K extends import("./selector/index.js").SelectorSource> ? K : never) : never : never>;
77
77
  richtext: <O extends Partial<{
78
78
  style: Partial<{
79
79
  bold: boolean;
@@ -97,7 +97,7 @@ export declare function initSchema(): {
97
97
  }>>(options?: O | undefined) => import("./schema/richtext.js").RichTextSchema<O, import("./index.js").RichTextSource<O>>;
98
98
  image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/image.js").ImageSchema<import("./index.js").ImageSource>;
99
99
  literal: <T_2 extends string>(value: T_2) => import("./schema/literal.js").LiteralSchema<T_2>;
100
- keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject, undefined> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/index.js").Schema<Src extends import("./selector/index.js").GenericSelector<infer S_2 extends import("./source/index.js").Source, undefined> ? S_2 extends readonly import("./source/index.js").Source[] ? number : S_2 extends import("./source/index.js").SourceObject ? string extends keyof S_2 ? import("./schema/string.js").RawString : keyof S_2 : S_2 extends Record<string, import("./source/index.js").Source> ? import("./schema/string.js").RawString : never : never>;
100
+ keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject, undefined> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/keyOf.js").KeyOfSchema<Src, Src extends import("./selector/index.js").GenericSelector<infer S_2 extends import("./source/index.js").Source, undefined> ? S_2 extends readonly import("./source/index.js").Source[] ? number : S_2 extends import("./source/index.js").SourceObject ? string extends keyof S_2 ? import("./schema/string.js").RawString : keyof S_2 : S_2 extends Record<string, import("./source/index.js").Source> ? import("./schema/string.js").RawString : never : never>;
101
101
  record: <S_3 extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S_3) => import("./schema/record.js").RecordSchema<S_3, Record<string, import("./schema/index.js").SelectorOfSchema<S_3>>>;
102
102
  file: (options?: import("./schema/file.js").FileOptions | undefined) => import("./schema/file.js").FileSchema<import("./index.js").FileSource<import("./schema/file.js").FileMetadata>>;
103
103
  date: (options?: Record<string, never> | undefined) => import("./schema/date.js").DateSchema<import("./schema/string.js").RawString>;
@@ -8,15 +8,18 @@ export type SerializedArraySchema = {
8
8
  type: "array";
9
9
  item: SerializedSchema;
10
10
  opt: boolean;
11
+ customValidate?: boolean;
11
12
  };
12
13
  export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends SelectorOfSchema<T>[] | null> extends Schema<Src> {
13
- readonly item: T;
14
- readonly opt: boolean;
15
- constructor(item: T, opt?: boolean);
16
- validate(path: SourcePath, src: Src): ValidationErrors;
17
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
18
- nullable(): Schema<Src | null>;
19
- serialize(): SerializedArraySchema;
14
+ private readonly item;
15
+ private readonly opt;
16
+ private readonly customValidateFunctions;
17
+ constructor(item: T, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[]);
18
+ validate(validationFunction: (src: Src) => false | string): ArraySchema<T, Src>;
19
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
20
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
21
+ nullable(): ArraySchema<T, Src | null>;
22
+ protected executeSerialize(): SerializedArraySchema;
20
23
  private previewInput;
21
24
  protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedPreview;
22
25
  preview(input: {
@@ -1,18 +1,21 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
5
5
  export type SerializedBooleanSchema = {
6
6
  type: "boolean";
7
7
  opt: boolean;
8
+ customValidate?: boolean;
8
9
  };
9
10
  export declare class BooleanSchema<Src extends boolean | null> extends Schema<Src> {
10
- readonly opt: boolean;
11
- constructor(opt?: boolean);
12
- validate(path: SourcePath, src: Src): ValidationErrors;
13
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
14
- nullable(): Schema<Src | null>;
15
- serialize(): SerializedSchema;
11
+ private readonly opt;
12
+ private readonly customValidateFunctions;
13
+ constructor(opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
14
+ validate(validationFunction: (src: Src) => false | string): BooleanSchema<Src>;
15
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
16
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
17
+ nullable(): BooleanSchema<Src | null>;
18
+ protected executeSerialize(): SerializedSchema;
16
19
  protected executePreview(): ReifiedPreview;
17
20
  }
18
- export declare const boolean: () => Schema<boolean>;
21
+ export declare const boolean: () => BooleanSchema<boolean>;
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { RawString } from "./string.js";
@@ -23,17 +23,20 @@ export type SerializedDateSchema = {
23
23
  type: "date";
24
24
  options?: DateOptions;
25
25
  opt: boolean;
26
+ customValidate?: boolean;
26
27
  };
27
28
  export declare class DateSchema<Src extends string | null> extends Schema<Src> {
28
- readonly options?: DateOptions | undefined;
29
- readonly opt: boolean;
30
- constructor(options?: DateOptions | undefined, opt?: boolean);
31
- validate(path: SourcePath, src: Src): ValidationErrors;
32
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
29
+ private readonly options?;
30
+ private readonly opt;
31
+ private readonly customValidateFunctions;
32
+ constructor(options?: DateOptions | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
33
+ validate(validationFunction: (src: Src) => false | string): DateSchema<Src>;
34
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
35
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
33
36
  from(from: string): DateSchema<Src>;
34
37
  to(to: string): DateSchema<Src>;
35
38
  nullable(): DateSchema<Src | null>;
36
- serialize(): SerializedSchema;
39
+ protected executeSerialize(): SerializedSchema;
37
40
  protected executePreview(): ReifiedPreview;
38
41
  }
39
42
  export declare const date: (options?: Record<string, never>) => DateSchema<RawString>;
@@ -1,6 +1,6 @@
1
1
  import { Json } from "../Json.js";
2
2
  import { FileSource } from "../source/file.js";
3
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
3
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
4
4
  import { SourcePath } from "../val/index.js";
5
5
  import { ValidationErrors } from "./validation/ValidationError.js";
6
6
  import { RemoteSource } from "../index.js";
@@ -13,20 +13,23 @@ export type SerializedFileSchema = {
13
13
  options?: FileOptions;
14
14
  remote?: boolean;
15
15
  opt: boolean;
16
+ customValidate?: boolean;
16
17
  };
17
18
  export type FileMetadata = {
18
19
  mimeType?: string;
19
20
  };
20
21
  export declare class FileSchema<Src extends FileSource<FileMetadata | undefined> | RemoteSource<FileMetadata | undefined> | null> extends Schema<Src> {
21
- readonly options?: FileOptions | undefined;
22
- readonly opt: boolean;
22
+ private readonly options?;
23
+ private readonly opt;
23
24
  protected readonly isRemote: boolean;
24
- constructor(options?: FileOptions | undefined, opt?: boolean, isRemote?: boolean);
25
+ private readonly customValidateFunctions;
26
+ constructor(options?: FileOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
25
27
  remote(): FileSchema<Src | RemoteSource<FileMetadata | undefined>>;
26
- validate(path: SourcePath, src: Src): ValidationErrors;
27
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
28
- nullable(): Schema<Src | null>;
29
- serialize(): SerializedSchema;
28
+ validate(validationFunction: CustomValidateFunction<Src>): FileSchema<Src>;
29
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
30
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
31
+ nullable(): FileSchema<Src | null>;
32
+ protected executeSerialize(): SerializedSchema;
30
33
  protected executePreview(): ReifiedPreview;
31
34
  }
32
35
  export declare const file: (options?: FileOptions) => FileSchema<FileSource<FileMetadata>>;
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
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
4
  import { SourcePath } from "../val/index.js";
@@ -17,6 +17,7 @@ export type SerializedImageSchema = {
17
17
  options?: ImageOptions;
18
18
  opt: boolean;
19
19
  remote?: boolean;
20
+ customValidate?: boolean;
20
21
  };
21
22
  export type ImageMetadata = FileMetadata & {
22
23
  width: number;
@@ -28,15 +29,17 @@ export type ImageMetadata = FileMetadata & {
28
29
  };
29
30
  };
30
31
  export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefined> | RemoteSource<ImageMetadata | undefined> | null> extends Schema<Src> {
31
- readonly options?: ImageOptions | undefined;
32
- readonly opt: boolean;
32
+ private readonly options?;
33
+ private readonly opt;
33
34
  protected readonly isRemote: boolean;
34
- constructor(options?: ImageOptions | undefined, opt?: boolean, isRemote?: boolean);
35
+ private readonly customValidateFunctions;
36
+ constructor(options?: ImageOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
35
37
  remote(): ImageSchema<Src | RemoteSource<ImageMetadata | undefined>>;
36
- validate(path: SourcePath, src: Src): ValidationErrors;
37
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
38
- nullable(): Schema<Src | null>;
39
- serialize(): SerializedSchema;
38
+ validate(validationFunction: CustomValidateFunction<Src>): ImageSchema<Src>;
39
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
40
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
41
+ nullable(): ImageSchema<Src | null>;
42
+ protected executeSerialize(): SerializedSchema;
40
43
  protected executePreview(): ReifiedPreview;
41
44
  }
42
45
  export declare const image: (options?: ImageOptions) => ImageSchema<ImageSource>;
@@ -13,7 +13,7 @@ import { SerializedRichTextSchema } from "./richtext.js";
13
13
  import { RawString, SerializedStringSchema } from "./string.js";
14
14
  import { SerializedUnionSchema } from "./union.js";
15
15
  import { SerializedDateSchema } from "./date.js";
16
- import { ValidationErrors } from "./validation/ValidationError.js";
16
+ import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
17
17
  import { FileSource } from "../source/file.js";
18
18
  import { GenericRichTextSourceNode, RichTextSource } from "../source/richtext.js";
19
19
  import { ReifiedPreview } from "../preview.js";
@@ -40,9 +40,11 @@ export type SchemaAssertResult<Src extends SelectorSource> = {
40
40
  success: false;
41
41
  errors: Record<SourcePath, AssertError[]>;
42
42
  };
43
+ export type CustomValidateFunction<Src extends SelectorSource> = (src: Src) => false | string;
43
44
  export declare abstract class Schema<Src extends SelectorSource> {
44
45
  /** Validate the value of source content */
45
- abstract validate(path: SourcePath, src: Src): ValidationErrors;
46
+ protected abstract executeValidate(path: SourcePath, src: Src): ValidationErrors;
47
+ protected executeCustomValidateFunctions(src: Src, customValidateFunctions: CustomValidateFunction<Src>[]): ValidationError[];
46
48
  /**
47
49
  * Check if the **root** **type** of source is correct.
48
50
  *
@@ -58,12 +60,12 @@ export declare abstract class Schema<Src extends SelectorSource> {
58
60
  * When using assert, you must assert recursively if you want to verify the entire source.
59
61
  * For example, if you have an object schema, you must assert each key / value pair manually.
60
62
  */
61
- abstract assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
63
+ protected abstract executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
62
64
  abstract nullable(): Schema<Src | null>;
63
- abstract serialize(): SerializedSchema;
65
+ protected abstract executeSerialize(): SerializedSchema;
64
66
  protected abstract executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedPreview;
65
67
  /** MUTATES! since internal and perf sensitive */
66
- protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown): ValidationErrors;
68
+ protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown, schemaError?: boolean): ValidationErrors;
67
69
  }
68
70
  export type SelectorOfSchema<T extends Schema<SelectorSource>> = T extends Schema<infer Src> ? Src : never;
69
71
  export {};
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ValModuleBrand } from "../module.js";
3
3
  import { GenericSelector } from "../selector/index.js";
4
4
  import { Source, SourceObject } from "../source/index.js";
@@ -12,18 +12,21 @@ export type SerializedKeyOfSchema = {
12
12
  schema: SerializedSchema;
13
13
  opt: boolean;
14
14
  values: "string" | string[];
15
+ customValidate?: boolean;
15
16
  };
16
17
  type KeyOfSelector<Sel extends GenericSelector<SourceObject>> = Sel extends GenericSelector<infer S> ? S extends readonly Source[] ? number : S extends SourceObject ? string extends keyof S ? RawString : keyof S : S extends Record<string, Source> ? RawString : never : never;
17
18
  export declare class KeyOfSchema<Sel extends GenericSelector<SourceObject>, Src extends KeyOfSelector<Sel> | null> extends Schema<Src> {
18
- readonly schema?: SerializedSchema | undefined;
19
- readonly sourcePath?: SourcePath | undefined;
20
- readonly opt: boolean;
21
- constructor(schema?: SerializedSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean);
22
- validate(path: SourcePath, src: Src): ValidationErrors;
23
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
24
- nullable(): Schema<Src | null>;
25
- serialize(): SerializedSchema;
19
+ private readonly schema?;
20
+ private readonly sourcePath?;
21
+ private readonly opt;
22
+ private readonly customValidateFunctions;
23
+ constructor(schema?: SerializedSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
24
+ validate(validationFunction: (src: Src) => false | string): KeyOfSchema<Sel, Src>;
25
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
26
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
27
+ nullable(): KeyOfSchema<Sel, Src | null>;
28
+ protected executeSerialize(): SerializedSchema;
26
29
  protected executePreview(): ReifiedPreview;
27
30
  }
28
- export declare const keyOf: <Src extends GenericSelector<SourceObject, undefined> & ValModuleBrand>(valModule: Src) => Schema<KeyOfSelector<Src>>;
31
+ export declare const keyOf: <Src extends GenericSelector<SourceObject, undefined> & ValModuleBrand>(valModule: Src) => KeyOfSchema<Src, KeyOfSelector<Src>>;
29
32
  export {};
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
@@ -6,15 +6,18 @@ export type SerializedLiteralSchema = {
6
6
  type: "literal";
7
7
  value: string;
8
8
  opt: boolean;
9
+ customValidate?: boolean;
9
10
  };
10
11
  export declare class LiteralSchema<Src extends string | null> extends Schema<Src> {
11
- readonly value: string;
12
- readonly opt: boolean;
13
- constructor(value: string, opt?: boolean);
14
- validate(path: SourcePath, src: Src): ValidationErrors;
15
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
16
- nullable(): Schema<Src | null>;
17
- serialize(): SerializedSchema;
12
+ private readonly value;
13
+ private readonly opt;
14
+ private readonly customValidateFunctions;
15
+ constructor(value: string, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
16
+ validate(validationFunction: (src: Src) => false | string): LiteralSchema<Src>;
17
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
18
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
19
+ nullable(): LiteralSchema<Src | null>;
20
+ protected executeSerialize(): SerializedSchema;
18
21
  protected executePreview(): ReifiedPreview;
19
22
  }
20
23
  export declare const literal: <T extends string>(value: T) => LiteralSchema<T>;
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
@@ -10,17 +10,20 @@ export type SerializedNumberSchema = {
10
10
  type: "number";
11
11
  options?: NumberOptions;
12
12
  opt: boolean;
13
+ customValidate?: boolean;
13
14
  };
14
15
  export declare class NumberSchema<Src extends number | null> extends Schema<Src> {
15
- readonly options?: NumberOptions | undefined;
16
- readonly opt: boolean;
17
- constructor(options?: NumberOptions | undefined, opt?: boolean);
18
- validate(path: SourcePath, src: Src): ValidationErrors;
19
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
20
- nullable(): Schema<Src>;
16
+ private readonly options?;
17
+ private readonly opt;
18
+ private readonly customValidateFunctions;
19
+ constructor(options?: NumberOptions | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
20
+ validate(validationFunction: (src: Src) => false | string): NumberSchema<Src>;
21
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
22
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
23
+ nullable(): NumberSchema<Src | null>;
21
24
  max(max: number): NumberSchema<Src>;
22
25
  min(min: number): NumberSchema<Src>;
23
- serialize(): SerializedSchema;
26
+ protected executeSerialize(): SerializedSchema;
24
27
  protected executePreview(): ReifiedPreview;
25
28
  }
26
29
  export declare const number: (options?: NumberOptions) => NumberSchema<number>;
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { SelectorSource } from "../selector/index.js";
4
4
  import { ModuleFilePath, SourcePath } from "../val/index.js";
@@ -7,6 +7,7 @@ export type SerializedObjectSchema = {
7
7
  type: "object";
8
8
  items: Record<string, SerializedSchema>;
9
9
  opt: boolean;
10
+ customValidate?: boolean;
10
11
  };
11
12
  type ObjectSchemaProps = {
12
13
  [key: string]: Schema<SelectorSource>;
@@ -30,14 +31,16 @@ type ObjectSchemaSrcOf<Props extends ObjectSchemaProps> = {
30
31
  [key in keyof Props]: SelectorOfSchema<Props[key]>;
31
32
  };
32
33
  export declare class ObjectSchema<Props extends ObjectSchemaProps, Src extends ObjectSchemaSrcOf<Props> | null> extends Schema<Src> {
33
- readonly items: Props;
34
- readonly opt: boolean;
35
- constructor(items: Props, opt?: boolean);
36
- validate(path: SourcePath, src: Src): ValidationErrors;
37
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
38
- nullable(): Schema<Src | null>;
39
- serialize(): SerializedSchema;
34
+ private readonly items;
35
+ private readonly opt;
36
+ private readonly customValidateFunctions;
37
+ constructor(items: Props, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
38
+ validate(validationFunction: (src: Src) => false | string): ObjectSchema<Props, Src>;
39
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
40
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
41
+ nullable(): ObjectSchema<Props, Src | null>;
42
+ protected executeSerialize(): SerializedSchema;
40
43
  protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedPreview;
41
44
  }
42
- export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => Schema<{ [key in keyof Props]: SelectorOfSchema<Props[key]>; }>;
45
+ export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => ObjectSchema<Props, ObjectSchemaSrcOf<Props>>;
43
46
  export {};
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
2
  import { PreviewSelector, ReifiedPreview } from "../preview.js";
3
3
  import { SelectorSource } from "../selector/index.js";
4
4
  import { ImageSource } from "../source/image.js";
@@ -10,15 +10,18 @@ export type SerializedRecordSchema = {
10
10
  type: "record";
11
11
  item: SerializedSchema;
12
12
  opt: boolean;
13
+ customValidate?: boolean;
13
14
  };
14
15
  export declare class RecordSchema<T extends Schema<SelectorSource>, Src extends Record<string, SelectorOfSchema<T>> | null> extends Schema<Src> {
15
- readonly item: T;
16
- readonly opt: boolean;
17
- constructor(item: T, opt?: boolean);
18
- validate(path: SourcePath, src: Src): ValidationErrors;
19
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
20
- nullable(): Schema<Src | null>;
21
- serialize(): SerializedRecordSchema;
16
+ private readonly item;
17
+ private readonly opt;
18
+ private readonly customValidateFunctions;
19
+ constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
20
+ validate(validationFunction: (src: Src) => false | string): RecordSchema<T, Src>;
21
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
22
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
23
+ nullable(): RecordSchema<T, Src | null>;
24
+ executeSerialize(): SerializedRecordSchema;
22
25
  private previewInput;
23
26
  protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedPreview;
24
27
  preview(input: {
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { ImageSource } from "../source/image.js";
4
4
  import { RichTextSource, RichTextOptions, SerializedRichTextOptions } from "../source/richtext.js";
@@ -13,19 +13,22 @@ export type SerializedRichTextSchema = {
13
13
  type: "richtext";
14
14
  opt: boolean;
15
15
  options?: SerializedRichTextOptions & ValidationOptions;
16
+ customValidate?: boolean;
16
17
  };
17
18
  export declare class RichTextSchema<O extends RichTextOptions, Src extends RichTextSource<O> | null> extends Schema<Src> {
18
- readonly options: O & ValidationOptions;
19
- readonly opt: boolean;
20
- constructor(options: O & ValidationOptions, opt?: boolean);
19
+ private readonly options;
20
+ private readonly opt;
21
+ private readonly customValidateFunctions;
22
+ constructor(options: O & ValidationOptions, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
21
23
  maxLength(max: number): RichTextSchema<O, Src>;
22
24
  minLength(min: number): RichTextSchema<O, Src>;
23
- validate(path: SourcePath, src: Src): ValidationErrors;
25
+ validate(validationFunction: (src: Src) => false | string): RichTextSchema<O, Src>;
26
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
24
27
  private internalValidate;
25
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
28
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
26
29
  private recursiveAssert;
27
- nullable(): Schema<Src | null>;
28
- serialize(): SerializedSchema;
30
+ nullable(): RichTextSchema<O, Src | null>;
31
+ protected executeSerialize(): SerializedSchema;
29
32
  protected executePreview(): ReifiedPreview;
30
33
  }
31
34
  export declare const richtext: <O extends Partial<{
@@ -6,6 +6,7 @@ type StringOptions = {
6
6
  maxLength?: number;
7
7
  minLength?: number;
8
8
  regexp?: RegExp;
9
+ regExpMessage?: string;
9
10
  };
10
11
  export type SerializedStringSchema = {
11
12
  type: "string";
@@ -13,22 +14,26 @@ export type SerializedStringSchema = {
13
14
  maxLength?: number;
14
15
  minLength?: number;
15
16
  regexp?: {
17
+ message?: string;
16
18
  source: string;
17
19
  flags: string;
18
20
  };
21
+ customValidate?: boolean;
19
22
  };
20
23
  opt: boolean;
21
24
  raw: boolean;
25
+ customValidate?: boolean;
22
26
  };
23
27
  declare const brand: unique symbol;
24
28
  export type RawString = string & {
25
29
  readonly [brand]: "raw";
26
30
  };
27
31
  export declare class StringSchema<Src extends string | null> extends Schema<Src> {
28
- readonly options?: StringOptions | undefined;
29
- readonly opt: boolean;
32
+ private readonly options?;
33
+ private readonly opt;
30
34
  private readonly isRaw;
31
- constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean);
35
+ private readonly customValidateFunctions;
36
+ constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean, customValidateFunctions?: ((src: Src) => false | string)[]);
32
37
  /**
33
38
  * @deprecated Use `minLength` instead
34
39
  */
@@ -39,12 +44,13 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
39
44
  */
40
45
  max(maxLength: number): StringSchema<Src>;
41
46
  maxLength(maxLength: number): StringSchema<Src>;
42
- regexp(regexp: RegExp): StringSchema<Src>;
43
- validate(path: SourcePath, src: Src): ValidationErrors;
44
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
47
+ regexp(regexp: RegExp, message?: string): StringSchema<Src>;
48
+ validate(validationFunction: (src: Src) => false | string): StringSchema<Src>;
49
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
50
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
45
51
  nullable(): StringSchema<Src | null>;
46
52
  raw(): StringSchema<Src extends null ? RawString | null : RawString>;
47
- serialize(): SerializedSchema;
53
+ protected executeSerialize(): SerializedSchema;
48
54
  protected executePreview(): ReifiedPreview;
49
55
  }
50
56
  export declare const string: <T extends string>(options?: Record<string, never>) => StringSchema<T>;
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
1
+ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { ReifiedPreview } from "../preview.js";
3
3
  import { SelectorSource } from "../selector/index.js";
4
4
  import { SourceObject } from "../source/index.js";
@@ -12,12 +12,14 @@ export type SerializedStringUnionSchema = {
12
12
  key: SerializedLiteralSchema;
13
13
  items: SerializedLiteralSchema[];
14
14
  opt: boolean;
15
+ customValidate?: boolean;
15
16
  };
16
17
  export type SerializedObjectUnionSchema = {
17
18
  type: "union";
18
19
  key: string;
19
20
  items: SerializedObjectSchema[];
20
21
  opt: boolean;
22
+ customValidate?: boolean;
21
23
  };
22
24
  type SourceOf<Key extends string | Schema<string>, T extends Schema<Key extends string ? SourceObject & {
23
25
  [k in Key]: string;
@@ -25,14 +27,16 @@ type SourceOf<Key extends string | Schema<string>, T extends Schema<Key extends
25
27
  export declare class UnionSchema<Key extends string | Schema<string>, T extends Schema<Key extends string ? SourceObject & {
26
28
  [k in Key]: string;
27
29
  } : Key extends Schema<string> ? string : unknown>[], Src extends SourceOf<Key, T> | null> extends Schema<Src> {
28
- readonly key: Key;
29
- readonly items: T;
30
- readonly opt: boolean;
31
- validate(path: SourcePath, src: Src): ValidationErrors;
32
- assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
33
- nullable(): Schema<Src | null>;
34
- serialize(): SerializedSchema;
35
- constructor(key: Key, items: T, opt?: boolean);
30
+ private readonly key;
31
+ private readonly items;
32
+ private readonly opt;
33
+ private readonly customValidateFunctions;
34
+ validate(validationFunction: (src: Src) => false | string): UnionSchema<Key, T, Src>;
35
+ protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
36
+ protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
37
+ nullable(): UnionSchema<Key, T, Src | null>;
38
+ protected executeSerialize(): SerializedSchema;
39
+ constructor(key: Key, items: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[]);
36
40
  protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedPreview;
37
41
  }
38
42
  export declare const union: <Key extends string | Schema<string>, T extends Schema<Key extends string ? {
@@ -45,5 +49,5 @@ export declare const union: <Key extends string | Schema<string>, T extends Sche
45
49
  _type?: undefined;
46
50
  val?: undefined;
47
51
  valPath?: undefined;
48
- } & { [k in Key]: string; } : Key extends Schema<string> ? string : unknown>[]>(key: Key, ...objects: T) => Schema<SourceOf<Key, T>>;
52
+ } & { [k in Key]: string; } : Key extends Schema<string> ? string : unknown>[]>(key: Key, ...objects: T) => UnionSchema<Key, T, SourceOf<Key, T>>;
49
53
  export {};
@@ -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 ImageMetadata | FileMetadata>(ref: RemoteRef, metadata: Metadata) => RemoteSource<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;