@valbuild/core 0.12.0 → 0.13.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/jest.config.js +4 -0
- package/package.json +1 -1
- package/src/Json.ts +4 -0
- package/src/expr/README.md +193 -0
- package/src/expr/eval.test.ts +202 -0
- package/src/expr/eval.ts +248 -0
- package/src/expr/expr.ts +91 -0
- package/src/expr/index.ts +3 -0
- package/src/expr/parser.test.ts +158 -0
- package/src/expr/parser.ts +229 -0
- package/src/expr/repl.ts +93 -0
- package/src/expr/tokenizer.test.ts +539 -0
- package/src/expr/tokenizer.ts +117 -0
- package/src/fetchVal.test.ts +164 -0
- package/src/fetchVal.ts +211 -0
- package/src/fp/array.ts +30 -0
- package/src/fp/index.ts +3 -0
- package/src/fp/result.ts +214 -0
- package/src/fp/util.ts +52 -0
- package/src/index.ts +55 -0
- package/src/initSchema.ts +45 -0
- package/src/initVal.ts +96 -0
- package/src/module.test.ts +170 -0
- package/src/module.ts +333 -0
- package/src/patch/deref.test.ts +300 -0
- package/src/patch/deref.ts +128 -0
- package/src/patch/index.ts +11 -0
- package/src/patch/json.test.ts +583 -0
- package/src/patch/json.ts +304 -0
- package/src/patch/operation.ts +74 -0
- package/src/patch/ops.ts +83 -0
- package/src/patch/parse.test.ts +202 -0
- package/src/patch/parse.ts +187 -0
- package/src/patch/patch.ts +46 -0
- package/src/patch/util.ts +67 -0
- package/src/schema/array.ts +52 -0
- package/src/schema/boolean.ts +38 -0
- package/src/schema/i18n.ts +65 -0
- package/src/schema/image.ts +70 -0
- package/src/schema/index.ts +46 -0
- package/src/schema/literal.ts +42 -0
- package/src/schema/number.ts +45 -0
- package/src/schema/object.ts +67 -0
- package/src/schema/oneOf.ts +60 -0
- package/src/schema/richtext.ts +417 -0
- package/src/schema/string.ts +49 -0
- package/src/schema/union.ts +62 -0
- package/src/selector/ExprProxy.test.ts +203 -0
- package/src/selector/ExprProxy.ts +209 -0
- package/src/selector/SelectorProxy.test.ts +172 -0
- package/src/selector/SelectorProxy.ts +237 -0
- package/src/selector/array.ts +37 -0
- package/src/selector/boolean.ts +4 -0
- package/src/selector/file.ts +14 -0
- package/src/selector/i18n.ts +13 -0
- package/src/selector/index.ts +159 -0
- package/src/selector/number.ts +4 -0
- package/src/selector/object.ts +22 -0
- package/src/selector/primitive.ts +17 -0
- package/src/selector/remote.ts +9 -0
- package/src/selector/selector.test.ts +453 -0
- package/src/selector/selectorOf.ts +7 -0
- package/src/selector/string.ts +4 -0
- package/src/source/file.ts +45 -0
- package/src/source/i18n.ts +60 -0
- package/src/source/index.ts +50 -0
- package/src/source/remote.ts +54 -0
- package/src/val/array.ts +10 -0
- package/src/val/index.ts +90 -0
- package/src/val/object.ts +13 -0
- package/src/val/primitive.ts +8 -0
package/src/val/index.ts
ADDED
@@ -0,0 +1,90 @@
|
|
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/i18n";
|
8
|
+
import { RemoteSource } from "../source/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
|
+
declare const brand: unique symbol;
|
56
|
+
/**
|
57
|
+
* The path of the source value.
|
58
|
+
*
|
59
|
+
* @example
|
60
|
+
* '/app/blogs.0.text' // the text property of the first element of the /app/blogs module
|
61
|
+
*/
|
62
|
+
export type SourcePath = string & {
|
63
|
+
[brand]: "SourcePath";
|
64
|
+
};
|
65
|
+
|
66
|
+
/**
|
67
|
+
* The path inside the module.
|
68
|
+
*
|
69
|
+
* @example
|
70
|
+
* '0."text"' // the text property of the first element of the module
|
71
|
+
*/
|
72
|
+
export type ModulePath = string & {
|
73
|
+
[brand]: "ModulePath";
|
74
|
+
};
|
75
|
+
|
76
|
+
/**
|
77
|
+
* The id of the module.
|
78
|
+
*
|
79
|
+
* @example
|
80
|
+
* '/app/blogs' // the /app/blogs module
|
81
|
+
*/
|
82
|
+
export type ModuleId = string & {
|
83
|
+
[brand]: "ModuleId";
|
84
|
+
};
|
85
|
+
|
86
|
+
export function getValPath(
|
87
|
+
valOrSelector: Val<Json> | Selector<Source>
|
88
|
+
): SourcePath | undefined {
|
89
|
+
return valOrSelector[Path];
|
90
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { SourcePath, Val as UnknownVal } from ".";
|
2
|
+
import { JsonObject } from "../Json";
|
3
|
+
import { Path } from "../selector";
|
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
|
+
};
|