@valbuild/core 0.63.6 → 0.64.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 (37) hide show
  1. package/dist/declarations/src/index.d.ts +11 -89
  2. package/dist/declarations/src/initSchema.d.ts +2 -2
  3. package/dist/declarations/src/mimeType/all.d.ts +4 -0
  4. package/dist/declarations/src/mimeType/convertMimeType.d.ts +3 -0
  5. package/dist/declarations/src/mimeType/index.d.ts +2 -0
  6. package/dist/declarations/src/schema/array.d.ts +5 -5
  7. package/dist/declarations/src/schema/boolean.d.ts +2 -2
  8. package/dist/declarations/src/schema/date.d.ts +5 -5
  9. package/dist/declarations/src/schema/file.d.ts +5 -3
  10. package/dist/declarations/src/schema/image.d.ts +4 -3
  11. package/dist/declarations/src/schema/index.d.ts +44 -3
  12. package/dist/declarations/src/schema/keyOf.d.ts +5 -5
  13. package/dist/declarations/src/schema/literal.d.ts +3 -3
  14. package/dist/declarations/src/schema/number.d.ts +3 -3
  15. package/dist/declarations/src/schema/object.d.ts +5 -5
  16. package/dist/declarations/src/schema/record.d.ts +5 -5
  17. package/dist/declarations/src/schema/richtext.d.ts +5 -4
  18. package/dist/declarations/src/schema/string.d.ts +2 -2
  19. package/dist/declarations/src/schema/union.d.ts +5 -5
  20. package/dist/declarations/src/schema/validation/ValidationError.d.ts +2 -1
  21. package/dist/declarations/src/selector/SelectorProxy.d.ts +1 -0
  22. package/dist/declarations/src/source/richtext.d.ts +7 -0
  23. package/dist/declarations/src/val/index.d.ts +1 -1
  24. package/dist/{index-041f75bd.cjs.prod.js → index-41223963.cjs.prod.js} +1583 -815
  25. package/dist/{index-fccba617.esm.js → index-4240c6a6.esm.js} +1583 -815
  26. package/dist/{index-c67ed8f9.cjs.dev.js → index-d384ec25.cjs.dev.js} +1583 -815
  27. package/dist/valbuild-core.cjs.dev.js +2 -2
  28. package/dist/valbuild-core.cjs.prod.js +2 -2
  29. package/dist/valbuild-core.esm.js +1 -1
  30. package/expr/dist/valbuild-core-expr.cjs.dev.js +1 -1
  31. package/expr/dist/valbuild-core-expr.cjs.prod.js +1 -1
  32. package/expr/dist/valbuild-core-expr.esm.js +1 -1
  33. package/package.json +1 -1
  34. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  35. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  36. package/patch/dist/valbuild-core-patch.esm.js +2 -2
  37. package/dist/declarations/src/ValApi.d.ts +0 -54
@@ -15,7 +15,6 @@ export type { AllRichTextOptions, Bold, Styles, HeadingNode, ImageNode, Italic,
15
15
  export { type Val, type SerializedVal, type ModuleFilePath, type PatchId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
16
16
  export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json.js";
17
17
  export type { ValidationError, ValidationErrors, } from "./schema/validation/ValidationError.js";
18
- import type { ValidationError, ValidationErrors } from "./schema/validation/ValidationError.js";
19
18
  export type { ValidationFix } from "./schema/validation/ValidationFix.js";
20
19
  export * as expr from "./expr/index.js";
21
20
  export { FILE_REF_PROP, FILE_REF_SUBTYPE_TAG } from "./source/file.js";
@@ -24,14 +23,13 @@ export { derefPatch } from "./patch/deref.js";
24
23
  export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector/index.js";
25
24
  import { getSource, resolvePath, splitModuleFilePathAndModulePath } from "./module.js";
26
25
  import { getSchema } from "./selector/index.js";
27
- import { ModuleFilePath, ModulePath, PatchId, SourcePath, getValPath, isVal } from "./val/index.js";
26
+ import { ModulePath, getValPath, isVal } from "./val/index.js";
28
27
  import { convertFileSource } from "./schema/file.js";
29
28
  import { createValPathOfItem } from "./selector/SelectorProxy.js";
30
29
  import { getVal } from "./future/fetchVal.js";
31
- import type { Json } from "./Json.js";
32
- import { Operation, Patch } from "./patch/index.js";
30
+ import { Operation } from "./patch/index.js";
33
31
  import { initSchema } from "./initSchema.js";
34
- import { SerializedSchema } from "./schema/index.js";
32
+ import { getMimeType, mimeTypeToFileExt, filenameToMimeType } from "./mimeType/index.js";
35
33
  export { type SerializedArraySchema, ArraySchema } from "./schema/array.js";
36
34
  export { type SerializedObjectSchema, ObjectSchema } from "./schema/object.js";
37
35
  export { type SerializedRecordSchema, RecordSchema } from "./schema/record.js";
@@ -41,96 +39,13 @@ export { type SerializedBooleanSchema, BooleanSchema } from "./schema/boolean.js
41
39
  export { type SerializedImageSchema, ImageSchema } from "./schema/image.js";
42
40
  export { type SerializedFileSchema, FileSchema } from "./schema/file.js";
43
41
  export { type SerializedDateSchema, DateSchema } from "./schema/date.js";
42
+ export { type SerializedKeyOfSchema, KeyOfSchema } from "./schema/keyOf.js";
44
43
  export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtext.js";
45
44
  export { type SerializedUnionSchema, UnionSchema } from "./schema/union.js";
46
45
  export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
47
46
  export { deserializeSchema } from "./schema/deserialize.js";
48
- export { ValApi } from "./ValApi.js";
49
- export type ApiCommitResponse = {};
50
- export type ApiSchemaResponse = {
51
- schemaSha: string;
52
- schemas: Record<ModuleFilePath, SerializedSchema>;
53
- };
54
- export type ApiTreeResponse = {
55
- schemaSha: string;
56
- fatalErrors?: ({
57
- message: string;
58
- type: "invalid-module-file-path";
59
- actualModuleFilePath: string;
60
- expectedModuleFilePath: string;
61
- } | {
62
- message: string;
63
- stack?: string;
64
- type?: undefined;
65
- })[];
66
- newPatchId?: PatchId;
67
- modules: Record<ModuleFilePath, {
68
- source: Json;
69
- patches?: {
70
- applied: PatchId[];
71
- skipped?: PatchId[];
72
- errors?: Record<PatchId, {
73
- message: string;
74
- }>;
75
- };
76
- validationErrors?: Record<SourcePath, ValidationError[]>;
77
- }>;
78
- };
79
- export type ApiGetPatchResponse = {
80
- patches: Record<PatchId, {
81
- path: ModuleFilePath;
82
- patch?: Patch;
83
- createdAt: string;
84
- authorId: string | null;
85
- appliedAt: {
86
- baseSha: string;
87
- git?: {
88
- commitSha: string;
89
- };
90
- timestamp: string;
91
- } | null;
92
- }>;
93
- error?: {
94
- message: string;
95
- };
96
- errors?: Record<PatchId, {
97
- message: string;
98
- }>;
99
- };
100
- export type ApiDeletePatchResponse = PatchId[];
101
- export type ApiPostPatchResponse = Record<ModuleFilePath, {
102
- patch_id: PatchId;
103
- }>;
104
- export type ApiPostValidationResponse = {
105
- validationErrors: false;
106
- modules: Record<ModuleFilePath, {
107
- patches: {
108
- applied: PatchId[];
109
- };
110
- }>;
111
- };
112
47
  export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
113
48
  export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
114
- export type ApiPostValidationErrorResponse = {
115
- modules: Record<ModuleFilePath, {
116
- patches: {
117
- applied: PatchId[];
118
- failed?: PatchId[];
119
- };
120
- }>;
121
- validationErrors: Record<ModuleFilePath, {
122
- source?: Json;
123
- errors: {
124
- invalidModulePath?: ModuleFilePath;
125
- validation?: ValidationErrors;
126
- fatal?: {
127
- message: string;
128
- stack?: string;
129
- type?: FatalErrorType;
130
- }[];
131
- };
132
- }>;
133
- };
134
49
  declare const Internal: {
135
50
  VERSION: {
136
51
  core: string | null;
@@ -146,6 +61,13 @@ declare const Internal: {
146
61
  createValPathOfItem: typeof createValPathOfItem;
147
62
  getSHA256Hash: (bits: Uint8Array) => string;
148
63
  initSchema: typeof initSchema;
64
+ getMimeType: typeof getMimeType;
65
+ mimeTypeToFileExt: typeof mimeTypeToFileExt;
66
+ filenameToMimeType: typeof filenameToMimeType;
67
+ EXT_TO_MIME_TYPES: Record<string, string>;
68
+ MIME_TYPES_TO_EXT: {
69
+ [k: string]: string;
70
+ };
149
71
  ModuleFilePathSep: string;
150
72
  notFileOp: (op: Operation) => boolean;
151
73
  isFileOp: (op: Operation) => op is {
@@ -78,9 +78,9 @@ export declare function initSchema(): {
78
78
  }>;
79
79
  }>>(options?: O | undefined) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
80
80
  image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").ImageSource>;
81
- literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
81
+ literal: <T_2 extends string>(value: T_2) => import("./schema/literal.js").LiteralSchema<T_2>;
82
82
  keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject | import("./source/index.js").SourceArray, 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>;
83
83
  record: <S_3 extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S_3) => import("./schema/index.js").Schema<Record<string, import("./schema/index.js").SelectorOfSchema<S_3>>>;
84
84
  file: (options?: import("./schema/file.js").FileOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").FileSource<import("./schema/file.js").FileMetadata>>;
85
- date: <T_3 extends string>(options?: Record<string, never> | undefined) => import("./schema/date.js").DateSchema<T_3>;
85
+ date: (options?: Record<string, never> | undefined) => import("./schema/date.js").DateSchema<import("./schema/string.js").RawString>;
86
86
  };
@@ -0,0 +1,4 @@
1
+ export declare const EXT_TO_MIME_TYPES: Record<string, string>;
2
+ export declare const MIME_TYPES_TO_EXT: {
3
+ [k: string]: string;
4
+ };
@@ -0,0 +1,3 @@
1
+ export declare function getMimeType(base64Url: string): string | undefined;
2
+ export declare function mimeTypeToFileExt(mimeType: string): string;
3
+ export declare function filenameToMimeType(filename: string): string | undefined;
@@ -0,0 +1,2 @@
1
+ export * from "./convertMimeType.js";
2
+ export * from "./all.js";
@@ -1,4 +1,4 @@
1
- import { Schema, SelectorOfSchema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
2
  import { SelectorSource } from "../selector/index.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
@@ -7,13 +7,13 @@ export type SerializedArraySchema = {
7
7
  item: SerializedSchema;
8
8
  opt: boolean;
9
9
  };
10
- export declare class ArraySchema<T extends Schema<SelectorSource>> extends Schema<SelectorOfSchema<T>[]> {
10
+ export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends SelectorOfSchema<T>[] | null> extends Schema<Src> {
11
11
  readonly item: T;
12
12
  readonly opt: boolean;
13
13
  constructor(item: T, opt?: boolean);
14
- validate(path: SourcePath, src: SelectorOfSchema<T>[]): ValidationErrors;
15
- assert(src: SelectorOfSchema<T>[]): boolean;
16
- nullable(): Schema<SelectorOfSchema<T>[] | null>;
14
+ validate(path: SourcePath, src: Src): ValidationErrors;
15
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
16
+ nullable(): Schema<Src | null>;
17
17
  serialize(): SerializedArraySchema;
18
18
  }
19
19
  export declare const array: <S extends Schema<SelectorSource>>(schema: S) => Schema<SelectorOfSchema<S>[]>;
@@ -1,4 +1,4 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
3
  import { ValidationErrors } from "./validation/ValidationError.js";
4
4
  export type SerializedBooleanSchema = {
@@ -9,7 +9,7 @@ export declare class BooleanSchema<Src extends boolean | null> extends Schema<Sr
9
9
  readonly opt: boolean;
10
10
  constructor(opt?: boolean);
11
11
  validate(path: SourcePath, src: Src): ValidationErrors;
12
- assert(src: Src): boolean;
12
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
13
13
  nullable(): Schema<Src | null>;
14
14
  serialize(): SerializedSchema;
15
15
  }
@@ -1,5 +1,6 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
+ import { RawString } from "./string.js";
3
4
  import { ValidationErrors } from "./validation/ValidationError.js";
4
5
  type DateOptions = {
5
6
  /**
@@ -25,14 +26,13 @@ export type SerializedDateSchema = {
25
26
  export declare class DateSchema<Src extends string | null> extends Schema<Src> {
26
27
  readonly options?: DateOptions | undefined;
27
28
  readonly opt: boolean;
28
- private readonly isRaw;
29
- constructor(options?: DateOptions | undefined, opt?: boolean, isRaw?: boolean);
29
+ constructor(options?: DateOptions | undefined, opt?: boolean);
30
30
  validate(path: SourcePath, src: Src): ValidationErrors;
31
- assert(src: Src): boolean;
31
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
32
32
  from(from: string): DateSchema<Src>;
33
33
  to(to: string): DateSchema<Src>;
34
34
  nullable(): DateSchema<Src | null>;
35
35
  serialize(): SerializedSchema;
36
36
  }
37
- export declare const date: <T extends string>(options?: Record<string, never>) => DateSchema<T>;
37
+ export declare const date: (options?: Record<string, never>) => DateSchema<RawString>;
38
38
  export {};
@@ -1,9 +1,11 @@
1
1
  import { Json } from "../Json.js";
2
2
  import { FileSource } from "../source/file.js";
3
- import { Schema, SerializedSchema } from "./index.js";
3
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
4
4
  import { SourcePath } from "../val/index.js";
5
5
  import { ValidationErrors } from "./validation/ValidationError.js";
6
- export type FileOptions = Record<string, never>;
6
+ export type FileOptions = {
7
+ accept?: string;
8
+ };
7
9
  export type SerializedFileSchema = {
8
10
  type: "file";
9
11
  options?: FileOptions;
@@ -18,7 +20,7 @@ export declare class FileSchema<Src extends FileSource<FileMetadata | undefined>
18
20
  readonly opt: boolean;
19
21
  constructor(options?: FileOptions | undefined, opt?: boolean);
20
22
  validate(path: SourcePath, src: Src): ValidationErrors;
21
- assert(src: Src): boolean;
23
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
22
24
  nullable(): Schema<Src | null>;
23
25
  serialize(): SerializedSchema;
24
26
  }
@@ -1,12 +1,13 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { 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";
5
5
  import { ValidationErrors } from "./validation/ValidationError.js";
6
6
  export type ImageOptions = {
7
- ext: ["jpg"] | ["webp"];
7
+ ext?: ["jpg"] | ["webp"];
8
8
  directory?: string;
9
9
  prefix?: string;
10
+ accept?: string;
10
11
  };
11
12
  export type SerializedImageSchema = {
12
13
  type: "image";
@@ -30,7 +31,7 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata | undefine
30
31
  readonly opt: boolean;
31
32
  constructor(options?: ImageOptions | undefined, opt?: boolean);
32
33
  validate(path: SourcePath, src: Src): ValidationErrors;
33
- assert(src: Src): boolean;
34
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
34
35
  nullable(): Schema<Src | null>;
35
36
  serialize(): SerializedSchema;
36
37
  }
@@ -10,17 +10,58 @@ import { SerializedNumberSchema } from "./number.js";
10
10
  import { SerializedObjectSchema } from "./object.js";
11
11
  import { SerializedRecordSchema } from "./record.js";
12
12
  import { SerializedRichTextSchema } from "./richtext.js";
13
- import { SerializedStringSchema } from "./string.js";
13
+ import { RawString, SerializedStringSchema } from "./string.js";
14
14
  import { SerializedUnionSchema } from "./union.js";
15
15
  import { SerializedDateSchema } from "./date.js";
16
16
  import { ValidationErrors } from "./validation/ValidationError.js";
17
+ import { FileSource } from "../source/file.js";
18
+ import { GenericRichTextSourceNode, RichTextSource } from "../source/richtext.js";
17
19
  export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedDateSchema | SerializedImageSchema;
20
+ type Primitives = number | string | boolean | null | FileSource;
21
+ export type AssertError = {
22
+ message: string;
23
+ schemaError: true;
24
+ } | {
25
+ message: string;
26
+ typeError: true;
27
+ } | {
28
+ message: string;
29
+ internalError: true;
30
+ };
31
+ export type SchemaAssertResult<Src extends SelectorSource> = {
32
+ data: Src extends RawString ? string : Src extends RichTextSource<{}> ? GenericRichTextSourceNode[] : Src extends Primitives ? Src : Src extends Array<SelectorSource> ? SelectorSource[] : Src extends {
33
+ [key: string]: SelectorSource;
34
+ } ? {
35
+ [key in keyof Src]: SelectorSource;
36
+ } : never;
37
+ success: true;
38
+ } | {
39
+ success: false;
40
+ errors: Record<SourcePath, AssertError[]>;
41
+ };
18
42
  export declare abstract class Schema<Src extends SelectorSource> {
43
+ /** Validate the value of source content */
19
44
  abstract validate(path: SourcePath, src: Src): ValidationErrors;
20
- abstract assert(src: Src): boolean;
45
+ /**
46
+ * Check if the **root** **type** of source is correct.
47
+ *
48
+ * The difference between assert and validate is:
49
+ * - assert verifies that the root **type** of the source is correct (it does not recurse down). Therefore, assert can be used as a runtime type check.
50
+ * - validate checks the **value** of the source in addition to the type. It recurses down the source.
51
+ *
52
+ * For example assert fails for a StringSchema if the source is not a string,
53
+ * it will not fail if the length is not correct.
54
+ * Validate will check the length and all other constraints.
55
+ *
56
+ * Assert is useful if you have a generic schema and need to make sure the root type is valid.
57
+ * When using assert, you must assert recursively if you want to verify the entire source.
58
+ * For example, if you have an object schema, you must assert each key / value pair manually.
59
+ */
60
+ abstract assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
21
61
  abstract nullable(): Schema<Src | null>;
22
62
  abstract serialize(): SerializedSchema;
23
63
  /** MUTATES! since internal and perf sensitive */
24
- protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value?: unknown): ValidationErrors;
64
+ protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown): ValidationErrors;
25
65
  }
26
66
  export type SelectorOfSchema<T extends Schema<SelectorSource>> = T extends Schema<infer Src> ? Src : never;
67
+ export {};
@@ -1,4 +1,4 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { 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, SourceArray, SourceObject } from "../source/index.js";
@@ -13,14 +13,14 @@ export type SerializedKeyOfSchema = {
13
13
  values: "string" | "number" | string[];
14
14
  };
15
15
  type KeyOfSelector<Sel extends GenericSelector<SourceArray | 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;
16
- export declare class KeyOfSchema<Sel extends GenericSelector<SourceArray | SourceObject>> extends Schema<KeyOfSelector<Sel>> {
16
+ export declare class KeyOfSchema<Sel extends GenericSelector<SourceArray | SourceObject>, Src extends KeyOfSelector<Sel> | null> extends Schema<Src> {
17
17
  readonly schema?: SerializedSchema | undefined;
18
18
  readonly sourcePath?: SourcePath | undefined;
19
19
  readonly opt: boolean;
20
20
  constructor(schema?: SerializedSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean);
21
- validate(path: SourcePath, src: KeyOfSelector<Sel>): ValidationErrors;
22
- assert(src: KeyOfSelector<Sel>): boolean;
23
- nullable(): Schema<KeyOfSelector<Sel> | null>;
21
+ validate(path: SourcePath, src: Src): ValidationErrors;
22
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
23
+ nullable(): Schema<Src | null>;
24
24
  serialize(): SerializedSchema;
25
25
  }
26
26
  export declare const keyOf: <Src extends GenericSelector<SourceObject | SourceArray, undefined> & ValModuleBrand>(valModule: Src) => Schema<KeyOfSelector<Src>>;
@@ -1,4 +1,4 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
3
  import { ValidationErrors } from "./validation/ValidationError.js";
4
4
  export type SerializedLiteralSchema = {
@@ -11,8 +11,8 @@ export declare class LiteralSchema<Src extends string | null> extends Schema<Src
11
11
  readonly opt: boolean;
12
12
  constructor(value: string, opt?: boolean);
13
13
  validate(path: SourcePath, src: Src): ValidationErrors;
14
- assert(src: Src): boolean;
14
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
15
15
  nullable(): Schema<Src | null>;
16
16
  serialize(): SerializedSchema;
17
17
  }
18
- export declare const literal: <T extends string>(value: T) => Schema<T>;
18
+ export declare const literal: <T extends string>(value: T) => LiteralSchema<T>;
@@ -1,4 +1,4 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
3
  import { ValidationErrors } from "./validation/ValidationError.js";
4
4
  type NumberOptions = {
@@ -15,8 +15,8 @@ export declare class NumberSchema<Src extends number | null> extends Schema<Src>
15
15
  readonly opt: boolean;
16
16
  constructor(options?: NumberOptions | undefined, opt?: boolean);
17
17
  validate(path: SourcePath, src: Src): ValidationErrors;
18
- assert(src: Src): boolean;
19
- nullable(): Schema<Src | null>;
18
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
19
+ nullable(): Schema<Src>;
20
20
  serialize(): SerializedSchema;
21
21
  }
22
22
  export declare const number: (options?: NumberOptions) => Schema<number>;
@@ -1,4 +1,4 @@
1
- import { Schema, SelectorOfSchema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
2
  import { SelectorSource } from "../selector/index.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
@@ -28,13 +28,13 @@ type ObjectSchemaProps = {
28
28
  type ObjectSchemaSrcOf<Props extends ObjectSchemaProps> = {
29
29
  [key in keyof Props]: SelectorOfSchema<Props[key]>;
30
30
  };
31
- export declare class ObjectSchema<Props extends ObjectSchemaProps> extends Schema<ObjectSchemaSrcOf<Props>> {
31
+ export declare class ObjectSchema<Props extends ObjectSchemaProps, Src extends ObjectSchemaSrcOf<Props> | null> extends Schema<Src> {
32
32
  readonly items: Props;
33
33
  readonly opt: boolean;
34
34
  constructor(items: Props, opt?: boolean);
35
- validate(path: SourcePath, src: ObjectSchemaSrcOf<Props>): ValidationErrors;
36
- assert(src: ObjectSchemaSrcOf<Props>): boolean;
37
- nullable(): Schema<ObjectSchemaSrcOf<Props> | null>;
35
+ validate(path: SourcePath, src: Src): ValidationErrors;
36
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
37
+ nullable(): Schema<Src | null>;
38
38
  serialize(): SerializedSchema;
39
39
  }
40
40
  export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => Schema<{ [key in keyof Props]: SelectorOfSchema<Props[key]>; }>;
@@ -1,4 +1,4 @@
1
- import { Schema, SelectorOfSchema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
2
2
  import { SelectorSource } from "../selector/index.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
@@ -7,13 +7,13 @@ export type SerializedRecordSchema = {
7
7
  item: SerializedSchema;
8
8
  opt: boolean;
9
9
  };
10
- export declare class RecordSchema<T extends Schema<SelectorSource>> extends Schema<Record<string, SelectorOfSchema<T>>> {
10
+ export declare class RecordSchema<T extends Schema<SelectorSource>, Src extends Record<string, SelectorOfSchema<T>> | null> extends Schema<Src> {
11
11
  readonly item: T;
12
12
  readonly opt: boolean;
13
13
  constructor(item: T, opt?: boolean);
14
- validate(path: SourcePath, src: Record<string, SelectorOfSchema<T>>): ValidationErrors;
15
- assert(src: Record<string, SelectorOfSchema<T>>): boolean;
16
- nullable(): Schema<Record<string, SelectorOfSchema<T>> | null>;
14
+ validate(path: SourcePath, src: Src): ValidationErrors;
15
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
16
+ nullable(): Schema<Src | null>;
17
17
  serialize(): SerializedRecordSchema;
18
18
  }
19
19
  export declare const record: <S extends Schema<SelectorSource>>(schema: S) => Schema<Record<string, SelectorOfSchema<S>>>;
@@ -1,19 +1,20 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { RichTextSource, RichTextOptions } from "../source/richtext.js";
3
3
  import { SourcePath } from "../val/index.js";
4
4
  import { ValidationErrors } from "./validation/ValidationError.js";
5
5
  export type SerializedRichTextSchema = {
6
6
  type: "richtext";
7
7
  opt: boolean;
8
- options: RichTextOptions;
8
+ options?: RichTextOptions;
9
9
  };
10
10
  export declare class RichTextSchema<O extends RichTextOptions, Src extends RichTextSource<O> | null> extends Schema<Src> {
11
11
  readonly options: O;
12
12
  readonly opt: boolean;
13
13
  constructor(options: O, opt?: boolean);
14
14
  validate(path: SourcePath, src: Src): ValidationErrors;
15
- assert(src: Src): boolean;
16
- nullable(): Schema<RichTextSource<O> | null>;
15
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
16
+ private recursiveAssert;
17
+ nullable(): Schema<Src | null>;
17
18
  serialize(): SerializedSchema;
18
19
  }
19
20
  export declare const richtext: <O extends Partial<{
@@ -1,4 +1,4 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
3
  import { ValidationErrors } from "./validation/ValidationError.js";
4
4
  type StringOptions = {
@@ -32,7 +32,7 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
32
32
  max(maxLength: number): StringSchema<Src>;
33
33
  regexp(regexp: RegExp): StringSchema<Src>;
34
34
  validate(path: SourcePath, src: Src): ValidationErrors;
35
- assert(src: Src): boolean;
35
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
36
36
  nullable(): StringSchema<Src | null>;
37
37
  raw(): StringSchema<Src extends null ? RawString | null : RawString>;
38
38
  serialize(): SerializedSchema;
@@ -1,4 +1,4 @@
1
- import { Schema, SerializedSchema } from "./index.js";
1
+ import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
2
2
  import { SelectorSource } from "../selector/index.js";
3
3
  import { SourceObject } from "../source/index.js";
4
4
  import { SourcePath } from "../val/index.js";
@@ -14,13 +14,13 @@ type SourceOf<Key extends string | Schema<string>, T extends Schema<Key extends
14
14
  } : Key extends Schema<string> ? string : unknown>[]> = T extends Schema<infer S>[] ? S extends SelectorSource ? S | (Key extends Schema<infer K> ? K : never) : never : never;
15
15
  export declare class UnionSchema<Key extends string | Schema<string>, T extends Schema<Key extends string ? SourceObject & {
16
16
  [k in Key]: string;
17
- } : Key extends Schema<string> ? string : unknown>[]> extends Schema<SourceOf<Key, T>> {
17
+ } : Key extends Schema<string> ? string : unknown>[], Src extends SourceOf<Key, T> | null> extends Schema<Src> {
18
18
  readonly key: Key;
19
19
  readonly items: T;
20
20
  readonly opt: boolean;
21
- validate(path: SourcePath, src: SourceOf<Key, T>): ValidationErrors;
22
- assert(src: SourceOf<Key, T>): boolean;
23
- nullable(): Schema<SourceOf<Key, T> | null>;
21
+ validate(path: SourcePath, src: Src): ValidationErrors;
22
+ assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
23
+ nullable(): Schema<Src | null>;
24
24
  serialize(): SerializedSchema;
25
25
  constructor(key: Key, items: T, opt?: boolean);
26
26
  }
@@ -3,7 +3,8 @@ import { ValidationFix } from "./ValidationFix.js";
3
3
  export type ValidationError = {
4
4
  message: string;
5
5
  value?: unknown;
6
- fatal?: boolean;
6
+ typeError?: boolean;
7
+ schemaError?: boolean;
7
8
  fixes?: ValidationFix[];
8
9
  };
9
10
  /**
@@ -4,4 +4,5 @@ import { 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
6
  export declare function createValPathOfItem(arrayPath: SourcePath | ModulePath | undefined, prop: string | number | symbol): SourcePath | undefined;
7
+ export declare function unsafeCreateSourcePath(path: string, itemKey: string | number | symbol): SourcePath;
7
8
  export declare function selectorToVal(s: any): any;
@@ -48,6 +48,13 @@ export type LineThrough<O extends RichTextOptions> = NonNullable<O["style"]>["li
48
48
  export type Italic<O extends RichTextOptions> = NonNullable<O["style"]>["italic"] extends true ? "italic" : never;
49
49
  export type Bold<O extends RichTextOptions> = NonNullable<O["style"]>["bold"] extends true ? "bold" : never;
50
50
  export type Styles<O extends RichTextOptions> = LineThrough<O> | Italic<O> | Bold<O>;
51
+ export type GenericRichTextSourceNode = {
52
+ tag: string;
53
+ styles?: string[];
54
+ href?: string;
55
+ src?: ImageSource;
56
+ children?: (string | GenericRichTextSourceNode)[];
57
+ };
51
58
  export type ParagraphNode<O extends RichTextOptions> = {
52
59
  tag: "p";
53
60
  children: (string | SpanNode<O> | BrNode | LinkNode<O> | ImageNode<O> | CustomInlineNode<O>)[];
@@ -22,7 +22,7 @@ export type Val<T extends Json> = Json extends T ? {
22
22
  readonly val: Source;
23
23
  } : T extends JsonObject ? ObjectVal<T> : T extends JsonArray ? ArrayVal<T> : T extends JsonPrimitive ? PrimitiveVal<T> : never;
24
24
  export declare function isVal<T extends Json>(val: unknown): val is Val<T>;
25
- declare const brand: unique symbol;
25
+ declare const brand = "VAL_DATA_TYPE";
26
26
  /**
27
27
  * The path of the source value.
28
28
  *