@valbuild/core 0.17.0 → 0.19.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 (44) hide show
  1. package/dist/declarations/src/index.d.ts +4 -1
  2. package/dist/declarations/src/initSchema.d.ts +8 -2
  3. package/dist/declarations/src/patch/deref.d.ts +2 -1
  4. package/dist/declarations/src/patch/operation.d.ts +8 -0
  5. package/dist/declarations/src/schema/keyOf.d.ts +2 -2
  6. package/dist/declarations/src/schema/richtext.d.ts +7 -6
  7. package/dist/declarations/src/schema/string.d.ts +6 -3
  8. package/dist/declarations/src/selector/future/index.d.ts +3 -3
  9. package/dist/declarations/src/selector/index.d.ts +3 -3
  10. package/dist/declarations/src/source/future/remote.d.ts +2 -2
  11. package/dist/declarations/src/source/index.d.ts +3 -3
  12. package/dist/declarations/src/source/richtext.d.ts +70 -54
  13. package/dist/{index-3e3e839e.esm.js → index-5d1ab97c.esm.js} +1 -1
  14. package/dist/{index-369caccf.esm.js → index-bccf1907.esm.js} +1 -1
  15. package/dist/{ops-f3015423.cjs.dev.js → ops-2d7e1742.cjs.dev.js} +106 -33
  16. package/dist/{ops-23a5abb2.esm.js → ops-7ef32b0a.esm.js} +107 -35
  17. package/dist/{ops-0d09f8ee.cjs.prod.js → ops-ae089ab2.cjs.prod.js} +106 -33
  18. package/dist/valbuild-core.cjs.dev.js +311 -15
  19. package/dist/valbuild-core.cjs.prod.js +311 -15
  20. package/dist/valbuild-core.esm.js +294 -18
  21. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  22. package/package.json +4 -1
  23. package/patch/dist/valbuild-core-patch.cjs.dev.js +6 -1
  24. package/patch/dist/valbuild-core-patch.cjs.prod.js +6 -1
  25. package/patch/dist/valbuild-core-patch.esm.js +8 -3
  26. package/src/getSha256.ts +8 -0
  27. package/src/index.ts +21 -5
  28. package/src/initSchema.ts +6 -0
  29. package/src/module.ts +33 -2
  30. package/src/patch/deref.ts +14 -1
  31. package/src/patch/operation.ts +10 -0
  32. package/src/patch/parse.ts +1 -0
  33. package/src/patch/patch.ts +3 -0
  34. package/src/schema/keyOf.ts +2 -2
  35. package/src/schema/richtext.ts +19 -73
  36. package/src/schema/string.ts +14 -4
  37. package/src/schema/validation.test.ts +2 -2
  38. package/src/selector/future/index.ts +8 -4
  39. package/src/selector/index.ts +4 -4
  40. package/src/source/future/remote.ts +2 -2
  41. package/src/source/index.ts +2 -2
  42. package/src/source/richtext.test.ts +178 -0
  43. package/src/source/richtext.ts +295 -89
  44. package/tsconfig.json +2 -1
@@ -4,7 +4,7 @@ export { Schema, type SerializedSchema } from "./schema/index.js";
4
4
  export type { ValModule, SerializedModule } from "./module.js";
5
5
  export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
6
6
  export type { FileSource } from "./source/file.js";
7
- export type { RichTextSource, RichText, TextNode, ParagraphNode, HeadingNode, ListItemNode, ListNode, } from "./source/richtext.js";
7
+ export type { AnyRichTextOptions, Bold, Classes, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, OrderedListNode, ParagraphNode, RichText, RichTextNode, RichTextOptions, RichTextSource, RichTextSourceNode, RootNode, SourceNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
8
8
  export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
9
9
  export type { Json, JsonPrimitive } from "./Json.js";
10
10
  export type { ValidationErrors, ValidationError, } from "./schema/validation/ValidationError.js";
@@ -21,6 +21,7 @@ import { createValPathOfItem } from "./selector/SelectorProxy.js";
21
21
  import { getVal } from "./future/fetchVal.js";
22
22
  import { Json } from "./Json.js";
23
23
  import { SerializedSchema } from "./schema/index.js";
24
+ import { convertRichTextSource } from "./source/richtext.js";
24
25
  export { ValApi } from "./ValApi.js";
25
26
  export type ApiTreeResponse = {
26
27
  git: {
@@ -42,6 +43,7 @@ declare const Internal: {
42
43
  url: string;
43
44
  metadata?: import("./schema/image.js").ImageMetadata;
44
45
  };
46
+ convertRichTextSource: typeof convertRichTextSource;
45
47
  getSchema: typeof getSchema;
46
48
  getValPath: typeof getValPath;
47
49
  getVal: typeof getVal;
@@ -50,6 +52,7 @@ declare const Internal: {
50
52
  splitModuleIdAndModulePath: typeof splitModuleIdAndModulePath;
51
53
  isVal: typeof isVal;
52
54
  createValPathOfItem: typeof createValPathOfItem;
55
+ getSHA256Hash: (bits: Uint8Array) => Promise<string>;
53
56
  createPatchJSONPath: (modulePath: ModulePath) => string;
54
57
  /**
55
58
  * Enables draft mode: updates all Val modules with patches
@@ -7,6 +7,8 @@ import { union } from "./schema/union.js";
7
7
  import { richtext } from "./schema/richtext.js";
8
8
  import { image } from "./schema/image.js";
9
9
  import { literal } from "./schema/literal.js";
10
+ import { keyOf } from "./schema/keyOf.js";
11
+ import { record } from "./schema/record.js";
10
12
  export type InitSchema = {
11
13
  readonly string: typeof string;
12
14
  readonly boolean: typeof boolean;
@@ -17,12 +19,14 @@ export type InitSchema = {
17
19
  readonly richtext: typeof richtext;
18
20
  readonly image: typeof image;
19
21
  readonly literal: typeof literal;
22
+ readonly keyOf: typeof keyOf;
23
+ readonly record: typeof record;
20
24
  };
21
25
  export declare function initSchema(): {
22
26
  string: <T extends string>(options?: {
23
27
  maxLength?: number | undefined;
24
28
  minLength?: number | undefined;
25
- } | undefined) => import("./schema/index.js").Schema<T>;
29
+ } | undefined) => import("./schema/string.js").StringSchema<T>;
26
30
  boolean: () => import("./schema/index.js").Schema<boolean>;
27
31
  array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/index.js").Schema<import("./schema/index.js").SchemaTypeOf<S>[]>;
28
32
  object: <Props extends {
@@ -43,7 +47,9 @@ export declare function initSchema(): {
43
47
  val?: undefined;
44
48
  valPath?: undefined;
45
49
  } & { [k in Key]: string; }>[]>(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 : never : never>;
46
- richtext: () => import("./schema/index.js").Schema<import("./index.js").RichTextSource>;
50
+ richtext: <O extends import("./index.js").RichTextOptions>(options: O) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
47
51
  image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").FileSource<import("./schema/image.js").ImageMetadata>>;
48
52
  literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
53
+ 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 any[] ? number : S_2 extends import("./source/index.js").SourceObject ? keyof S_2 : S_2 extends Record<string, any> ? string : never : never>;
54
+ 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").SchemaTypeOf<S_3>>>;
49
55
  };
@@ -1,6 +1,7 @@
1
1
  import { result } from "../fp/index.js";
2
2
  import { Ops, PatchError } from "./ops.js";
3
3
  import { Patch } from "./patch.js";
4
+ import { Operation } from "./operation.js";
4
5
  export type DerefPatchResult = {
5
6
  dereferencedPatch: Patch;
6
7
  fileUpdates: {
@@ -10,4 +11,4 @@ export type DerefPatchResult = {
10
11
  [ref: string]: Patch;
11
12
  };
12
13
  };
13
- export declare function derefPatch<D, E>(patch: Patch, document: D, ops: Ops<D, E>): result.Result<DerefPatchResult, E | PatchError>;
14
+ export declare function derefPatch<D, E>(patch: Operation[], document: D, ops: Ops<D, E>): result.Result<DerefPatchResult, E | PatchError>;
@@ -26,6 +26,10 @@ export type OperationJSON = {
26
26
  op: "test";
27
27
  path: string;
28
28
  value: JSONValue;
29
+ } | {
30
+ op: "file";
31
+ path: string;
32
+ value: JSONValue;
29
33
  };
30
34
  /**
31
35
  * Parsed form of JSON patch operation.
@@ -56,4 +60,8 @@ export type Operation = {
56
60
  op: "test";
57
61
  path: string[];
58
62
  value: JSONValue;
63
+ } | {
64
+ op: "file";
65
+ path: string[];
66
+ value: JSONValue;
59
67
  };
@@ -1,7 +1,7 @@
1
- import { Schema, SerializedSchema, SourceObject } from "../index.js";
1
+ import { Schema, SerializedSchema } from "./index.js";
2
2
  import { ValModuleBrand } from "../module.js";
3
3
  import { GenericSelector } from "../selector/index.js";
4
- import { SourceArray } from "../source/index.js";
4
+ import { SourceArray, SourceObject } from "../source/index.js";
5
5
  import { SourcePath } from "../val/index.js";
6
6
  import { ValidationErrors } from "./validation/ValidationError.js";
7
7
  export type SerializedKeyOfSchema = {
@@ -1,17 +1,18 @@
1
1
  import { Schema, SerializedSchema } from "./index.js";
2
- import { RichTextSource } from "../source/richtext.js";
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
- export type SerializedRichTextSchema = {
5
+ export type SerializedRichTextSchema = RichTextOptions & {
6
6
  type: "richtext";
7
7
  opt: boolean;
8
8
  };
9
- export declare class RichTextSchema<Src extends RichTextSource | null> extends Schema<Src> {
9
+ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichTextSource<O> | null> extends Schema<Src> {
10
+ readonly options: O;
10
11
  readonly opt: boolean;
12
+ constructor(options: O, opt?: boolean);
11
13
  validate(path: SourcePath, src: Src): ValidationErrors;
12
14
  assert(src: Src): boolean;
13
- optional(): Schema<RichTextSource | null>;
15
+ optional(): Schema<RichTextSource<O> | null>;
14
16
  serialize(): SerializedSchema;
15
- constructor(opt?: boolean);
16
17
  }
17
- export declare const richtext: () => Schema<RichTextSource>;
18
+ export declare const richtext: <O extends RichTextOptions>(options: O) => Schema<RichTextSource<O>>;
@@ -9,15 +9,18 @@ export type SerializedStringSchema = {
9
9
  type: "string";
10
10
  options?: StringOptions;
11
11
  opt: boolean;
12
+ raw: boolean;
12
13
  };
13
14
  export declare class StringSchema<Src extends string | null> extends Schema<Src> {
14
15
  readonly options?: StringOptions | undefined;
15
16
  readonly opt: boolean;
16
- constructor(options?: StringOptions | undefined, opt?: boolean);
17
+ readonly isRaw: boolean;
18
+ constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean);
17
19
  validate(path: SourcePath, src: Src): ValidationErrors;
18
20
  assert(src: Src): boolean;
19
- optional(): Schema<Src | null>;
21
+ optional(): StringSchema<Src | null>;
22
+ raw(): StringSchema<Src>;
20
23
  serialize(): SerializedSchema;
21
24
  }
22
- export declare const string: <T extends string>(options?: StringOptions) => Schema<T>;
25
+ export declare const string: <T extends string>(options?: StringOptions) => StringSchema<T>;
23
26
  export {};
@@ -15,7 +15,7 @@ import { 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 { RichText, RichTextSource } from "../../source/richtext.js";
18
+ import { AnyRichTextOptions, RichText, RichTextSource } from "../../source/richtext.js";
19
19
  /**
20
20
  * Selectors can be used to select parts of a Val module.
21
21
  * Unlike queries, joins, aggregates etc is and will not be supported.
@@ -37,10 +37,10 @@ import { RichText, RichTextSource } from "../../source/richtext.js";
37
37
  * }));
38
38
  *
39
39
  */
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 ? RichText : 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;
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
41
  export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
42
42
  [key: string]: SelectorSource;
43
- } | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource | GenericSelector<Source>;
43
+ } | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource<AnyRichTextOptions> | GenericSelector<Source>;
44
44
  /**
45
45
  * @internal
46
46
  */
@@ -10,11 +10,11 @@ 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, RichTextSource } from "../source/richtext.js";
14
- export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource ? FileSelector : T extends RichTextSource ? RichText : 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;
13
+ import { RichText, RichTextOptions, RichTextSource } from "../source/richtext.js";
14
+ export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : 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;
15
15
  export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
16
16
  [key: string]: SelectorSource;
17
- } | FileSource | RichTextSource | GenericSelector<Source>;
17
+ } | FileSource | RichTextSource<RichTextOptions> | GenericSelector<Source>;
18
18
  /**
19
19
  * @internal
20
20
  */
@@ -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 { RichTextSource } from "../richtext.js";
4
+ import { AnyRichTextOptions, 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 | FileSource | I18nSource<string[], I18nCompatibleSource>;
8
+ export type RemoteCompatibleSource = SourcePrimitive | RemoteObject | RemoteArray | RichTextSource<AnyRichTextOptions> | FileSource | I18nSource<string[], I18nCompatibleSource>;
9
9
  export type RemoteObject = {
10
10
  [key in string]: RemoteCompatibleSource;
11
11
  };
@@ -1,8 +1,8 @@
1
1
  import { FileSource } from "./file.js";
2
2
  import { I18nSource, I18nCompatibleSource } from "./future/i18n.js";
3
3
  import { RemoteSource, RemoteCompatibleSource } from "./future/remote.js";
4
- import { RichTextSource } from "./richtext.js";
5
- export type Source = SourcePrimitive | SourceObject | SourceArray | I18nSource<string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource;
4
+ import { RichTextOptions, RichTextSource } from "./richtext.js";
5
+ export type Source = SourcePrimitive | SourceObject | SourceArray | I18nSource<string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource<RichTextOptions>;
6
6
  export type SourceObject = {
7
7
  [key in string]: Source;
8
8
  } & {
@@ -17,7 +17,7 @@ export type SourceObject = {
17
17
  export type SourceArray = readonly Source[];
18
18
  export type SourcePrimitive = string | number | boolean | null;
19
19
  export declare const VAL_EXTENSION: "_type";
20
- export declare function getValExtension(source: Source): false | "" | 0 | "richtext" | "remote" | "file" | "i18n" | null | undefined;
20
+ export declare function getValExtension(source: Source): false | "" | 0 | "remote" | "file" | "richtext" | "i18n" | null | undefined;
21
21
  /**
22
22
  * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
23
23
  *
@@ -1,63 +1,79 @@
1
+ import { FileSource } from "./file.js";
1
2
  import { VAL_EXTENSION } from "./index.js";
2
- import { SourcePath } from "../val/index.js";
3
- type Node = {
4
- version?: 1;
3
+ export type RichTextOptions = {
4
+ headings?: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
5
+ img?: boolean;
6
+ ul?: boolean;
7
+ ol?: boolean;
8
+ lineThrough?: boolean;
9
+ bold?: boolean;
10
+ italic?: boolean;
5
11
  };
6
- type NodeType = Node & {
7
- format?: FormatType;
8
- direction?: DirectionType;
9
- indent?: number;
12
+ export type ParagraphNode<O extends RichTextOptions> = {
13
+ tag: "p";
14
+ children: (string | SpanNode<O> | ImageNode<O>)[];
10
15
  };
11
- type FormatType = "left" | "start" | "center" | "right" | "end" | "justify" | "";
12
- type DirectionType = "ltr" | "rtl" | null;
13
- export type TextNode = Node & {
14
- type: "text";
15
- format?: FormatType | number;
16
- detail?: number;
17
- mode?: "normal" | "code" | "quote";
18
- style?: string;
19
- text: string;
20
- direction?: DirectionType;
21
- indent?: number;
16
+ export type LineThrough<O extends RichTextOptions> = O["lineThrough"] extends true ? "line-through" : never;
17
+ export type Italic<O extends RichTextOptions> = O["italic"] extends true ? "italic" : never;
18
+ export type Bold<O extends RichTextOptions> = O["bold"] extends true ? "bold" : never;
19
+ export type Classes<O extends RichTextOptions> = LineThrough<O> | Italic<O> | Bold<O>;
20
+ export type SpanNode<O extends RichTextOptions> = {
21
+ tag: "span";
22
+ classes: Classes<O>[];
23
+ children: [string | SpanNode<O>];
22
24
  };
23
- export type ParagraphNode<VN = TextNode> = NodeType & {
24
- children: (TextNode | VN)[];
25
- type: "paragraph";
25
+ export type ImageNode<O extends RichTextOptions> = O["img"] extends true ? {
26
+ tag: "img";
27
+ src: string;
28
+ height?: number;
29
+ width?: number;
30
+ } : never;
31
+ export type ListItemNode<O extends RichTextOptions> = {
32
+ tag: "li";
33
+ children: (string | SpanNode<O> | ImageNode<O> | UnorderedListNode<O> | OrderedListNode<O>)[];
26
34
  };
27
- export type HeadingNode<HT extends HeadingTags = HeadingTags> = NodeType & {
28
- children: TextNode[];
29
- type: "heading";
30
- tag: HT;
35
+ export type UnorderedListNode<O extends RichTextOptions> = O["ul"] extends true ? {
36
+ tag: "ul";
37
+ dir?: "ltr" | "rtl";
38
+ children: ListItemNode<O>[];
39
+ } : never;
40
+ export type OrderedListNode<O extends RichTextOptions> = O["ol"] extends true ? {
41
+ tag: "ol";
42
+ dir?: "ltr" | "rtl";
43
+ children: ListItemNode<O>[];
44
+ } : never;
45
+ export type HeadingNode<O extends RichTextOptions> = O["headings"] extends any[] ? {
46
+ tag: O["headings"][number];
47
+ children: (string | SpanNode<O>)[];
48
+ } : never;
49
+ type ImageSource = FileSource<{
50
+ width: number;
51
+ height: number;
52
+ sha256: string;
53
+ }>;
54
+ export type SourceNode<O extends RichTextOptions> = O["img"] extends true ? ImageSource : never;
55
+ export type AnyRichTextOptions = {
56
+ headings: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
57
+ img: true;
58
+ ul: true;
59
+ ol: true;
60
+ lineThrough: true;
61
+ bold: true;
62
+ italic: true;
31
63
  };
32
- export type ListItemNode<VN = TextNode> = NodeType & {
33
- children: (TextNode | VN)[];
34
- type: "listitem";
35
- value: number;
36
- checked?: boolean;
64
+ export type RichTextSourceNode<O extends RichTextOptions> = Exclude<RichTextNode<O>, {
65
+ tag: "img";
66
+ }> | ParagraphNode<O> | ListItemNode<O> | ImageNode<O> | SourceNode<O>;
67
+ export type RichTextSource<O extends RichTextOptions> = {
68
+ [VAL_EXTENSION]: "richtext";
69
+ children: (HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | SourceNode<O>)[];
37
70
  };
38
- export type ListNode<VN = TextNode> = NodeType & {
39
- children: ListItemNode<VN>[];
40
- type: "list";
41
- tag: "ol" | "ul";
42
- listType: "number" | "bullet" | "check";
43
- start?: number;
71
+ export type RichTextNode<O extends RichTextOptions> = string | HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | ListItemNode<O> | SpanNode<O> | ImageNode<O>;
72
+ export type RootNode<O extends RichTextOptions> = HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | ImageNode<O>;
73
+ export type RichText<O extends RichTextOptions> = {
74
+ [VAL_EXTENSION]: "richtext";
75
+ children: RootNode<O>[];
44
76
  };
45
- type HeadingTags = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
46
- export type RootNode<HT extends HeadingTags, VN> = Node & {
47
- children: (HeadingNode<HT> | ParagraphNode<VN> | ListNode<VN>)[];
48
- type?: "root";
49
- format?: FormatType;
50
- direction?: DirectionType;
51
- indent?: number;
52
- };
53
- declare const brand: unique symbol;
54
- export type RichText<HT extends HeadingTags = HeadingTags, VN extends TextNode = TextNode> = RootNode<HT, VN> & {
55
- [brand]: "richtext";
56
- valPath: SourcePath;
57
- };
58
- export type RichTextSource = RichText & {
59
- readonly [VAL_EXTENSION]: "richtext";
60
- };
61
- export declare function richtext(data: RootNode<HeadingTags, TextNode> | string): RichTextSource;
62
- export declare function isRichText(obj: unknown): obj is RichTextSource;
77
+ export declare function convertRichTextSource<O extends RichTextOptions>(src: RichTextSource<O>): RichText<O>;
78
+ export declare function richtext<O extends RichTextOptions, Nodes extends never | ImageSource>(templateStrings: TemplateStringsArray, ...expr: Nodes[]): RichTextSource<O>;
63
79
  export {};
@@ -1,4 +1,4 @@
1
- import { f as _objectSpread2, j as _slicedToArray, c as _createClass, b as _classCallCheck, q as Sym, C as Call, r as StringLiteral, s as StringTemplate, e as _typeof, l as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, m as convertFileSource, d as _defineProperty, S as Schema, E as Expr, t as _toConsumableArray, N as NilSym } from './index-369caccf.esm.js';
1
+ import { j as _objectSpread2, k as _slicedToArray, c as _createClass, b as _classCallCheck, r as Sym, C as Call, s as StringLiteral, t as StringTemplate, e as _typeof, n as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, f as convertFileSource, d as _defineProperty, S as Schema, E as Expr, u as _toConsumableArray, N as NilSym } from './index-bccf1907.esm.js';
2
2
  import { i as isErr, e as err, o as ok, a as isOk } from './result-b96df128.esm.js';
3
3
 
4
4
  var WHITE_SPACE = ["\n", "\r", "\t", " "];
@@ -547,4 +547,4 @@ function getValPath(valOrSelector) {
547
547
  return valOrSelector[Path];
548
548
  }
549
549
 
550
- export { Call as C, Expr as E, FILE_REF_PROP as F, GetSource as G, ImageSchema as I, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _defineProperty as d, _typeof as e, _objectSpread2 as f, getValPath as g, file as h, image as i, _slicedToArray as j, isFile as k, isSerializedVal as l, convertFileSource as m, getSchema as n, isVal as o, GenericSelector as p, Sym as q, StringLiteral as r, StringTemplate as s, _toConsumableArray as t, GetSchema as u };
550
+ export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, ImageSchema as I, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _defineProperty as d, _typeof as e, convertFileSource as f, getValPath as g, file as h, image as i, _objectSpread2 as j, _slicedToArray as k, isFile as l, GetSource as m, isSerializedVal as n, getSchema as o, isVal as p, GenericSelector as q, Sym as r, StringLiteral as s, StringTemplate as t, _toConsumableArray as u };
@@ -382,75 +382,132 @@ var union = function union(key) {
382
382
  var RichTextSchema = /*#__PURE__*/function (_Schema) {
383
383
  index._inherits(RichTextSchema, _Schema);
384
384
  var _super = index._createSuper(RichTextSchema);
385
- function RichTextSchema() {
385
+ function RichTextSchema(options) {
386
386
  var _this;
387
- var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
387
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
388
388
  index._classCallCheck(this, RichTextSchema);
389
389
  _this = _super.call(this);
390
+ _this.options = options;
390
391
  _this.opt = opt;
391
392
  return _this;
392
393
  }
393
394
  index._createClass(RichTextSchema, [{
394
395
  key: "validate",
395
396
  value: function validate(path, src) {
397
+ return false; //TODO
398
+ }
399
+ }, {
400
+ key: "assert",
401
+ value: function assert(src) {
402
+ return true; // TODO
403
+ }
404
+ }, {
405
+ key: "optional",
406
+ value: function optional() {
407
+ return new RichTextSchema(this.options, true);
408
+ }
409
+ }, {
410
+ key: "serialize",
411
+ value: function serialize() {
412
+ return {
413
+ type: "richtext",
414
+ opt: this.opt
415
+ };
416
+ }
417
+ }]);
418
+ return RichTextSchema;
419
+ }(index.Schema);
420
+ var richtext = function richtext(options) {
421
+ return new RichTextSchema(options);
422
+ };
423
+
424
+ var RecordSchema = /*#__PURE__*/function (_Schema) {
425
+ index._inherits(RecordSchema, _Schema);
426
+ var _super = index._createSuper(RecordSchema);
427
+ function RecordSchema(item) {
428
+ var _this;
429
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
430
+ index._classCallCheck(this, RecordSchema);
431
+ _this = _super.call(this);
432
+ _this.item = item;
433
+ _this.opt = opt;
434
+ return _this;
435
+ }
436
+ index._createClass(RecordSchema, [{
437
+ key: "validate",
438
+ value: function validate(path, src) {
439
+ var _this2 = this;
440
+ var error = false;
396
441
  if (this.opt && (src === null || src === undefined)) {
397
442
  return false;
398
443
  }
399
- if (src === null || src === undefined) {
400
- return index._defineProperty({}, path, [{
401
- message: "Expected non-nullable got '".concat(src, "'")
402
- }]);
403
- }
404
- if (index._typeof(src) !== "object" && !Array.isArray(src)) {
405
- return index._defineProperty({}, path, [{
406
- message: "Expected 'object' (that is not of an array) or 'string', got '".concat(index._typeof(src), "'"),
407
- value: src
408
- }]);
409
- }
410
- if (src[index.VAL_EXTENSION] !== "richtext") {
411
- return index._defineProperty({}, path, [{
412
- message: "Expected _type key with value 'richtext' got '".concat(src[index.VAL_EXTENSION], "'"),
413
- value: src
414
- }]);
415
- }
416
- if (src.type !== "root") {
444
+ if (index._typeof(src) !== "object") {
417
445
  return index._defineProperty({}, path, [{
418
- message: "Expected type key with value 'root' got '".concat(src.type, "'"),
419
- value: src
446
+ message: "Expected 'object', got '".concat(index._typeof(src), "'")
420
447
  }]);
421
448
  }
422
- if (index._typeof(src.children) !== "object" && !Array.isArray(src.children)) {
449
+ if (Array.isArray(src)) {
423
450
  return index._defineProperty({}, path, [{
424
- message: "Expected children to be an array, but got '".concat(src.type, "'"),
425
- value: src
451
+ message: "Expected 'object', got 'array'"
426
452
  }]);
427
453
  }
428
- return false;
454
+ Object.entries(src).forEach(function (_ref3) {
455
+ var _ref4 = index._slicedToArray(_ref3, 2),
456
+ key = _ref4[0],
457
+ elem = _ref4[1];
458
+ var subPath = createValPathOfItem(path, key);
459
+ if (!subPath) {
460
+ error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
461
+ // Should! never happen
462
+ src);
463
+ } else {
464
+ var subError = _this2.item.validate(subPath, elem);
465
+ if (subError && error) {
466
+ error = index._objectSpread2(index._objectSpread2({}, subError), error);
467
+ } else if (subError) {
468
+ error = subError;
469
+ }
470
+ }
471
+ });
472
+ return error;
429
473
  }
430
474
  }, {
431
475
  key: "assert",
432
476
  value: function assert(src) {
433
- // TODO:
434
- return true;
477
+ if (this.opt && (src === null || src === undefined)) {
478
+ return true;
479
+ }
480
+ if (!src) {
481
+ return false;
482
+ }
483
+ for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
484
+ var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
485
+ _item = _Object$entries$_i[1];
486
+ if (!this.item.assert(_item)) {
487
+ return false;
488
+ }
489
+ }
490
+ return index._typeof(src) === "object" && !Array.isArray(src);
435
491
  }
436
492
  }, {
437
493
  key: "optional",
438
494
  value: function optional() {
439
- return new RichTextSchema(true);
495
+ return new RecordSchema(this.item, true);
440
496
  }
441
497
  }, {
442
498
  key: "serialize",
443
499
  value: function serialize() {
444
500
  return {
445
- type: "richtext",
501
+ type: "record",
502
+ item: this.item.serialize(),
446
503
  opt: this.opt
447
504
  };
448
505
  }
449
506
  }]);
450
- return RichTextSchema;
507
+ return RecordSchema;
451
508
  }(index.Schema);
452
- var richtext = function richtext() {
453
- return new RichTextSchema();
509
+ var record = function record(schema) {
510
+ return new RecordSchema(schema);
454
511
  };
455
512
 
456
513
  function content(
@@ -477,6 +534,9 @@ function splitModuleIdAndModulePath(path) {
477
534
  function isObjectSchema(schema) {
478
535
  return schema instanceof ObjectSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "object";
479
536
  }
537
+ function isRecordSchema(schema) {
538
+ return schema instanceof RecordSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "record";
539
+ }
480
540
  function isArraySchema(schema) {
481
541
  return schema instanceof ArraySchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "array";
482
542
  }
@@ -535,6 +595,18 @@ function resolvePath(path, valModule, schema) {
535
595
  }
536
596
  resolvedSource = resolvedSource[part];
537
597
  resolvedSchema = resolvedSchema.item;
598
+ } else if (isRecordSchema(resolvedSchema)) {
599
+ if (typeof part !== "string") {
600
+ throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
601
+ }
602
+ if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
603
+ throw Error("Schema type error: expected source to be type of record, but got ".concat(index._typeof(resolvedSource)));
604
+ }
605
+ if (!resolvedSource[part]) {
606
+ throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
607
+ }
608
+ resolvedSource = resolvedSource[part];
609
+ resolvedSchema = resolvedSchema.item;
538
610
  } else if (isObjectSchema(resolvedSchema)) {
539
611
  if (index._typeof(resolvedSource) !== "object") {
540
612
  throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
@@ -678,6 +750,7 @@ exports.getSource = getSource;
678
750
  exports.isSelector = isSelector;
679
751
  exports.newSelectorProxy = newSelectorProxy;
680
752
  exports.object = object;
753
+ exports.record = record;
681
754
  exports.resolvePath = resolvePath;
682
755
  exports.richtext = richtext;
683
756
  exports.splitModuleIdAndModulePath = splitModuleIdAndModulePath;