@valbuild/core 0.63.5 → 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.
- package/dist/declarations/src/index.d.ts +12 -89
- package/dist/declarations/src/initSchema.d.ts +4 -1
- package/dist/declarations/src/mimeType/all.d.ts +4 -0
- package/dist/declarations/src/mimeType/convertMimeType.d.ts +3 -0
- package/dist/declarations/src/mimeType/index.d.ts +2 -0
- package/dist/declarations/src/schema/array.d.ts +5 -5
- package/dist/declarations/src/schema/boolean.d.ts +2 -2
- package/dist/declarations/src/schema/date.d.ts +38 -0
- package/dist/declarations/src/schema/file.d.ts +5 -3
- package/dist/declarations/src/schema/image.d.ts +4 -3
- package/dist/declarations/src/schema/index.d.ts +46 -4
- package/dist/declarations/src/schema/keyOf.d.ts +5 -5
- package/dist/declarations/src/schema/literal.d.ts +3 -3
- package/dist/declarations/src/schema/number.d.ts +3 -3
- package/dist/declarations/src/schema/object.d.ts +5 -5
- package/dist/declarations/src/schema/record.d.ts +5 -5
- package/dist/declarations/src/schema/richtext.d.ts +5 -4
- package/dist/declarations/src/schema/string.d.ts +2 -2
- package/dist/declarations/src/schema/union.d.ts +5 -5
- package/dist/declarations/src/schema/validation/ValidationError.d.ts +2 -1
- package/dist/declarations/src/selector/SelectorProxy.d.ts +1 -0
- package/dist/declarations/src/source/richtext.d.ts +7 -0
- package/dist/declarations/src/val/index.d.ts +1 -1
- package/dist/{index-7c62e0da.cjs.prod.js → index-41223963.cjs.prod.js} +1697 -818
- package/dist/{index-3c8b4776.esm.js → index-4240c6a6.esm.js} +1696 -818
- package/dist/{index-3388fb33.cjs.dev.js → index-d384ec25.cjs.dev.js} +1697 -818
- package/dist/valbuild-core.cjs.dev.js +3 -2
- package/dist/valbuild-core.cjs.prod.js +3 -2
- package/dist/valbuild-core.esm.js +1 -1
- package/expr/dist/valbuild-core-expr.cjs.dev.js +1 -1
- package/expr/dist/valbuild-core-expr.cjs.prod.js +1 -1
- package/expr/dist/valbuild-core-expr.esm.js +1 -1
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
- 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 {
|
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
|
32
|
-
import { Operation, Patch } from "./patch/index.js";
|
30
|
+
import { Operation } from "./patch/index.js";
|
33
31
|
import { initSchema } from "./initSchema.js";
|
34
|
-
import {
|
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";
|
@@ -40,96 +38,14 @@ export { type SerializedNumberSchema, NumberSchema } from "./schema/number.js";
|
|
40
38
|
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";
|
41
|
+
export { type SerializedDateSchema, DateSchema } from "./schema/date.js";
|
42
|
+
export { type SerializedKeyOfSchema, KeyOfSchema } from "./schema/keyOf.js";
|
43
43
|
export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtext.js";
|
44
44
|
export { type SerializedUnionSchema, UnionSchema } from "./schema/union.js";
|
45
45
|
export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
|
46
46
|
export { deserializeSchema } from "./schema/deserialize.js";
|
47
|
-
export { ValApi } from "./ValApi.js";
|
48
|
-
export type ApiCommitResponse = {};
|
49
|
-
export type ApiSchemaResponse = {
|
50
|
-
schemaSha: string;
|
51
|
-
schemas: Record<ModuleFilePath, SerializedSchema>;
|
52
|
-
};
|
53
|
-
export type ApiTreeResponse = {
|
54
|
-
schemaSha: string;
|
55
|
-
fatalErrors?: ({
|
56
|
-
message: string;
|
57
|
-
type: "invalid-module-file-path";
|
58
|
-
actualModuleFilePath: string;
|
59
|
-
expectedModuleFilePath: string;
|
60
|
-
} | {
|
61
|
-
message: string;
|
62
|
-
stack?: string;
|
63
|
-
type?: undefined;
|
64
|
-
})[];
|
65
|
-
newPatchId?: PatchId;
|
66
|
-
modules: Record<ModuleFilePath, {
|
67
|
-
source: Json;
|
68
|
-
patches?: {
|
69
|
-
applied: PatchId[];
|
70
|
-
skipped?: PatchId[];
|
71
|
-
errors?: Record<PatchId, {
|
72
|
-
message: string;
|
73
|
-
}>;
|
74
|
-
};
|
75
|
-
validationErrors?: Record<SourcePath, ValidationError[]>;
|
76
|
-
}>;
|
77
|
-
};
|
78
|
-
export type ApiGetPatchResponse = {
|
79
|
-
patches: Record<PatchId, {
|
80
|
-
path: ModuleFilePath;
|
81
|
-
patch?: Patch;
|
82
|
-
createdAt: string;
|
83
|
-
authorId: string | null;
|
84
|
-
appliedAt: {
|
85
|
-
baseSha: string;
|
86
|
-
git?: {
|
87
|
-
commitSha: string;
|
88
|
-
};
|
89
|
-
timestamp: string;
|
90
|
-
} | null;
|
91
|
-
}>;
|
92
|
-
error?: {
|
93
|
-
message: string;
|
94
|
-
};
|
95
|
-
errors?: Record<PatchId, {
|
96
|
-
message: string;
|
97
|
-
}>;
|
98
|
-
};
|
99
|
-
export type ApiDeletePatchResponse = PatchId[];
|
100
|
-
export type ApiPostPatchResponse = Record<ModuleFilePath, {
|
101
|
-
patch_id: PatchId;
|
102
|
-
}>;
|
103
|
-
export type ApiPostValidationResponse = {
|
104
|
-
validationErrors: false;
|
105
|
-
modules: Record<ModuleFilePath, {
|
106
|
-
patches: {
|
107
|
-
applied: PatchId[];
|
108
|
-
};
|
109
|
-
}>;
|
110
|
-
};
|
111
47
|
export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
|
112
48
|
export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
|
113
|
-
export type ApiPostValidationErrorResponse = {
|
114
|
-
modules: Record<ModuleFilePath, {
|
115
|
-
patches: {
|
116
|
-
applied: PatchId[];
|
117
|
-
failed?: PatchId[];
|
118
|
-
};
|
119
|
-
}>;
|
120
|
-
validationErrors: Record<ModuleFilePath, {
|
121
|
-
source?: Json;
|
122
|
-
errors: {
|
123
|
-
invalidModulePath?: ModuleFilePath;
|
124
|
-
validation?: ValidationErrors;
|
125
|
-
fatal?: {
|
126
|
-
message: string;
|
127
|
-
stack?: string;
|
128
|
-
type?: FatalErrorType;
|
129
|
-
}[];
|
130
|
-
};
|
131
|
-
}>;
|
132
|
-
};
|
133
49
|
declare const Internal: {
|
134
50
|
VERSION: {
|
135
51
|
core: string | null;
|
@@ -145,6 +61,13 @@ declare const Internal: {
|
|
145
61
|
createValPathOfItem: typeof createValPathOfItem;
|
146
62
|
getSHA256Hash: (bits: Uint8Array) => string;
|
147
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
|
+
};
|
148
71
|
ModuleFilePathSep: string;
|
149
72
|
notFileOp: (op: Operation) => boolean;
|
150
73
|
isFileOp: (op: Operation) => op is {
|
@@ -10,6 +10,7 @@ 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 { date } from "./schema/date.js";
|
13
14
|
export type InitSchema = {
|
14
15
|
readonly string: typeof string;
|
15
16
|
readonly boolean: typeof boolean;
|
@@ -23,6 +24,7 @@ export type InitSchema = {
|
|
23
24
|
readonly keyOf: typeof keyOf;
|
24
25
|
readonly record: typeof record;
|
25
26
|
readonly file: typeof file;
|
27
|
+
readonly date: typeof date;
|
26
28
|
};
|
27
29
|
export declare function initSchema(): {
|
28
30
|
string: <T extends string>(options?: Record<string, never> | undefined) => import("./schema/string.js").StringSchema<T>;
|
@@ -76,8 +78,9 @@ export declare function initSchema(): {
|
|
76
78
|
}>;
|
77
79
|
}>>(options?: O | undefined) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
|
78
80
|
image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").ImageSource>;
|
79
|
-
literal: <T_2 extends string>(value: T_2) => import("./schema/
|
81
|
+
literal: <T_2 extends string>(value: T_2) => import("./schema/literal.js").LiteralSchema<T_2>;
|
80
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>;
|
81
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>>>;
|
82
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: (options?: Record<string, never> | undefined) => import("./schema/date.js").DateSchema<import("./schema/string.js").RawString>;
|
83
86
|
};
|
@@ -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
|
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:
|
15
|
-
assert(src:
|
16
|
-
nullable(): Schema<
|
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:
|
12
|
+
assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
13
13
|
nullable(): Schema<Src | null>;
|
14
14
|
serialize(): SerializedSchema;
|
15
15
|
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
2
|
+
import { SourcePath } from "../val/index.js";
|
3
|
+
import { RawString } from "./string.js";
|
4
|
+
import { ValidationErrors } from "./validation/ValidationError.js";
|
5
|
+
type DateOptions = {
|
6
|
+
/**
|
7
|
+
* Validate that the date is this date or after (inclusive).
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* 2021-01-01
|
11
|
+
*/
|
12
|
+
from?: string;
|
13
|
+
/**
|
14
|
+
* Validate that the date is this date or before (inclusive).
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
* 2021-01-01
|
18
|
+
*/
|
19
|
+
to?: string;
|
20
|
+
};
|
21
|
+
export type SerializedDateSchema = {
|
22
|
+
type: "date";
|
23
|
+
options?: DateOptions;
|
24
|
+
opt: boolean;
|
25
|
+
};
|
26
|
+
export declare class DateSchema<Src extends string | null> extends Schema<Src> {
|
27
|
+
readonly options?: DateOptions | undefined;
|
28
|
+
readonly opt: boolean;
|
29
|
+
constructor(options?: DateOptions | undefined, opt?: boolean);
|
30
|
+
validate(path: SourcePath, src: Src): ValidationErrors;
|
31
|
+
assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
32
|
+
from(from: string): DateSchema<Src>;
|
33
|
+
to(to: string): DateSchema<Src>;
|
34
|
+
nullable(): DateSchema<Src | null>;
|
35
|
+
serialize(): SerializedSchema;
|
36
|
+
}
|
37
|
+
export declare const date: (options?: Record<string, never>) => DateSchema<RawString>;
|
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 =
|
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:
|
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
|
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:
|
34
|
+
assert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
34
35
|
nullable(): Schema<Src | null>;
|
35
36
|
serialize(): SerializedSchema;
|
36
37
|
}
|
@@ -10,16 +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
|
+
import { SerializedDateSchema } from "./date.js";
|
15
16
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
16
|
-
|
17
|
+
import { FileSource } from "../source/file.js";
|
18
|
+
import { GenericRichTextSourceNode, RichTextSource } from "../source/richtext.js";
|
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
|
+
};
|
17
42
|
export declare abstract class Schema<Src extends SelectorSource> {
|
43
|
+
/** Validate the value of source content */
|
18
44
|
abstract validate(path: SourcePath, src: Src): ValidationErrors;
|
19
|
-
|
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>;
|
20
61
|
abstract nullable(): Schema<Src | null>;
|
21
62
|
abstract serialize(): SerializedSchema;
|
22
63
|
/** MUTATES! since internal and perf sensitive */
|
23
|
-
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value
|
64
|
+
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown): ValidationErrors;
|
24
65
|
}
|
25
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
|
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:
|
22
|
-
assert(src:
|
23
|
-
nullable(): Schema<
|
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:
|
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) =>
|
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:
|
19
|
-
nullable(): Schema<Src
|
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
|
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:
|
36
|
-
assert(src:
|
37
|
-
nullable(): Schema<
|
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
|
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:
|
15
|
-
assert(
|
16
|
-
nullable(): Schema<
|
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
|
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:
|
16
|
-
|
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:
|
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>[]
|
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:
|
22
|
-
assert(
|
23
|
-
nullable(): Schema<
|
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
|
}
|
@@ -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
|
25
|
+
declare const brand = "VAL_DATA_TYPE";
|
26
26
|
/**
|
27
27
|
* The path of the source value.
|
28
28
|
*
|