@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.
Files changed (71) hide show
  1. package/jest.config.js +4 -0
  2. package/package.json +1 -1
  3. package/src/Json.ts +4 -0
  4. package/src/expr/README.md +193 -0
  5. package/src/expr/eval.test.ts +202 -0
  6. package/src/expr/eval.ts +248 -0
  7. package/src/expr/expr.ts +91 -0
  8. package/src/expr/index.ts +3 -0
  9. package/src/expr/parser.test.ts +158 -0
  10. package/src/expr/parser.ts +229 -0
  11. package/src/expr/repl.ts +93 -0
  12. package/src/expr/tokenizer.test.ts +539 -0
  13. package/src/expr/tokenizer.ts +117 -0
  14. package/src/fetchVal.test.ts +164 -0
  15. package/src/fetchVal.ts +211 -0
  16. package/src/fp/array.ts +30 -0
  17. package/src/fp/index.ts +3 -0
  18. package/src/fp/result.ts +214 -0
  19. package/src/fp/util.ts +52 -0
  20. package/src/index.ts +55 -0
  21. package/src/initSchema.ts +45 -0
  22. package/src/initVal.ts +96 -0
  23. package/src/module.test.ts +170 -0
  24. package/src/module.ts +333 -0
  25. package/src/patch/deref.test.ts +300 -0
  26. package/src/patch/deref.ts +128 -0
  27. package/src/patch/index.ts +11 -0
  28. package/src/patch/json.test.ts +583 -0
  29. package/src/patch/json.ts +304 -0
  30. package/src/patch/operation.ts +74 -0
  31. package/src/patch/ops.ts +83 -0
  32. package/src/patch/parse.test.ts +202 -0
  33. package/src/patch/parse.ts +187 -0
  34. package/src/patch/patch.ts +46 -0
  35. package/src/patch/util.ts +67 -0
  36. package/src/schema/array.ts +52 -0
  37. package/src/schema/boolean.ts +38 -0
  38. package/src/schema/i18n.ts +65 -0
  39. package/src/schema/image.ts +70 -0
  40. package/src/schema/index.ts +46 -0
  41. package/src/schema/literal.ts +42 -0
  42. package/src/schema/number.ts +45 -0
  43. package/src/schema/object.ts +67 -0
  44. package/src/schema/oneOf.ts +60 -0
  45. package/src/schema/richtext.ts +417 -0
  46. package/src/schema/string.ts +49 -0
  47. package/src/schema/union.ts +62 -0
  48. package/src/selector/ExprProxy.test.ts +203 -0
  49. package/src/selector/ExprProxy.ts +209 -0
  50. package/src/selector/SelectorProxy.test.ts +172 -0
  51. package/src/selector/SelectorProxy.ts +237 -0
  52. package/src/selector/array.ts +37 -0
  53. package/src/selector/boolean.ts +4 -0
  54. package/src/selector/file.ts +14 -0
  55. package/src/selector/i18n.ts +13 -0
  56. package/src/selector/index.ts +159 -0
  57. package/src/selector/number.ts +4 -0
  58. package/src/selector/object.ts +22 -0
  59. package/src/selector/primitive.ts +17 -0
  60. package/src/selector/remote.ts +9 -0
  61. package/src/selector/selector.test.ts +453 -0
  62. package/src/selector/selectorOf.ts +7 -0
  63. package/src/selector/string.ts +4 -0
  64. package/src/source/file.ts +45 -0
  65. package/src/source/i18n.ts +60 -0
  66. package/src/source/index.ts +50 -0
  67. package/src/source/remote.ts +54 -0
  68. package/src/val/array.ts +10 -0
  69. package/src/val/index.ts +90 -0
  70. package/src/val/object.ts +13 -0
  71. package/src/val/primitive.ts +8 -0
@@ -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
+ };
@@ -0,0 +1,8 @@
1
+ import { SourcePath } from ".";
2
+ import { JsonPrimitive } from "../Json";
3
+ import { Path } from "../selector";
4
+
5
+ export type Val<T extends JsonPrimitive> = {
6
+ [Path]: SourcePath | undefined;
7
+ val: T;
8
+ };