@valbuild/core 0.62.6 → 0.63.1

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.
@@ -11,7 +11,7 @@ export type { FileSource } from "./source/file.js";
11
11
  export type { RawString } from "./schema/string.js";
12
12
  export type { ImageSource } from "./source/image.js";
13
13
  export { RT_IMAGE_TAG } from "./source/richtext.js";
14
- export type { AnyRichTextOptions, Bold, Classes, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, LinkNode, OrderedListNode, ParagraphNode, BrNode, RichText, RichTextNode, RichTextOptions, RichTextSource, RootNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
14
+ export type { AllRichTextOptions, Bold, Styles, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, LinkNode, OrderedListNode, ParagraphNode, BrNode, RichTextNode, RichTextOptions, RichTextSource, BlockNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
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";
@@ -54,7 +54,27 @@ export declare function initSchema(): {
54
54
  val?: undefined;
55
55
  valPath?: undefined;
56
56
  } & { [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>;
57
- richtext: <O extends import("./index.js").RichTextOptions>(options?: O | undefined) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
57
+ richtext: <O extends Partial<{
58
+ style: Partial<{
59
+ bold: boolean;
60
+ italic: boolean;
61
+ lineThrough: boolean;
62
+ }>;
63
+ block: Partial<{
64
+ h1: boolean;
65
+ h2: boolean;
66
+ h3: boolean;
67
+ h4: boolean;
68
+ h5: boolean;
69
+ h6: boolean;
70
+ ul: boolean;
71
+ ol: boolean;
72
+ }>;
73
+ inline: Partial<{
74
+ a: boolean;
75
+ img: boolean;
76
+ }>;
77
+ }>>(options?: O | undefined) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
58
78
  image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").ImageSource>;
59
79
  literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
60
80
  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>;
@@ -12,7 +12,7 @@ export type ValModuleBrand = {
12
12
  [brand]: "ValModule";
13
13
  };
14
14
  export type InferValModuleType<T extends ValModule<SelectorSource>> = T extends GenericSelector<infer S> ? S : never;
15
- type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends ImageSelector ? ImageSource : T extends {
15
+ export type ReplaceRawStringWithString<T extends SelectorSource> = SelectorSource extends T ? T : T extends RawString ? string : T extends ImageSelector ? ImageSource : T extends {
16
16
  [key in string]: SelectorSource;
17
17
  } ? {
18
18
  [key in keyof T]: ReplaceRawStringWithString<T[key]>;
@@ -63,7 +63,11 @@ export type Operation = {
63
63
  value: JSONValue;
64
64
  } | {
65
65
  op: "file";
66
+ /** path of the top-most element where the schema of the element points to */
66
67
  path: string[];
68
+ /** file path relative to project (starts with /public, e.g. /public/example.png) */
67
69
  filePath: string;
70
+ /** files can be nested within an object (for richtext), in order to find the actual file element this path can be used (we use this to add the patch_id on files) */
71
+ nestedFilePath?: string[];
68
72
  value: JSONValue;
69
73
  };
@@ -16,4 +16,24 @@ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichT
16
16
  nullable(): Schema<RichTextSource<O> | null>;
17
17
  serialize(): SerializedSchema;
18
18
  }
19
- export declare const richtext: <O extends RichTextOptions>(options?: O | undefined) => Schema<RichTextSource<O>>;
19
+ export declare const richtext: <O extends Partial<{
20
+ style: Partial<{
21
+ bold: boolean;
22
+ italic: boolean;
23
+ lineThrough: boolean;
24
+ }>;
25
+ block: Partial<{
26
+ h1: boolean;
27
+ h2: boolean;
28
+ h3: boolean;
29
+ h4: boolean;
30
+ h5: boolean;
31
+ h6: boolean;
32
+ ul: boolean;
33
+ ol: boolean;
34
+ }>;
35
+ inline: Partial<{
36
+ a: boolean;
37
+ img: boolean;
38
+ }>;
39
+ }>>(options?: O | undefined) => Schema<RichTextSource<O>>;
@@ -1,2 +1,2 @@
1
- export declare const ValidationFix: readonly ["image:add-metadata", "image:replace-metadata", "file:add-metadata", "file:check-metadata"];
1
+ export declare const ValidationFix: readonly ["image:add-metadata", "image:replace-metadata", "file:add-metadata", "file:check-metadata", "fix:deprecated-richtext"];
2
2
  export type ValidationFix = (typeof ValidationFix)[number];
@@ -15,7 +15,8 @@ import type { A } from "ts-toolbelt";
15
15
  import { I18nSource, I18nCompatibleSource } from "../../source/future/i18n.js";
16
16
  import { RemoteCompatibleSource, RemoteSource } from "../../source/future/remote.js";
17
17
  import { FileSource } from "../../source/file.js";
18
- import { AnyRichTextOptions, RichText, RichTextSource } from "../../source/richtext.js";
18
+ import { AllRichTextOptions, RichTextSource } from "../../source/richtext.js";
19
+ import { RichTextSelector } from "../richtext.js";
19
20
  /**
20
21
  * Selectors can be used to select parts of a Val module.
21
22
  * Unlike queries, joins, aggregates etc is and will not be supported.
@@ -37,10 +38,10 @@ import { AnyRichTextOptions, RichText, RichTextSource } from "../../source/richt
37
38
  * }));
38
39
  *
39
40
  */
40
- export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends I18nSource<infer L, infer S> ? I18nSelector<L, S> : T extends RemoteSource<infer S> ? S extends RemoteCompatibleSource ? RemoteSelector<S> : GenericSelector<Source, "Could not determine remote source"> : T extends FileSource ? FileSelector : T extends RichTextSource<infer O> ? RichText<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
41
+ export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends I18nSource<infer L, infer S> ? I18nSelector<L, S> : T extends RemoteSource<infer S> ? S extends RemoteCompatibleSource ? RemoteSelector<S> : GenericSelector<Source, "Could not determine remote source"> : T extends FileSource ? FileSelector : T extends RichTextSource<infer O> ? RichTextSelector<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
41
42
  export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
42
43
  [key: string]: SelectorSource;
43
- } | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource<AnyRichTextOptions> | GenericSelector<Source>;
44
+ } | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
44
45
  /**
45
46
  * @internal
46
47
  */
@@ -10,13 +10,14 @@ import { Source, SourceArray, SourceObject, SourcePrimitive } from "../source/in
10
10
  import { Schema } from "../schema/index.js";
11
11
  import type { A } from "ts-toolbelt";
12
12
  import { FileSource } from "../source/file.js";
13
- import { RichText, RichTextOptions, RichTextSource } from "../source/richtext.js";
13
+ import { AllRichTextOptions, RichTextSource } from "../source/richtext.js";
14
14
  import { ImageMetadata } from "../schema/image.js";
15
15
  import { ImageSelector } from "./image.js";
16
- export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource<infer M> ? M extends ImageMetadata ? ImageSelector : FileSelector<M> : T extends RichTextSource<infer O> ? RichText<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
16
+ import { RichTextSelector } from "./richtext.js";
17
+ export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource<infer M> ? M extends ImageMetadata ? ImageSelector : FileSelector<M> : T extends RichTextSource<infer O> ? RichTextSelector<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
17
18
  export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
18
19
  [key: string]: SelectorSource;
19
- } | FileSource | RichTextSource<RichTextOptions> | GenericSelector<Source>;
20
+ } | FileSource | RichTextSource<AllRichTextOptions> | GenericSelector<Source>;
20
21
  /**
21
22
  * @internal
22
23
  */
@@ -0,0 +1,3 @@
1
+ import { GenericSelector } from "./index.js";
2
+ import { RichTextOptions, RichTextSource } from "../source/richtext.js";
3
+ export type RichTextSelector<O extends RichTextOptions> = GenericSelector<RichTextSource<O>>;
@@ -1,11 +1,11 @@
1
1
  import { SourcePrimitive, VAL_EXTENSION, PhantomType } from "../index.js";
2
2
  import { FileSource } from "../file.js";
3
3
  import { I18nCompatibleSource, I18nSource } from "./i18n.js";
4
- import { AnyRichTextOptions, RichTextSource } from "../richtext.js";
4
+ import { AllRichTextOptions, RichTextSource } from "../richtext.js";
5
5
  /**
6
6
  * Remote sources cannot include other remote sources.
7
7
  */
8
- export type RemoteCompatibleSource = SourcePrimitive | RemoteObject | RemoteArray | RichTextSource<AnyRichTextOptions> | FileSource | I18nSource<string[], I18nCompatibleSource>;
8
+ export type RemoteCompatibleSource = SourcePrimitive | RemoteObject | RemoteArray | RichTextSource<AllRichTextOptions> | FileSource | I18nSource<string[], I18nCompatibleSource>;
9
9
  export type RemoteObject = {
10
10
  [key in string]: RemoteCompatibleSource;
11
11
  };
@@ -24,7 +24,7 @@ export type SourceObject = {
24
24
  export type SourceArray = readonly Source[];
25
25
  export type SourcePrimitive = string | number | boolean | null;
26
26
  export declare const VAL_EXTENSION: "_type";
27
- export declare function getValExtension(source: Source): false | "" | 0 | "file" | "remote" | "richtext" | "i18n" | null | undefined;
27
+ export declare function getValExtension(source: Source): false | "" | 0 | "file" | "remote" | "i18n" | null | undefined;
28
28
  /**
29
29
  * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
30
30
  *
@@ -1,96 +1,102 @@
1
- import { VAL_EXTENSION } from "./index.js";
2
1
  import { LinkSource } from "./link.js";
3
2
  import { ImageSource } from "./image.js";
4
3
  import { ImageMetadata } from "../schema/image.js";
5
4
  import { FileSource } from "./file.js";
6
- export type RichTextOptions = {
7
- headings?: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
8
- img?: boolean;
9
- a?: boolean;
10
- ul?: boolean;
11
- ol?: boolean;
12
- lineThrough?: boolean;
13
- bold?: boolean;
14
- italic?: boolean;
5
+ export type RichTextOptions = Partial<{
6
+ style: Partial<{
7
+ bold: boolean;
8
+ italic: boolean;
9
+ lineThrough: boolean;
10
+ }>;
11
+ block: Partial<{
12
+ h1: boolean;
13
+ h2: boolean;
14
+ h3: boolean;
15
+ h4: boolean;
16
+ h5: boolean;
17
+ h6: boolean;
18
+ ul: boolean;
19
+ ol: boolean;
20
+ }>;
21
+ inline: Partial<{
22
+ a: boolean;
23
+ img: boolean;
24
+ }>;
25
+ }>;
26
+ export type AllRichTextOptions = {
27
+ style: {
28
+ bold: true;
29
+ italic: true;
30
+ lineThrough: true;
31
+ };
32
+ block: {
33
+ h1: true;
34
+ h2: true;
35
+ h3: true;
36
+ h4: true;
37
+ h5: true;
38
+ h6: true;
39
+ ul: true;
40
+ ol: true;
41
+ };
42
+ inline: {
43
+ a: true;
44
+ img: true;
45
+ };
15
46
  };
16
- export type AnyRichTextOptions = {
17
- headings: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
18
- img: true;
19
- a: true;
20
- ul: true;
21
- ol: true;
22
- lineThrough: true;
23
- bold: true;
24
- italic: true;
25
- };
26
- export type LineThrough<O extends RichTextOptions> = O["lineThrough"] extends true ? "line-through" : never;
27
- export type Italic<O extends RichTextOptions> = O["italic"] extends true ? "italic" : never;
28
- export type Bold<O extends RichTextOptions> = O["bold"] extends true ? "bold" : never;
29
- export type Classes<O extends RichTextOptions> = LineThrough<O> | Italic<O> | Bold<O>;
47
+ export type LineThrough<O extends RichTextOptions> = NonNullable<O["style"]>["lineThrough"] extends true ? "line-through" : never;
48
+ export type Italic<O extends RichTextOptions> = NonNullable<O["style"]>["italic"] extends true ? "italic" : never;
49
+ export type Bold<O extends RichTextOptions> = NonNullable<O["style"]>["bold"] extends true ? "bold" : never;
50
+ export type Styles<O extends RichTextOptions> = LineThrough<O> | Italic<O> | Bold<O>;
30
51
  export type ParagraphNode<O extends RichTextOptions> = {
31
52
  tag: "p";
32
- children: (string | SpanNode<O> | BrNode | LinkNode<O> | ImageNode<O>)[];
53
+ children: (string | SpanNode<O> | BrNode | LinkNode<O> | ImageNode<O> | CustomInlineNode<O>)[];
33
54
  };
34
55
  export type BrNode = {
35
56
  tag: "br";
36
57
  };
37
58
  export type SpanNode<O extends RichTextOptions> = {
38
59
  tag: "span";
39
- classes: Classes<O>[];
60
+ styles: Styles<O>[];
40
61
  children: [string];
41
62
  };
42
- type ImageTagNode = {
63
+ export type ImageNode<O extends RichTextOptions> = NonNullable<O["inline"]>["img"] extends true ? {
43
64
  tag: "img";
44
- src: string;
45
- alt?: string;
46
- height?: number;
47
- width?: number;
48
- mimeType?: string;
49
- };
50
- export type ImageNode<O extends RichTextOptions> = O["img"] extends true ? ImageTagNode : never;
65
+ src: ImageSource;
66
+ } : never;
51
67
  type LinkTagNode<O extends RichTextOptions> = {
52
68
  tag: "a";
53
69
  href: string;
54
- children: (string | SpanNode<O>)[];
70
+ children: (string | SpanNode<O> | ImageNode<O> | CustomInlineNode<O>)[];
55
71
  };
56
- export type LinkNode<O extends RichTextOptions> = O["a"] extends true ? LinkTagNode<O> : never;
57
- export type ListItemNode<O extends RichTextOptions> = O["ul"] | O["ol"] extends true ? {
72
+ export type LinkNode<O extends RichTextOptions> = NonNullable<O["inline"]>["a"] extends true ? LinkTagNode<O> : never;
73
+ type ListItemTagNode<O extends RichTextOptions> = {
58
74
  tag: "li";
59
- children: (string | SpanNode<O> | LinkNode<O> | BrNode | UnorderedListNode<O> | OrderedListNode<O>)[];
60
- } : never;
61
- export type UnorderedListNode<O extends RichTextOptions> = O["ul"] extends true ? {
75
+ children: (ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O>)[];
76
+ };
77
+ export type ListItemNode<O extends RichTextOptions> = NonNullable<O["block"]>["ul"] extends true ? ListItemTagNode<O> : never | NonNullable<O["block"]>["ol"] extends true ? ListItemTagNode<O> : never;
78
+ export type UnorderedListNode<O extends RichTextOptions> = NonNullable<O["block"]>["ul"] extends true ? {
62
79
  tag: "ul";
63
- dir?: "ltr" | "rtl";
64
80
  children: ListItemNode<O>[];
65
81
  } : never;
66
- export type OrderedListNode<O extends RichTextOptions> = O["ol"] extends true ? {
82
+ export type OrderedListNode<O extends RichTextOptions> = NonNullable<O["block"]>["ol"] extends true ? {
67
83
  tag: "ol";
68
- dir?: "ltr" | "rtl";
69
84
  children: ListItemNode<O>[];
70
85
  } : never;
71
- export type HeadingNode<O extends RichTextOptions> = O["headings"] extends ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[] ? {
72
- tag: O["headings"][number];
73
- children: (string | SpanNode<O>)[];
86
+ export type HeadingTagOf<S extends keyof NonNullable<NonNullable<O["block"]>>, O extends RichTextOptions> = NonNullable<NonNullable<O["block"]>>[S] extends true ? {
87
+ tag: S;
88
+ children: (string | SpanNode<O> | CustomInlineNode<O> | LinkNode<O> | BrNode | ImageNode<O>)[];
74
89
  } : never;
75
- export type RichTextNode<O extends RichTextOptions> = string | RootNode<O> | ListItemNode<O> | BrNode | SpanNode<O> | LinkNode<O> | ImageNode<O>;
76
- export type RootNode<O extends RichTextOptions> = HeadingNode<O> | ParagraphNode<O> | BrNode | UnorderedListNode<O> | OrderedListNode<O>;
90
+ export type HeadingNode<O extends RichTextOptions> = HeadingTagOf<"h1", O> | HeadingTagOf<"h2", O> | HeadingTagOf<"h3", O> | HeadingTagOf<"h4", O> | HeadingTagOf<"h5", O> | HeadingTagOf<"h6", O>;
91
+ export type CustomInlineNode<O extends RichTextOptions> = never;
92
+ export type CustomBlockNode<O extends RichTextOptions> = never;
93
+ export type RichTextNode<O extends RichTextOptions> = string | BlockNode<O> | ListItemNode<O> | BrNode | SpanNode<O> | LinkNode<O> | ImageNode<O> | CustomInlineNode<O>;
94
+ export type BlockNode<O extends RichTextOptions> = HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | CustomBlockNode<O>;
77
95
  /**
78
- * RichTextSource is defined in ValModules
96
+ * RichText as defined in a ValModule
79
97
  **/
80
- export type RichTextSource<O extends RichTextOptions> = {
81
- [VAL_EXTENSION]: "richtext";
82
- templateStrings: string[];
83
- exprs: ((O["img"] extends true ? ImageSource : never) | (O["a"] extends true ? LinkSource : never))[];
84
- };
85
- /**
86
- * RichText is accessible by users (after conversion via useVal / fetchVal)
87
- * Internally it is a Selector
88
- **/
89
- export type RichText<O extends RichTextOptions> = {
90
- [VAL_EXTENSION]: "richtext";
91
- children: RootNode<O>[];
92
- };
93
- export declare function richtext<O extends RichTextOptions>(templateStrings: TemplateStringsArray, ...nodes: (ImageSource | LinkSource)[]): RichTextSource<O>;
98
+ export type RichTextSource<O extends RichTextOptions> = BlockNode<O>[];
99
+ export declare function richtext<O extends RichTextOptions>(templateStrings: TemplateStringsArray, ...nodes: (ImageSource | LinkSource)[]): RichTextSource<{}>;
94
100
  export declare const RT_IMAGE_TAG = "rt_image";
95
101
  export type RTImageMetadata = ImageMetadata;
96
102
  export declare function image(ref: `/public/${string}`, metadata?: RTImageMetadata): FileSource<RTImageMetadata>;