@valbuild/core 0.14.0 → 0.16.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 (66) hide show
  1. package/dist/SelectorProxy-2af1b2b8.cjs.prod.js +756 -0
  2. package/dist/SelectorProxy-63c2d0e2.esm.js +722 -0
  3. package/dist/SelectorProxy-873782a5.cjs.dev.js +756 -0
  4. package/dist/declarations/src/index.d.ts +2 -0
  5. package/dist/declarations/src/initVal.d.ts +1 -1
  6. package/dist/declarations/src/patch/index.d.ts +1 -1
  7. package/dist/declarations/src/patch/util.d.ts +2 -0
  8. package/dist/declarations/src/schema/array.d.ts +3 -2
  9. package/dist/declarations/src/schema/boolean.d.ts +3 -2
  10. package/dist/declarations/src/schema/i18n.d.ts +3 -2
  11. package/dist/declarations/src/schema/image.d.ts +3 -2
  12. package/dist/declarations/src/schema/index.d.ts +5 -2
  13. package/dist/declarations/src/schema/literal.d.ts +3 -2
  14. package/dist/declarations/src/schema/number.d.ts +3 -2
  15. package/dist/declarations/src/schema/object.d.ts +3 -2
  16. package/dist/declarations/src/schema/oneOf.d.ts +3 -2
  17. package/dist/declarations/src/schema/richtext.d.ts +3 -2
  18. package/dist/declarations/src/schema/string.d.ts +3 -2
  19. package/dist/declarations/src/schema/union.d.ts +3 -2
  20. package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
  21. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
  22. package/dist/index-2fff5ca8.cjs.dev.js +456 -0
  23. package/dist/{index-06df0a5b.esm.js → index-af761363.esm.js} +2 -555
  24. package/dist/index-cac9ecbd.cjs.prod.js +456 -0
  25. package/dist/ops-1b6e0e35.cjs.prod.js +552 -0
  26. package/dist/ops-74661336.esm.js +541 -0
  27. package/dist/ops-ea4827fc.cjs.dev.js +552 -0
  28. package/dist/valbuild-core.cjs.dev.js +151 -531
  29. package/dist/valbuild-core.cjs.prod.js +151 -531
  30. package/dist/valbuild-core.esm.js +65 -445
  31. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  32. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  33. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  34. package/package.json +2 -1
  35. package/patch/dist/valbuild-core-patch.cjs.dev.js +30 -21
  36. package/patch/dist/valbuild-core-patch.cjs.prod.js +30 -21
  37. package/patch/dist/valbuild-core-patch.esm.js +12 -4
  38. package/src/expr/repl.ts +2 -2
  39. package/src/index.ts +5 -0
  40. package/src/initVal.ts +1 -1
  41. package/src/patch/index.ts +1 -0
  42. package/src/patch/util.ts +7 -0
  43. package/src/schema/array.ts +45 -4
  44. package/src/schema/boolean.ts +14 -3
  45. package/src/schema/i18n.ts +4 -2
  46. package/src/schema/image.ts +65 -5
  47. package/src/schema/index.ts +23 -2
  48. package/src/schema/literal.ts +24 -3
  49. package/src/schema/number.ts +14 -3
  50. package/src/schema/object.ts +50 -7
  51. package/src/schema/oneOf.ts +3 -2
  52. package/src/schema/richtext.ts +63 -3
  53. package/src/schema/string.ts +14 -3
  54. package/src/schema/union.ts +3 -2
  55. package/src/schema/validation/ValidationError.ts +16 -0
  56. package/src/schema/validation/ValidationFix.ts +6 -0
  57. package/src/schema/validation.test.ts +226 -0
  58. package/src/selector/SelectorProxy.ts +1 -1
  59. package/dist/createClass-012eebbf.esm.js +0 -109
  60. package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
  61. package/dist/createClass-de7426aa.cjs.prod.js +0 -116
  62. package/dist/index-9663f28a.cjs.dev.js +0 -1037
  63. package/dist/index-b2270f8f.cjs.prod.js +0 -1037
  64. package/dist/ops-6fae92a1.esm.js +0 -12
  65. package/dist/ops-87cdbafc.cjs.dev.js +0 -14
  66. package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -8,6 +8,8 @@ export type { RemoteSource } from "./source/remote.js";
8
8
  export type { RichTextSource, RichText, TextNode, ParagraphNode, HeadingNode, ListItemNode, ListNode, } from "./source/richtext.js";
9
9
  export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
10
10
  export type { Json, JsonPrimitive } from "./Json.js";
11
+ export type { ValidationErrors, ValidationError, } from "./schema/validation/ValidationError.js";
12
+ export type { ValidationFix } from "./schema/validation/ValidationFix.js";
11
13
  export * as expr from "./expr/index.js";
12
14
  export { FILE_REF_PROP } from "./source/file.js";
13
15
  export { VAL_EXTENSION, type SourceArray } from "./source/index.js";
@@ -29,7 +29,7 @@ type NarrowStrings<A> = (A extends [] ? [] : never) | (A extends string ? A : ne
29
29
  export declare const initVal: <Locales extends readonly string[] | undefined>(options?: {
30
30
  readonly locales?: {
31
31
  readonly required: NarrowStrings<Locales>;
32
- readonly fallback: NarrowStrings<Locales extends readonly string[] ? Locales[number] : never>;
32
+ readonly default: NarrowStrings<Locales extends readonly string[] ? Locales[number] : never>;
33
33
  } | undefined;
34
34
  } | undefined) => InitVal<Locales>;
35
35
  export {};
@@ -3,4 +3,4 @@ export { type OperationJSON, type Operation } from "./operation.js";
3
3
  export { parsePatch, parseJSONPointer, formatJSONPointer } from "./parse.js";
4
4
  export { type JSONValue, type Ops, PatchError } from "./ops.js";
5
5
  export { type PatchJSON, type Patch, applyPatch } from "./patch.js";
6
- export { isNotRoot, deepEqual, deepClone, parseAndValidateArrayIndex, } from "./util.js";
6
+ export { isNotRoot, deepEqual, deepClone, parseAndValidateArrayIndex, sourceToPatchPath, } from "./util.js";
@@ -1,6 +1,8 @@
1
1
  import { array, result } from "../fp/index.js";
2
2
  import { PatchError, ReadonlyJSONValue, ToMutable } from "./ops.js";
3
+ import { SourcePath } from "../val/index.js";
3
4
  export declare function isNotRoot(path: string[]): path is array.NonEmptyArray<string>;
4
5
  export declare function deepEqual(a: ReadonlyJSONValue, b: ReadonlyJSONValue): boolean;
5
6
  export declare function deepClone<T extends ReadonlyJSONValue>(value: T): ToMutable<T>;
6
7
  export declare function parseAndValidateArrayIndex(value: string): result.Result<number, PatchError>;
8
+ export declare function sourceToPatchPath(sourcePath: SourcePath): any[];
@@ -1,6 +1,7 @@
1
1
  import { Schema, SchemaTypeOf, SerializedSchema } from "./index.js";
2
2
  import { SelectorSource } from "../selector/index.js";
3
3
  import { SourcePath } from "../val/index.js";
4
+ import { ValidationErrors } from "./validation/ValidationError.js";
4
5
  export type SerializedArraySchema = {
5
6
  type: "array";
6
7
  item: SerializedSchema;
@@ -10,8 +11,8 @@ export declare class ArraySchema<T extends Schema<SelectorSource>> extends Schem
10
11
  readonly item: T;
11
12
  readonly opt: boolean;
12
13
  constructor(item: T, opt?: boolean);
13
- validate(src: SchemaTypeOf<T>[]): false | Record<SourcePath, string[]>;
14
- match(src: SchemaTypeOf<T>[]): boolean;
14
+ validate(path: SourcePath, src: SchemaTypeOf<T>[]): ValidationErrors;
15
+ assert(src: SchemaTypeOf<T>[]): boolean;
15
16
  optional(): Schema<SchemaTypeOf<T>[] | null>;
16
17
  serialize(): SerializedArraySchema;
17
18
  }
@@ -1,5 +1,6 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
+ import { ValidationErrors } from "./validation/ValidationError.js";
3
4
  export type SerializedBooleanSchema = {
4
5
  type: "boolean";
5
6
  opt: boolean;
@@ -7,8 +8,8 @@ export type SerializedBooleanSchema = {
7
8
  export declare class BooleanSchema<Src extends boolean | null> extends Schema<Src> {
8
9
  readonly opt: boolean;
9
10
  constructor(opt?: boolean);
10
- validate(src: Src): false | Record<SourcePath, string[]>;
11
- match(src: Src): boolean;
11
+ validate(path: SourcePath, src: Src): ValidationErrors;
12
+ assert(src: Src): boolean;
12
13
  optional(): Schema<Src | null>;
13
14
  serialize(): SerializedSchema;
14
15
  }
@@ -1,6 +1,7 @@
1
1
  import { Schema, SchemaTypeOf, SerializedSchema } from "./index.js";
2
2
  import { I18nCompatibleSource, I18nSource } from "../source/i18n.js";
3
3
  import { SourcePath } from "../val/index.js";
4
+ import { ValidationErrors } from "./validation/ValidationError.js";
4
5
  export type SerializedI18nSchema = {
5
6
  type: "i18n";
6
7
  locales: readonly string[];
@@ -12,8 +13,8 @@ export declare class I18nSchema<Locales extends readonly string[]> extends Schem
12
13
  readonly item: Schema<SchemaTypeOf<Schema<I18nCompatibleSource>>>;
13
14
  readonly opt: boolean;
14
15
  constructor(locales: Locales, item: Schema<SchemaTypeOf<Schema<I18nCompatibleSource>>>, opt?: boolean);
15
- validate(src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>): false | Record<SourcePath, string[]>;
16
- match(src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>): boolean;
16
+ validate(path: SourcePath, src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>): ValidationErrors;
17
+ assert(src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>): boolean;
17
18
  optional(): Schema<I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>> | null>;
18
19
  serialize(): SerializedSchema;
19
20
  }
@@ -1,6 +1,7 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
2
  import { FileSource } from "../source/file.js";
3
3
  import { SourcePath } from "../val/index.js";
4
+ import { ValidationErrors } from "./validation/ValidationError.js";
4
5
  export type ImageOptions = {
5
6
  ext: ["jpg"] | ["webp"];
6
7
  directory?: string;
@@ -20,8 +21,8 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata> | null> e
20
21
  readonly options?: ImageOptions | undefined;
21
22
  readonly opt: boolean;
22
23
  constructor(options?: ImageOptions | undefined, opt?: boolean);
23
- validate(src: Src): false | Record<SourcePath, string[]>;
24
- match(src: Src): boolean;
24
+ validate(path: SourcePath, src: Src): ValidationErrors;
25
+ assert(src: Src): boolean;
25
26
  optional(): Schema<Src | null>;
26
27
  serialize(): SerializedSchema;
27
28
  }
@@ -12,12 +12,15 @@ import { SerializedOneOfSchema } from "./oneOf.js";
12
12
  import { SerializedRichTextSchema } from "./richtext.js";
13
13
  import { SerializedStringSchema } from "./string.js";
14
14
  import { SerializedUnionSchema } from "./union.js";
15
+ import { ValidationErrors } from "./validation/ValidationError.js";
15
16
  export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedOneOfSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedImageSchema | SerializedI18nSchema;
16
17
  export declare abstract class Schema<Src extends SelectorSource> {
17
- abstract validate(src: Src): false | Record<SourcePath, string[]>;
18
- abstract match(src: Src): boolean;
18
+ abstract validate(path: SourcePath, src: Src): ValidationErrors;
19
+ abstract assert(src: Src): boolean;
19
20
  abstract optional(): Schema<Src | null>;
20
21
  abstract serialize(): SerializedSchema;
21
22
  remote(): Src extends RemoteCompatibleSource ? Schema<RemoteSource<Src>> : never;
23
+ /** MUTATES! since internal and perf sensitive */
24
+ protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value?: unknown): ValidationErrors;
22
25
  }
23
26
  export type SchemaTypeOf<T extends Schema<SelectorSource>> = T extends Schema<infer Src> ? Src : never;
@@ -1,5 +1,6 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
+ import { ValidationErrors } from "./validation/ValidationError.js";
3
4
  export type SerializedLiteralSchema = {
4
5
  type: "literal";
5
6
  value: string;
@@ -9,8 +10,8 @@ export declare class LiteralSchema<Src extends string | null> extends Schema<Src
9
10
  readonly value: string;
10
11
  readonly opt: boolean;
11
12
  constructor(value: string, opt?: boolean);
12
- validate(src: Src): false | Record<SourcePath, string[]>;
13
- match(src: Src): boolean;
13
+ validate(path: SourcePath, src: Src): ValidationErrors;
14
+ assert(src: Src): boolean;
14
15
  optional(): Schema<Src | null>;
15
16
  serialize(): SerializedSchema;
16
17
  }
@@ -1,5 +1,6 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
+ import { ValidationErrors } from "./validation/ValidationError.js";
3
4
  type NumberOptions = {
4
5
  max?: number;
5
6
  min?: number;
@@ -13,8 +14,8 @@ export declare class NumberSchema<Src extends number | null> extends Schema<Src>
13
14
  readonly options?: NumberOptions | undefined;
14
15
  readonly opt: boolean;
15
16
  constructor(options?: NumberOptions | undefined, opt?: boolean);
16
- validate(src: Src): false | Record<SourcePath, string[]>;
17
- match(src: Src): boolean;
17
+ validate(path: SourcePath, src: Src): ValidationErrors;
18
+ assert(src: Src): boolean;
18
19
  optional(): Schema<Src | null>;
19
20
  serialize(): SerializedSchema;
20
21
  }
@@ -1,6 +1,7 @@
1
1
  import { Schema, SchemaTypeOf, SerializedSchema } from "./index.js";
2
2
  import { SelectorSource } from "../selector/index.js";
3
3
  import { SourcePath } from "../val/index.js";
4
+ import { ValidationErrors } from "./validation/ValidationError.js";
4
5
  export type SerializedObjectSchema = {
5
6
  type: "object";
6
7
  items: Record<string, SerializedSchema>;
@@ -16,8 +17,8 @@ export declare class ObjectSchema<Props extends ObjectSchemaProps> extends Schem
16
17
  readonly items: Props;
17
18
  readonly opt: boolean;
18
19
  constructor(items: Props, opt?: boolean);
19
- validate(src: ObjectSchemaSrcOf<Props>): false | Record<SourcePath, string[]>;
20
- match(src: ObjectSchemaSrcOf<Props>): boolean;
20
+ validate(path: SourcePath, src: ObjectSchemaSrcOf<Props>): ValidationErrors;
21
+ assert(src: ObjectSchemaSrcOf<Props>): boolean;
21
22
  optional(): Schema<ObjectSchemaSrcOf<Props> | null>;
22
23
  serialize(): SerializedSchema;
23
24
  }
@@ -3,6 +3,7 @@ import { ValModuleBrand } from "../module.js";
3
3
  import { GenericSelector } from "../selector/index.js";
4
4
  import { Source, SourceArray } from "../source/index.js";
5
5
  import { SourcePath } from "../val/index.js";
6
+ import { ValidationErrors } from "./validation/ValidationError.js";
6
7
  export type SerializedOneOfSchema = {
7
8
  type: "oneOf";
8
9
  selector: SourcePath;
@@ -13,8 +14,8 @@ export declare class OneOfSchema<Sel extends GenericSelector<SourceArray>> exten
13
14
  readonly selector: Sel;
14
15
  readonly opt: boolean;
15
16
  constructor(selector: Sel, opt?: boolean);
16
- validate(src: OneOfSelector<Sel>): false | Record<SourcePath, string[]>;
17
- match(src: OneOfSelector<Sel>): boolean;
17
+ validate(path: SourcePath, src: OneOfSelector<Sel>): ValidationErrors;
18
+ assert(src: OneOfSelector<Sel>): boolean;
18
19
  optional(): Schema<OneOfSelector<Sel> | null>;
19
20
  serialize(): SerializedSchema;
20
21
  }
@@ -1,14 +1,15 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
2
  import { RichTextSource } from "../source/richtext.js";
3
3
  import { SourcePath } from "../val/index.js";
4
+ import { ValidationErrors } from "./validation/ValidationError.js";
4
5
  export type SerializedRichTextSchema = {
5
6
  type: "richtext";
6
7
  opt: boolean;
7
8
  };
8
9
  export declare class RichTextSchema<Src extends RichTextSource | null> extends Schema<Src> {
9
10
  readonly opt: boolean;
10
- validate(src: Src): false | Record<SourcePath, string[]>;
11
- match(src: Src): boolean;
11
+ validate(path: SourcePath, src: Src): ValidationErrors;
12
+ assert(src: Src): boolean;
12
13
  optional(): Schema<RichTextSource | null>;
13
14
  serialize(): SerializedSchema;
14
15
  constructor(opt?: boolean);
@@ -1,5 +1,6 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
2
  import { SourcePath } from "../val/index.js";
3
+ import { ValidationErrors } from "./validation/ValidationError.js";
3
4
  type StringOptions = {
4
5
  maxLength?: number;
5
6
  minLength?: number;
@@ -13,8 +14,8 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
13
14
  readonly options?: StringOptions | undefined;
14
15
  readonly opt: boolean;
15
16
  constructor(options?: StringOptions | undefined, opt?: boolean);
16
- validate(src: Src): false | Record<SourcePath, string[]>;
17
- match(src: Src): boolean;
17
+ validate(path: SourcePath, src: Src): ValidationErrors;
18
+ assert(src: Src): boolean;
18
19
  optional(): Schema<Src | null>;
19
20
  serialize(): SerializedSchema;
20
21
  }
@@ -2,6 +2,7 @@ import { Schema, 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";
5
+ import { ValidationErrors } from "./validation/ValidationError.js";
5
6
  export type SerializedUnionSchema = {
6
7
  type: "union";
7
8
  key: string;
@@ -17,8 +18,8 @@ export declare class UnionSchema<Key extends string, T extends Schema<SourceObje
17
18
  readonly key: Key;
18
19
  readonly items: T;
19
20
  readonly opt: boolean;
20
- validate(src: SourceOf<Key, T>): false | Record<SourcePath, string[]>;
21
- match(src: SourceOf<Key, T>): boolean;
21
+ validate(path: SourcePath, src: SourceOf<Key, T>): ValidationErrors;
22
+ assert(src: SourceOf<Key, T>): boolean;
22
23
  optional(): Schema<SourceOf<Key, T> | null>;
23
24
  serialize(): SerializedSchema;
24
25
  constructor(key: Key, items: T, opt?: boolean);
@@ -0,0 +1,14 @@
1
+ import { SourcePath } from "../../val/index.js";
2
+ import { ValidationFix } from "./ValidationFix.js";
3
+ export type ValidationError = {
4
+ message: string;
5
+ value?: unknown;
6
+ fixes?: ValidationFix[];
7
+ };
8
+ /**
9
+ * Equals `false` if no validation errors were found.
10
+ * Errors are indexed by the full source path.
11
+ *
12
+ * Global errors have the path `"/"`.
13
+ */
14
+ export type ValidationErrors = false | Record<SourcePath, ValidationError[]>;
@@ -0,0 +1,2 @@
1
+ export declare const ValidationFix: readonly ["image:add-metadata", "image:replace-metadata"];
2
+ export type ValidationFix = (typeof ValidationFix)[number];