@valbuild/core 0.26.0 → 0.27.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/package.json +12 -3
- package/CHANGELOG.md +0 -0
- package/ROADMAP.md +0 -106
- package/jest.config.js +0 -4
- package/src/Json.ts +0 -4
- package/src/ValApi.ts +0 -81
- package/src/expr/README.md +0 -193
- package/src/expr/eval.test.ts +0 -198
- package/src/expr/eval.ts +0 -251
- package/src/expr/expr.ts +0 -91
- package/src/expr/index.ts +0 -3
- package/src/expr/parser.test.ts +0 -158
- package/src/expr/parser.ts +0 -229
- package/src/expr/repl.ts +0 -88
- package/src/expr/tokenizer.test.ts +0 -539
- package/src/expr/tokenizer.ts +0 -117
- package/src/fp/array.ts +0 -30
- package/src/fp/index.ts +0 -3
- package/src/fp/result.ts +0 -214
- package/src/fp/util.ts +0 -52
- package/src/future/fetchVal.test.ts +0 -164
- package/src/future/fetchVal.ts +0 -206
- package/src/getSha256.ts +0 -8
- package/src/index.ts +0 -132
- package/src/initSchema.ts +0 -50
- package/src/initVal.ts +0 -73
- package/src/module.test.ts +0 -170
- package/src/module.ts +0 -397
- package/src/patch/deref.test.ts +0 -298
- package/src/patch/deref.ts +0 -136
- package/src/patch/index.ts +0 -12
- package/src/patch/json.test.ts +0 -582
- package/src/patch/json.ts +0 -304
- package/src/patch/operation.ts +0 -86
- package/src/patch/ops.ts +0 -83
- package/src/patch/parse.test.ts +0 -202
- package/src/patch/parse.ts +0 -202
- package/src/patch/patch.ts +0 -49
- package/src/patch/util.ts +0 -74
- package/src/schema/array.ts +0 -93
- package/src/schema/boolean.ts +0 -49
- package/src/schema/future/i18n.ts +0 -69
- package/src/schema/future/oneOf.ts +0 -63
- package/src/schema/image.ts +0 -137
- package/src/schema/index.ts +0 -70
- package/src/schema/keyOf.ts +0 -167
- package/src/schema/literal.ts +0 -63
- package/src/schema/number.ts +0 -56
- package/src/schema/object.ts +0 -110
- package/src/schema/record.ts +0 -103
- package/src/schema/richtext.ts +0 -44
- package/src/schema/string.ts +0 -95
- package/src/schema/union.ts +0 -63
- package/src/schema/validation/ValidationError.ts +0 -16
- package/src/schema/validation/ValidationFix.ts +0 -6
- package/src/schema/validation.test.ts +0 -291
- package/src/selector/SelectorProxy.ts +0 -238
- package/src/selector/array.ts +0 -13
- package/src/selector/boolean.ts +0 -4
- package/src/selector/file.ts +0 -6
- package/src/selector/future/ExprProxy.test.ts +0 -203
- package/src/selector/future/ExprProxy.ts +0 -216
- package/src/selector/future/SelectorProxy.test.ts +0 -172
- package/src/selector/future/SelectorProxy.ts +0 -238
- package/src/selector/future/array.ts +0 -37
- package/src/selector/future/boolean.ts +0 -4
- package/src/selector/future/file.ts +0 -14
- package/src/selector/future/i18n.ts +0 -13
- package/src/selector/future/index.ts +0 -169
- package/src/selector/future/number.ts +0 -4
- package/src/selector/future/object.ts +0 -22
- package/src/selector/future/primitive.ts +0 -17
- package/src/selector/future/remote.ts +0 -9
- package/src/selector/future/selector.test.ts +0 -429
- package/src/selector/future/selectorOf.ts +0 -7
- package/src/selector/future/string.ts +0 -4
- package/src/selector/index.ts +0 -121
- package/src/selector/number.ts +0 -4
- package/src/selector/object.ts +0 -5
- package/src/selector/primitive.ts +0 -4
- package/src/selector/string.ts +0 -4
- package/src/source/file.ts +0 -45
- package/src/source/future/i18n.ts +0 -60
- package/src/source/future/remote.ts +0 -54
- package/src/source/index.ts +0 -53
- package/src/source/link.ts +0 -14
- package/src/source/richtext.ts +0 -178
- package/src/val/array.ts +0 -10
- package/src/val/index.ts +0 -100
- package/src/val/object.ts +0 -13
- package/src/val/primitive.ts +0 -8
- package/tsconfig.json +0 -8
@@ -1,54 +0,0 @@
|
|
1
|
-
import { SourcePrimitive, VAL_EXTENSION, PhantomType } from "..";
|
2
|
-
import { FileSource } from "../file";
|
3
|
-
import { I18nCompatibleSource, I18nSource } from "./i18n";
|
4
|
-
import { AnyRichTextOptions, RichTextSource } from "../richtext";
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Remote sources cannot include other remote sources.
|
8
|
-
*/
|
9
|
-
export type RemoteCompatibleSource =
|
10
|
-
| SourcePrimitive
|
11
|
-
| RemoteObject
|
12
|
-
| RemoteArray
|
13
|
-
| RichTextSource<AnyRichTextOptions>
|
14
|
-
| FileSource
|
15
|
-
| I18nSource<string[], I18nCompatibleSource>;
|
16
|
-
export type RemoteObject = { [key in string]: RemoteCompatibleSource };
|
17
|
-
export type RemoteArray = readonly RemoteCompatibleSource[];
|
18
|
-
|
19
|
-
export const REMOTE_REF_PROP = "_ref" as const; // TODO: same as FILE_REF_PROP so use same prop?
|
20
|
-
|
21
|
-
declare const brand: unique symbol;
|
22
|
-
export type RemoteRef = string & { readonly [brand]: "RemoteRef" };
|
23
|
-
|
24
|
-
/**
|
25
|
-
* A remote source is a hash that represents a remote object.
|
26
|
-
*
|
27
|
-
* It will be resolved into a ValRemote object.
|
28
|
-
*/
|
29
|
-
export type RemoteSource<Src extends RemoteCompatibleSource> = {
|
30
|
-
readonly [REMOTE_REF_PROP]: RemoteRef;
|
31
|
-
readonly [VAL_EXTENSION]: "remote";
|
32
|
-
} & PhantomType<Src>;
|
33
|
-
|
34
|
-
export function remote<Src extends RemoteCompatibleSource>(
|
35
|
-
ref: string
|
36
|
-
): RemoteSource<Src> {
|
37
|
-
return {
|
38
|
-
[REMOTE_REF_PROP]: ref as RemoteRef,
|
39
|
-
[VAL_EXTENSION]: "remote",
|
40
|
-
} as RemoteSource<Src>;
|
41
|
-
}
|
42
|
-
|
43
|
-
export function isRemote(
|
44
|
-
obj: unknown
|
45
|
-
): obj is RemoteSource<RemoteCompatibleSource> {
|
46
|
-
return (
|
47
|
-
typeof obj === "object" &&
|
48
|
-
obj !== null &&
|
49
|
-
VAL_EXTENSION in obj &&
|
50
|
-
obj[VAL_EXTENSION] === "remote" &&
|
51
|
-
REMOTE_REF_PROP in obj &&
|
52
|
-
typeof obj[REMOTE_REF_PROP] === "string"
|
53
|
-
);
|
54
|
-
}
|
package/src/source/index.ts
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
import { FileSource } from "./file";
|
2
|
-
import { I18nSource, I18nCompatibleSource } from "./future/i18n";
|
3
|
-
import { RemoteSource, RemoteCompatibleSource } from "./future/remote";
|
4
|
-
import { RichTextOptions, RichTextSource } from "./richtext";
|
5
|
-
|
6
|
-
export type Source =
|
7
|
-
| SourcePrimitive
|
8
|
-
| SourceObject
|
9
|
-
| SourceArray
|
10
|
-
| I18nSource<string[], I18nCompatibleSource>
|
11
|
-
| RemoteSource<RemoteCompatibleSource>
|
12
|
-
| FileSource
|
13
|
-
| RichTextSource<RichTextOptions>;
|
14
|
-
|
15
|
-
export type SourceObject = { [key in string]: Source } & {
|
16
|
-
// TODO: update these restricted parameters:
|
17
|
-
fold?: never;
|
18
|
-
assert?: never;
|
19
|
-
andThen?: never;
|
20
|
-
_ref?: never;
|
21
|
-
_type?: never;
|
22
|
-
val?: never;
|
23
|
-
valPath?: never; // used when serializing vals
|
24
|
-
};
|
25
|
-
export type SourceArray = readonly Source[];
|
26
|
-
export type SourcePrimitive = string | number | boolean | null;
|
27
|
-
|
28
|
-
/* Branded extension types: file, remote, i18n */
|
29
|
-
export const VAL_EXTENSION = "_type" as const;
|
30
|
-
|
31
|
-
export function getValExtension(source: Source) {
|
32
|
-
return (
|
33
|
-
source &&
|
34
|
-
typeof source === "object" &&
|
35
|
-
VAL_EXTENSION in source &&
|
36
|
-
source[VAL_EXTENSION]
|
37
|
-
);
|
38
|
-
}
|
39
|
-
|
40
|
-
/**
|
41
|
-
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
42
|
-
*
|
43
|
-
* An example where this is useful is remote types, where the type of the remote source is known at compile time,
|
44
|
-
* but the value is not there before it is fetched.
|
45
|
-
*
|
46
|
-
* @example
|
47
|
-
* type Example<T> = string & PhantomType<T>;
|
48
|
-
*
|
49
|
-
**/
|
50
|
-
declare const PhantomType: unique symbol;
|
51
|
-
export type PhantomType<T> = {
|
52
|
-
[PhantomType]: T;
|
53
|
-
};
|
package/src/source/link.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { VAL_EXTENSION } from ".";
|
2
|
-
export type LinkSource = {
|
3
|
-
[VAL_EXTENSION]: "link";
|
4
|
-
href: string;
|
5
|
-
children: [string];
|
6
|
-
};
|
7
|
-
|
8
|
-
export function link(text: string, { href }: { href: string }): LinkSource {
|
9
|
-
return {
|
10
|
-
[VAL_EXTENSION]: "link",
|
11
|
-
href,
|
12
|
-
children: [text],
|
13
|
-
};
|
14
|
-
}
|
package/src/source/richtext.ts
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
import { FileSource } from "./file";
|
2
|
-
import { VAL_EXTENSION } from ".";
|
3
|
-
import { LinkSource } from "./link";
|
4
|
-
import { ImageMetadata } from "../schema/image";
|
5
|
-
|
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;
|
15
|
-
};
|
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
|
-
|
27
|
-
// Classes
|
28
|
-
export type LineThrough<O extends RichTextOptions> =
|
29
|
-
O["lineThrough"] extends true ? "line-through" : never;
|
30
|
-
|
31
|
-
export type Italic<O extends RichTextOptions> = O["italic"] extends true
|
32
|
-
? "italic"
|
33
|
-
: never;
|
34
|
-
|
35
|
-
export type Bold<O extends RichTextOptions> = O["bold"] extends true
|
36
|
-
? "bold"
|
37
|
-
: never;
|
38
|
-
|
39
|
-
export type Classes<O extends RichTextOptions> =
|
40
|
-
| LineThrough<O>
|
41
|
-
| Italic<O>
|
42
|
-
| Bold<O>;
|
43
|
-
|
44
|
-
/// Paragraph
|
45
|
-
export type ParagraphNode<O extends RichTextOptions> = {
|
46
|
-
tag: "p";
|
47
|
-
children: (string | SpanNode<O> | BrNode | LinkNode<O> | ImageNode<O>)[];
|
48
|
-
};
|
49
|
-
|
50
|
-
/// Break
|
51
|
-
export type BrNode = {
|
52
|
-
tag: "br";
|
53
|
-
children: [];
|
54
|
-
};
|
55
|
-
|
56
|
-
/// Span
|
57
|
-
export type SpanNode<O extends RichTextOptions> = {
|
58
|
-
tag: "span";
|
59
|
-
classes: Classes<O>[];
|
60
|
-
children: [string | SpanNode<O>];
|
61
|
-
};
|
62
|
-
|
63
|
-
/// Image
|
64
|
-
type ImageTagNode = {
|
65
|
-
tag: "img";
|
66
|
-
src: string;
|
67
|
-
height?: number;
|
68
|
-
width?: number;
|
69
|
-
children: [];
|
70
|
-
};
|
71
|
-
export type ImageNode<O extends RichTextOptions> = O["img"] extends true
|
72
|
-
? ImageTagNode
|
73
|
-
: never;
|
74
|
-
|
75
|
-
/// Link
|
76
|
-
type LinkTagNode<O extends RichTextOptions> = {
|
77
|
-
tag: "a";
|
78
|
-
href: string;
|
79
|
-
children: (string | SpanNode<O>)[];
|
80
|
-
};
|
81
|
-
export type LinkNode<O extends RichTextOptions> = O["a"] extends true
|
82
|
-
? LinkTagNode<O>
|
83
|
-
: never;
|
84
|
-
|
85
|
-
/// List
|
86
|
-
export type ListItemNode<O extends RichTextOptions> = {
|
87
|
-
tag: "li";
|
88
|
-
children: (
|
89
|
-
| string
|
90
|
-
| SpanNode<O>
|
91
|
-
| LinkNode<O>
|
92
|
-
| BrNode
|
93
|
-
| UnorderedListNode<O>
|
94
|
-
| OrderedListNode<O>
|
95
|
-
)[];
|
96
|
-
};
|
97
|
-
|
98
|
-
export type UnorderedListNode<O extends RichTextOptions> = O["ul"] extends true
|
99
|
-
? {
|
100
|
-
tag: "ul";
|
101
|
-
dir?: "ltr" | "rtl";
|
102
|
-
children: ListItemNode<O>[];
|
103
|
-
}
|
104
|
-
: never;
|
105
|
-
|
106
|
-
export type OrderedListNode<O extends RichTextOptions> = O["ol"] extends true
|
107
|
-
? {
|
108
|
-
tag: "ol";
|
109
|
-
dir?: "ltr" | "rtl";
|
110
|
-
children: ListItemNode<O>[];
|
111
|
-
}
|
112
|
-
: never;
|
113
|
-
|
114
|
-
/// Heading
|
115
|
-
export type HeadingNode<O extends RichTextOptions> = O["headings"] extends (
|
116
|
-
| "h1"
|
117
|
-
| "h2"
|
118
|
-
| "h3"
|
119
|
-
| "h4"
|
120
|
-
| "h5"
|
121
|
-
| "h6"
|
122
|
-
)[]
|
123
|
-
? {
|
124
|
-
tag: O["headings"][number];
|
125
|
-
children: (string | SpanNode<O>)[];
|
126
|
-
}
|
127
|
-
: never;
|
128
|
-
|
129
|
-
/// Root and nodes
|
130
|
-
export type RichTextNode<O extends RichTextOptions> =
|
131
|
-
| string
|
132
|
-
| RootNode<O>
|
133
|
-
| ListItemNode<O>
|
134
|
-
| BrNode
|
135
|
-
| SpanNode<O>
|
136
|
-
| LinkNode<O>
|
137
|
-
| ImageNode<O>;
|
138
|
-
|
139
|
-
export type RootNode<O extends RichTextOptions> =
|
140
|
-
| HeadingNode<O>
|
141
|
-
| ParagraphNode<O>
|
142
|
-
| BrNode
|
143
|
-
| UnorderedListNode<O>
|
144
|
-
| OrderedListNode<O>;
|
145
|
-
|
146
|
-
/// Main types
|
147
|
-
|
148
|
-
/**
|
149
|
-
* RichTextSource is defined in ValModules
|
150
|
-
**/
|
151
|
-
export type RichTextSource<O extends RichTextOptions> = {
|
152
|
-
[VAL_EXTENSION]: "richtext";
|
153
|
-
templateStrings: string[];
|
154
|
-
exprs: (
|
155
|
-
| (O["img"] extends true ? FileSource<ImageMetadata> : never)
|
156
|
-
| (O["a"] extends true ? LinkSource : never)
|
157
|
-
)[];
|
158
|
-
};
|
159
|
-
/**
|
160
|
-
* RichText is accessible by users (after conversion via useVal / fetchVal)
|
161
|
-
* Internally it is a Selector
|
162
|
-
**/
|
163
|
-
export type RichText<O extends RichTextOptions> = {
|
164
|
-
[VAL_EXTENSION]: "richtext";
|
165
|
-
children: RootNode<O>[];
|
166
|
-
};
|
167
|
-
|
168
|
-
export function richtext<O extends RichTextOptions>(
|
169
|
-
templateStrings: TemplateStringsArray,
|
170
|
-
...nodes: (FileSource<ImageMetadata> | LinkSource)[]
|
171
|
-
): RichTextSource<O> {
|
172
|
-
return {
|
173
|
-
[VAL_EXTENSION]: "richtext",
|
174
|
-
templateStrings: templateStrings as unknown as string[],
|
175
|
-
exprs:
|
176
|
-
nodes as RichTextSource<AnyRichTextOptions>["exprs"] as RichTextSource<O>["exprs"],
|
177
|
-
};
|
178
|
-
}
|
package/src/val/array.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
import { SourcePath, Val as UnknownVal } from ".";
|
2
|
-
import { JsonArray } from "../Json";
|
3
|
-
import { Path } from "../selector/index";
|
4
|
-
|
5
|
-
export type Val<T extends JsonArray> = {
|
6
|
-
readonly [key in keyof T]: UnknownVal<T[key]>;
|
7
|
-
} & {
|
8
|
-
readonly [Path]: SourcePath | undefined;
|
9
|
-
readonly val: T;
|
10
|
-
};
|
package/src/val/index.ts
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
import { Source, SourceArray, SourceObject } from "../source";
|
2
|
-
import { Val as ObjectVal } from "./object";
|
3
|
-
import { Val as ArrayVal } from "./array";
|
4
|
-
import { Val as PrimitiveVal } from "./primitive";
|
5
|
-
import { Json, JsonArray, JsonObject, JsonPrimitive } from "../Json";
|
6
|
-
import { Path, Selector } from "../selector";
|
7
|
-
import { I18nSource } from "../source/future/i18n";
|
8
|
-
import { RemoteSource } from "../source/future/remote";
|
9
|
-
import { FileSource } from "../source/file";
|
10
|
-
|
11
|
-
export type SerializedVal = {
|
12
|
-
val: SerializedVal | Json;
|
13
|
-
valPath: SourcePath | undefined;
|
14
|
-
};
|
15
|
-
export function isSerializedVal(val: unknown): val is SerializedVal {
|
16
|
-
return (
|
17
|
-
typeof val === "object" &&
|
18
|
-
val !== null &&
|
19
|
-
val !== undefined &&
|
20
|
-
("val" in val || "valPath" in val)
|
21
|
-
);
|
22
|
-
}
|
23
|
-
|
24
|
-
export type JsonOfSource<T extends Source> = Json extends T
|
25
|
-
? Json
|
26
|
-
: T extends I18nSource<readonly string[], infer U>
|
27
|
-
? JsonOfSource<U>
|
28
|
-
: T extends RemoteSource<infer U>
|
29
|
-
? JsonOfSource<U>
|
30
|
-
: T extends FileSource
|
31
|
-
? { url: string }
|
32
|
-
: T extends SourceObject
|
33
|
-
? {
|
34
|
-
[key in keyof T]: JsonOfSource<T[key]>;
|
35
|
-
}
|
36
|
-
: T extends SourceArray
|
37
|
-
? JsonOfSource<T[number]>[]
|
38
|
-
: T extends JsonPrimitive
|
39
|
-
? T
|
40
|
-
: never;
|
41
|
-
|
42
|
-
export type Val<T extends Json> = Json extends T
|
43
|
-
? {
|
44
|
-
readonly [Path]: SourcePath | undefined;
|
45
|
-
readonly val: Source;
|
46
|
-
}
|
47
|
-
: T extends JsonObject
|
48
|
-
? ObjectVal<T>
|
49
|
-
: T extends JsonArray
|
50
|
-
? ArrayVal<T>
|
51
|
-
: T extends JsonPrimitive
|
52
|
-
? PrimitiveVal<T>
|
53
|
-
: never;
|
54
|
-
|
55
|
-
export function isVal<T extends Json>(val: unknown): val is Val<T> {
|
56
|
-
return (
|
57
|
-
typeof val === "object" &&
|
58
|
-
val !== null &&
|
59
|
-
val !== undefined &&
|
60
|
-
Path in val &&
|
61
|
-
"val" in val
|
62
|
-
);
|
63
|
-
}
|
64
|
-
|
65
|
-
declare const brand: unique symbol;
|
66
|
-
/**
|
67
|
-
* The path of the source value.
|
68
|
-
*
|
69
|
-
* @example
|
70
|
-
* '/app/blogs.0.text' // the text property of the first element of the /app/blogs module
|
71
|
-
*/
|
72
|
-
export type SourcePath = string & {
|
73
|
-
[brand]: "SourcePath";
|
74
|
-
};
|
75
|
-
|
76
|
-
/**
|
77
|
-
* The path inside the module.
|
78
|
-
*
|
79
|
-
* @example
|
80
|
-
* '0."text"' // the text property of the first element of the module
|
81
|
-
*/
|
82
|
-
export type ModulePath = string & {
|
83
|
-
[brand]: "ModulePath";
|
84
|
-
};
|
85
|
-
|
86
|
-
/**
|
87
|
-
* The id of the module.
|
88
|
-
*
|
89
|
-
* @example
|
90
|
-
* '/app/blogs' // the /app/blogs module
|
91
|
-
*/
|
92
|
-
export type ModuleId = string & {
|
93
|
-
[brand]: "ModuleId";
|
94
|
-
};
|
95
|
-
|
96
|
-
export function getValPath(
|
97
|
-
valOrSelector: Val<Json> | Selector<Source>
|
98
|
-
): SourcePath | undefined {
|
99
|
-
return valOrSelector[Path];
|
100
|
-
}
|
package/src/val/object.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import { SourcePath, Val as UnknownVal } from ".";
|
2
|
-
import { JsonObject } from "../Json";
|
3
|
-
import { Path } from "../selector/index";
|
4
|
-
|
5
|
-
export type Val<T extends JsonObject> = Omit<
|
6
|
-
{
|
7
|
-
readonly [key in keyof T]: UnknownVal<T[key]>;
|
8
|
-
},
|
9
|
-
"valPath" | "val"
|
10
|
-
> & {
|
11
|
-
readonly [Path]: SourcePath | undefined;
|
12
|
-
readonly val: T;
|
13
|
-
};
|
package/src/val/primitive.ts
DELETED