@valbuild/core 0.15.0 → 0.17.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 (133) hide show
  1. package/ROADMAP.md +106 -0
  2. package/dist/declarations/src/ValApi.d.ts +26 -0
  3. package/dist/declarations/src/expr/eval.d.ts +1 -1
  4. package/dist/declarations/src/future/fetchVal.d.ts +5 -0
  5. package/dist/declarations/src/index.d.ts +38 -9
  6. package/dist/declarations/src/initSchema.d.ts +2 -10
  7. package/dist/declarations/src/initVal.d.ts +3 -21
  8. package/dist/declarations/src/module.d.ts +2 -14
  9. package/dist/declarations/src/patch/index.d.ts +1 -1
  10. package/dist/declarations/src/patch/util.d.ts +2 -0
  11. package/dist/declarations/src/schema/array.d.ts +3 -2
  12. package/dist/declarations/src/schema/boolean.d.ts +3 -2
  13. package/dist/declarations/src/schema/image.d.ts +4 -3
  14. package/dist/declarations/src/schema/index.d.ts +8 -7
  15. package/dist/declarations/src/schema/keyOf.d.ts +23 -0
  16. package/dist/declarations/src/schema/literal.d.ts +3 -2
  17. package/dist/declarations/src/schema/number.d.ts +3 -2
  18. package/dist/declarations/src/schema/object.d.ts +3 -2
  19. package/dist/declarations/src/schema/record.d.ts +19 -0
  20. package/dist/declarations/src/schema/richtext.d.ts +3 -2
  21. package/dist/declarations/src/schema/string.d.ts +3 -2
  22. package/dist/declarations/src/schema/union.d.ts +4 -2
  23. package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
  24. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
  25. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  26. package/dist/declarations/src/selector/array.d.ts +2 -13
  27. package/dist/declarations/src/selector/file.d.ts +1 -4
  28. package/dist/declarations/src/selector/future/array.d.ts +17 -0
  29. package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
  30. package/dist/declarations/src/selector/future/file.d.ts +9 -0
  31. package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
  32. package/dist/declarations/src/selector/future/index.d.ts +81 -0
  33. package/dist/declarations/src/selector/future/number.d.ts +2 -0
  34. package/dist/declarations/src/selector/future/object.d.ts +10 -0
  35. package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
  36. package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
  37. package/dist/declarations/src/selector/future/string.d.ts +2 -0
  38. package/dist/declarations/src/selector/index.d.ts +5 -32
  39. package/dist/declarations/src/selector/object.d.ts +2 -9
  40. package/dist/declarations/src/selector/primitive.d.ts +3 -9
  41. package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
  42. package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
  43. package/dist/declarations/src/source/index.d.ts +4 -3
  44. package/dist/declarations/src/val/index.d.ts +2 -2
  45. package/dist/index-369caccf.esm.js +550 -0
  46. package/dist/{index-06df0a5b.esm.js → index-3e3e839e.esm.js} +190 -555
  47. package/dist/{index-9663f28a.cjs.dev.js → index-486c7fbf.cjs.dev.js} +224 -617
  48. package/dist/{index-b2270f8f.cjs.prod.js → index-601a7d73.cjs.prod.js} +224 -617
  49. package/dist/index-8706c87e.cjs.prod.js +582 -0
  50. package/dist/index-a6e642dd.cjs.dev.js +582 -0
  51. package/dist/ops-0d09f8ee.cjs.prod.js +684 -0
  52. package/dist/ops-23a5abb2.esm.js +671 -0
  53. package/dist/ops-f3015423.cjs.dev.js +684 -0
  54. package/dist/valbuild-core.cjs.dev.js +640 -633
  55. package/dist/valbuild-core.cjs.prod.js +640 -633
  56. package/dist/valbuild-core.esm.js +578 -572
  57. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  58. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  59. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  60. package/package.json +2 -2
  61. package/patch/dist/valbuild-core-patch.cjs.dev.js +32 -23
  62. package/patch/dist/valbuild-core-patch.cjs.prod.js +32 -23
  63. package/patch/dist/valbuild-core-patch.esm.js +12 -4
  64. package/src/ValApi.ts +85 -0
  65. package/src/expr/eval.test.ts +2 -2
  66. package/src/expr/eval.ts +2 -2
  67. package/src/expr/repl.ts +2 -2
  68. package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
  69. package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
  70. package/src/index.ts +51 -14
  71. package/src/initSchema.ts +11 -12
  72. package/src/initVal.ts +42 -52
  73. package/src/module.test.ts +40 -40
  74. package/src/module.ts +53 -43
  75. package/src/patch/deref.test.ts +1 -1
  76. package/src/patch/deref.ts +1 -1
  77. package/src/patch/index.ts +1 -0
  78. package/src/patch/json.test.ts +0 -1
  79. package/src/patch/util.ts +7 -0
  80. package/src/schema/array.ts +45 -4
  81. package/src/schema/boolean.ts +14 -3
  82. package/src/schema/{i18n.ts → future/i18n.ts} +15 -11
  83. package/src/schema/{oneOf.ts → future/oneOf.ts} +21 -18
  84. package/src/schema/image.ts +66 -6
  85. package/src/schema/index.ts +37 -13
  86. package/src/schema/keyOf.ts +167 -0
  87. package/src/schema/literal.ts +24 -3
  88. package/src/schema/number.ts +14 -3
  89. package/src/schema/object.ts +50 -7
  90. package/src/schema/record.ts +103 -0
  91. package/src/schema/richtext.ts +63 -3
  92. package/src/schema/string.ts +14 -3
  93. package/src/schema/union.ts +4 -3
  94. package/src/schema/validation/ValidationError.ts +16 -0
  95. package/src/schema/validation/ValidationFix.ts +6 -0
  96. package/src/schema/validation.test.ts +291 -0
  97. package/src/selector/SelectorProxy.ts +16 -16
  98. package/src/selector/array.ts +2 -26
  99. package/src/selector/file.ts +1 -9
  100. package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
  101. package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
  102. package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
  103. package/src/selector/future/SelectorProxy.ts +238 -0
  104. package/src/selector/future/array.ts +37 -0
  105. package/src/selector/future/boolean.ts +4 -0
  106. package/src/selector/future/file.ts +14 -0
  107. package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
  108. package/src/selector/future/index.ts +165 -0
  109. package/src/selector/future/number.ts +4 -0
  110. package/src/selector/future/object.ts +22 -0
  111. package/src/selector/future/primitive.ts +17 -0
  112. package/src/selector/{remote.ts → future/remote.ts} +1 -1
  113. package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
  114. package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
  115. package/src/selector/future/string.ts +4 -0
  116. package/src/selector/index.ts +4 -46
  117. package/src/selector/object.ts +2 -19
  118. package/src/selector/primitive.ts +3 -16
  119. package/src/source/{i18n.ts → future/i18n.ts} +2 -2
  120. package/src/source/{remote.ts → future/remote.ts} +3 -3
  121. package/src/source/index.ts +3 -2
  122. package/src/val/array.ts +1 -1
  123. package/src/val/index.ts +2 -2
  124. package/src/val/object.ts +1 -1
  125. package/dist/createClass-012eebbf.esm.js +0 -109
  126. package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
  127. package/dist/createClass-de7426aa.cjs.prod.js +0 -116
  128. package/dist/declarations/src/fetchVal.d.ts +0 -5
  129. package/dist/declarations/src/schema/i18n.d.ts +0 -21
  130. package/dist/declarations/src/schema/oneOf.d.ts +0 -22
  131. package/dist/ops-6fae92a1.esm.js +0 -12
  132. package/dist/ops-87cdbafc.cjs.dev.js +0 -14
  133. package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -1,9 +1,9 @@
1
- import { initSchema } from "./initSchema";
2
- import { content } from "./module";
3
- import { getValPath } from "./val";
1
+ import { initSchema } from "../initSchema";
2
+ import { content } from "../module";
3
+ import { getValPath } from "../val";
4
4
  import { serializedValOfSelectorSource, fetchVal } from "./fetchVal";
5
5
 
6
- const s = initSchema(["en_US", "no_NB"]);
6
+ const s = initSchema();
7
7
  // const i18n = initI18n(["en_US", "no_NB"]);
8
8
 
9
9
  describe("serialization of val", () => {
@@ -108,57 +108,57 @@ describe("fetchVal", () => {
108
108
  expect(getValPath(test.foo.bar[1])).toStrictEqual('/app."foo"."bar".1');
109
109
  });
110
110
 
111
- test("valuate: array with map", async () => {
112
- const schema = s.array(s.string());
113
-
114
- const testVal = content("/app", schema, ["foo", "bar"]);
115
-
116
- const test = await fetchVal({
117
- // ^? should be Val<{ title: string }[]>
118
- foo: testVal.map((v) => ({ title: v })),
119
- test: testVal,
120
- });
121
- expect(test.val).toStrictEqual({
122
- foo: [{ title: "foo" }, { title: "bar" }],
123
- test: ["foo", "bar"],
124
- });
125
- });
126
-
127
- test("valuate: 2 modules with oneOf", async () => {
128
- const testVal1 = content("/testVal1", s.array(s.string()), [
129
- "test-val-1-0",
130
- "test-val-1-1",
131
- ]);
132
- const testVal2 = content(
133
- "/testVal2",
134
- s.object({ test1: s.oneOf(testVal1), test2: s.string() }),
135
- {
136
- test2: "test2 value",
137
- test1: testVal1[0],
138
- }
139
- );
140
-
141
- const test = await fetchVal({
142
- // ^?
143
- testVal1: testVal1.map((v) => ({ title: v, otherModule: testVal2 })),
144
- testVal2: testVal2,
145
- });
146
- expect(test.val).toStrictEqual({
147
- testVal1: [
148
- {
149
- title: "test-val-1-0",
150
- otherModule: { test2: "test2 value", test1: "test-val-1-0" },
151
- },
152
- {
153
- title: "test-val-1-1",
154
- otherModule: { test2: "test2 value", test1: "test-val-1-0" },
155
- },
156
- ],
157
- testVal2: { test2: "test2 value", test1: "test-val-1-0" },
158
- });
159
- expect(getValPath(test.testVal1[0].otherModule.test1)).toStrictEqual(
160
- "/testVal1.0"
161
- );
162
- expect(getValPath(test.testVal2.test2)).toStrictEqual('/testVal2."test2"');
163
- });
111
+ // test("valuate: array with map", async () => {
112
+ // const schema = s.array(s.string());
113
+
114
+ // const testVal = content("/app", schema, ["foo", "bar"]);
115
+
116
+ // const test = await fetchVal({
117
+ // // ^? should be Val<{ title: string }[]>
118
+ // foo: testVal.map((v) => ({ title: v })),
119
+ // test: testVal,
120
+ // });
121
+ // expect(test.val).toStrictEqual({
122
+ // foo: [{ title: "foo" }, { title: "bar" }],
123
+ // test: ["foo", "bar"],
124
+ // });
125
+ // });
126
+
127
+ // test("valuate: 2 modules with oneOf", async () => {
128
+ // const testVal1 = content("/testVal1", s.array(s.string()), [
129
+ // "test-val-1-0",
130
+ // "test-val-1-1",
131
+ // ]);
132
+ // const testVal2 = content(
133
+ // "/testVal2",
134
+ // s.object({ test1: s.oneOf(testVal1), test2: s.string() }),
135
+ // {
136
+ // test2: "test2 value",
137
+ // test1: testVal1[0],
138
+ // }
139
+ // );
140
+
141
+ // const test = await fetchVal({
142
+ // // ^?
143
+ // testVal1: testVal1.map((v) => ({ title: v, otherModule: testVal2 })),
144
+ // testVal2: testVal2,
145
+ // });
146
+ // expect(test.val).toStrictEqual({
147
+ // testVal1: [
148
+ // {
149
+ // title: "test-val-1-0",
150
+ // otherModule: { test2: "test2 value", test1: "test-val-1-0" },
151
+ // },
152
+ // {
153
+ // title: "test-val-1-1",
154
+ // otherModule: { test2: "test2 value", test1: "test-val-1-0" },
155
+ // },
156
+ // ],
157
+ // testVal2: { test2: "test2 value", test1: "test-val-1-0" },
158
+ // });
159
+ // expect(getValPath(test.testVal1[0].otherModule.test1)).toStrictEqual(
160
+ // "/testVal1.0"
161
+ // );
162
+ // expect(getValPath(test.testVal2.test2)).toStrictEqual('/testVal2."test2"');
163
+ // });
164
164
  });
@@ -3,39 +3,36 @@ import {
3
3
  Path,
4
4
  SelectorOf,
5
5
  SelectorSource,
6
- SourceOrExpr,
7
- } from "./selector";
6
+ GetSource,
7
+ } from "../selector";
8
8
  import {
9
9
  isSerializedVal,
10
10
  JsonOfSource,
11
11
  SerializedVal,
12
12
  SourcePath,
13
13
  Val,
14
- } from "./val";
14
+ } from "../val";
15
15
  import {
16
16
  createValPathOfItem,
17
17
  isSelector,
18
18
  newSelectorProxy,
19
- } from "./selector/SelectorProxy";
20
- import { Json } from "./Json";
19
+ } from "../selector/SelectorProxy";
20
+ import { Json } from "../Json";
21
21
 
22
22
  export function fetchVal<T extends SelectorSource>(
23
- selector: T,
24
- locale?: string
23
+ selector: T
25
24
  ): SelectorOf<T> extends GenericSelector<infer S>
26
25
  ? Promise<Val<JsonOfSource<S>>>
27
26
  : never {
28
27
  return Promise.resolve(
29
- getVal(selector, locale) as unknown
28
+ getVal(selector) as unknown
30
29
  ) as SelectorOf<T> extends GenericSelector<infer S>
31
30
  ? Promise<Val<JsonOfSource<S>>>
32
31
  : never;
33
32
  }
34
33
 
35
34
  export function getVal<T extends SelectorSource>(
36
- selector: T,
37
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
- locale?: string
35
+ selector: T
39
36
  ): SelectorOf<T> extends GenericSelector<infer S>
40
37
  ? Val<JsonOfSource<S>>
41
38
  : never {
@@ -50,9 +47,9 @@ export function getVal<T extends SelectorSource>(
50
47
  function isArrayOrArraySelector(child: any) {
51
48
  if (isSelector(child)) {
52
49
  return (
53
- typeof child[SourceOrExpr] === "object" &&
54
- typeof child[SourceOrExpr] !== null &&
55
- Array.isArray(child[SourceOrExpr])
50
+ typeof child[GetSource] === "object" &&
51
+ typeof child[GetSource] !== null &&
52
+ Array.isArray(child[GetSource])
56
53
  );
57
54
  }
58
55
  return Array.isArray(child);
@@ -62,9 +59,9 @@ function isArrayOrArraySelector(child: any) {
62
59
  function isObjectOrObjectSelector(child: any) {
63
60
  if (isSelector(child)) {
64
61
  return (
65
- typeof child[SourceOrExpr] === "object" &&
66
- typeof child[SourceOrExpr] !== null &&
67
- !Array.isArray(child[SourceOrExpr])
62
+ typeof child[GetSource] === "object" &&
63
+ typeof child[GetSource] !== null &&
64
+ !Array.isArray(child[GetSource])
68
65
  );
69
66
  }
70
67
  return typeof child === "object";
@@ -80,7 +77,7 @@ export function serializedValOfSelectorSource<T extends SelectorSource>(
80
77
  const isObject = isObjectOrObjectSelector(child);
81
78
  if (isArray) {
82
79
  const array = (
83
- SourceOrExpr in child ? child[SourceOrExpr] : child
80
+ GetSource in child ? child[GetSource] : child
84
81
  ) as Array<unknown>;
85
82
  const valPath = Path in child ? (child[Path] as SourcePath) : undefined;
86
83
  return {
@@ -94,9 +91,7 @@ export function serializedValOfSelectorSource<T extends SelectorSource>(
94
91
  valPath,
95
92
  };
96
93
  } else if (isObject) {
97
- const obj = (
98
- SourceOrExpr in child ? child[SourceOrExpr] : child
99
- ) as object;
94
+ const obj = (GetSource in child ? child[GetSource] : child) as object;
100
95
  const valPath = Path in child ? (child[Path] as SourcePath) : undefined;
101
96
  return {
102
97
  val:
@@ -115,7 +110,7 @@ export function serializedValOfSelectorSource<T extends SelectorSource>(
115
110
  };
116
111
  } else if (isSelector(child)) {
117
112
  return {
118
- val: rec(child[SourceOrExpr]),
113
+ val: rec(child[GetSource]),
119
114
  valPath: child[Path],
120
115
  };
121
116
  } else {
package/src/index.ts CHANGED
@@ -4,7 +4,6 @@ export { Schema, type SerializedSchema } from "./schema";
4
4
  export type { ValModule, SerializedModule } from "./module";
5
5
  export type { SourceObject, SourcePrimitive, Source } from "./source";
6
6
  export type { FileSource } from "./source/file";
7
- export type { RemoteSource } from "./source/remote";
8
7
  export type {
9
8
  RichTextSource,
10
9
  RichText,
@@ -23,37 +22,75 @@ export {
23
22
  type JsonOfSource,
24
23
  } from "./val";
25
24
  export type { Json, JsonPrimitive } from "./Json";
25
+ export type {
26
+ ValidationErrors,
27
+ ValidationError,
28
+ } from "./schema/validation/ValidationError";
29
+ export type { ValidationFix } from "./schema/validation/ValidationFix";
26
30
  export * as expr from "./expr/";
27
31
  export { FILE_REF_PROP } from "./source/file";
28
32
  export { VAL_EXTENSION, type SourceArray } from "./source";
29
- export type { I18nSource } from "./source/i18n";
30
33
  export { derefPatch } from "./patch/deref";
31
34
  export {
32
35
  type SelectorSource,
33
36
  type SelectorOf,
34
37
  GenericSelector,
35
38
  } from "./selector";
36
- import { getVal } from "./fetchVal";
37
- import {
38
- getRawSource,
39
- resolvePath,
40
- splitModuleIdAndModulePath,
41
- } from "./module";
39
+ import { getSource, resolvePath, splitModuleIdAndModulePath } from "./module";
42
40
  import { getSchema } from "./selector";
43
- import { getValPath, isVal } from "./val";
44
- import { convertImageSource } from "./schema/image";
45
- import { fetchVal } from "./fetchVal";
41
+ import { ModuleId, ModulePath, getValPath, isVal } from "./val";
42
+ import { convertFileSource } from "./schema/image";
43
+ import { createValPathOfItem } from "./selector/SelectorProxy";
44
+ import { getVal } from "./future/fetchVal";
45
+ import { Json } from "./Json";
46
+ import { SerializedSchema } from "./schema";
47
+ export { ValApi } from "./ValApi";
48
+
49
+ export type ApiTreeResponse = {
50
+ git: {
51
+ commit?: string;
52
+ branch?: string;
53
+ };
54
+ modules: Record<
55
+ ModuleId,
56
+ {
57
+ schema?: SerializedSchema;
58
+ patches?: {
59
+ applied: string[];
60
+ failed?: string[];
61
+ };
62
+ source?: Json;
63
+ }
64
+ >;
65
+ };
66
+
67
+ export type ApiPatchResponse = Record<ModuleId, string[]>;
46
68
 
47
69
  const Internal = {
48
- convertImageSource,
70
+ convertFileSource,
49
71
  getSchema,
50
72
  getValPath,
51
73
  getVal,
52
- getRawSource,
74
+ getSource,
53
75
  resolvePath,
54
76
  splitModuleIdAndModulePath,
55
- fetchVal,
56
77
  isVal,
78
+ createValPathOfItem,
79
+ createPatchJSONPath: (modulePath: ModulePath) =>
80
+ `/${modulePath
81
+ .split(".")
82
+ .map((segment) => JSON.parse(segment))
83
+ .join("/")}`,
84
+ /**
85
+ * Enables draft mode: updates all Val modules with patches
86
+ */
87
+ VAL_DRAFT_MODE_COOKIE: "val_draft_mode",
88
+ /**
89
+ * Enables Val: show the overlay / menu
90
+ */
91
+ VAL_ENABLE_COOKIE_NAME: "val_enable",
92
+ VAL_STATE_COOKIE: "val_state",
93
+ VAL_SESSION_COOKIE: "val_session",
57
94
  };
58
95
 
59
96
  export { Internal };
package/src/initSchema.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { F } from "ts-toolbelt";
1
+ // import type { F } from "ts-toolbelt";
2
2
  import { array } from "./schema/array";
3
3
  import { number } from "./schema/number";
4
4
  import { object } from "./schema/object";
5
5
  import { string } from "./schema/string";
6
6
  import { boolean } from "./schema/boolean";
7
- import { oneOf } from "./schema/oneOf";
8
7
  import { union } from "./schema/union";
9
- import { i18n, I18n } from "./schema/i18n";
10
8
  import { richtext } from "./schema/richtext";
11
9
  import { image } from "./schema/image";
12
10
  import { literal } from "./schema/literal";
11
+ // import { i18n, I18n } from "./schema/future/i18n";
12
+ // import { oneOf } from "./schema/future/oneOf";
13
13
 
14
14
  export type InitSchema = {
15
15
  readonly string: typeof string;
@@ -18,17 +18,16 @@ export type InitSchema = {
18
18
  readonly object: typeof object;
19
19
  readonly number: typeof number;
20
20
  readonly union: typeof union;
21
- readonly oneOf: typeof oneOf;
21
+ // readonly oneOf: typeof oneOf;
22
22
  readonly richtext: typeof richtext;
23
23
  readonly image: typeof image;
24
24
  readonly literal: typeof literal;
25
25
  };
26
- export type InitSchemaLocalized<Locales extends readonly string[]> = {
27
- readonly i18n: I18n<Locales>;
28
- };
29
- export function initSchema<Locales extends readonly string[]>(
30
- locales: F.Narrow<Locales>
31
- ) {
26
+ // export type InitSchemaLocalized<Locales extends readonly string[]> = {
27
+ // readonly i18n: I18n<Locales>;
28
+ // };
29
+ export function initSchema() {
30
+ // locales: F.Narrow<Locales>
32
31
  return {
33
32
  string,
34
33
  boolean,
@@ -36,10 +35,10 @@ export function initSchema<Locales extends readonly string[]>(
36
35
  object,
37
36
  number,
38
37
  union,
39
- oneOf,
38
+ // oneOf,
40
39
  richtext,
41
40
  image,
42
41
  literal,
43
- i18n: i18n(locales),
42
+ // i18n: i18n(locales),
44
43
  };
45
44
  }
package/src/initVal.ts CHANGED
@@ -1,79 +1,69 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
3
  import { content } from "./module";
4
- import { i18n, I18n } from "./source/i18n";
5
- import { InitSchema, initSchema, InitSchemaLocalized } from "./initSchema";
4
+ import { InitSchema, initSchema } from "./initSchema";
6
5
  import { getValPath as getPath } from "./val";
7
- import { remote } from "./source/remote";
8
6
  import { file } from "./source/file";
9
7
  import { richtext } from "./source/richtext";
8
+ // import { i18n, I18n } from "./source/future/i18n";
9
+ // import { remote } from "./source/future/remote";
10
10
 
11
11
  type ValConstructor = {
12
12
  content: typeof content;
13
13
  getPath: typeof getPath;
14
- remote: typeof remote;
14
+ // remote: typeof remote;
15
15
  file: typeof file;
16
16
  richtext: typeof richtext;
17
17
  };
18
- export type InitVal<Locales extends readonly string[] | undefined> = [
19
- Locales
20
- ] extends [readonly string[]]
21
- ? {
22
- val: ValConstructor & {
23
- i18n: I18n<Locales>;
24
- };
25
- s: InitSchema & InitSchemaLocalized<Locales>;
26
- }
27
- : {
28
- val: ValConstructor;
29
- s: InitSchema;
30
- };
18
+ export type InitVal = {
19
+ val: ValConstructor;
20
+ s: InitSchema;
21
+ };
31
22
 
32
- type NarrowStrings<A> =
33
- | (A extends [] ? [] : never)
34
- | (A extends string ? A : never)
35
- | {
36
- [K in keyof A]: NarrowStrings<A[K]>;
37
- };
23
+ // type NarrowStrings<A> =
24
+ // | (A extends [] ? [] : never)
25
+ // | (A extends string ? A : never)
26
+ // | {
27
+ // [K in keyof A]: NarrowStrings<A[K]>;
28
+ // };
38
29
 
39
- export const initVal = <
40
- Locales extends readonly string[] | undefined
41
- >(options?: {
42
- readonly locales?: NarrowStrings<{
43
- readonly required: Locales;
44
- readonly fallback: Locales extends readonly string[]
45
- ? Locales[number]
46
- : never;
47
- }>;
48
- }): InitVal<Locales> => {
49
- const locales = options?.locales;
50
- const s = initSchema(locales?.required as readonly string[]);
51
- if (locales?.required) {
52
- console.error("Locales / i18n currently not implemented");
53
- return {
54
- val: {
55
- content,
56
- i18n,
57
- remote,
58
- getPath,
59
- file,
60
- richtext,
61
- },
62
- s,
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- } as any;
65
- }
30
+ // TODO: Rename to createValSystem (only to be used by internal things), we can then export * from '@valbuild/core' in the next package then.
31
+ export const initVal = (): // options?: {
32
+ // readonly locales?: NarrowStrings<{
33
+ // readonly required: Locales;
34
+ // readonly default: Locales extends readonly string[]
35
+ // ? Locales[number]
36
+ // : never;
37
+ // }>;
38
+ // }
39
+ InitVal => {
40
+ // const locales = options?.locales;
41
+ const s = initSchema();
42
+ // if (locales?.required) {
43
+ // console.error("Locales / i18n currently not implemented");
44
+ // return {
45
+ // val: {
46
+ // content,
47
+ // i18n,
48
+ // remote,
49
+ // getPath,
50
+ // file,
51
+ // richtext,
52
+ // },
53
+ // s,
54
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ // } as any;
56
+ // }
66
57
  return {
67
58
  val: {
68
59
  content,
69
- remote,
60
+ // remote,
70
61
  getPath,
71
62
  file,
72
63
  richtext,
73
64
  },
74
65
  s: {
75
66
  ...s,
76
- i18n: undefined,
77
67
  },
78
68
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
69
  } as any;
@@ -6,21 +6,21 @@ import {
6
6
  } from "./module";
7
7
  import { SchemaTypeOf } from "./schema";
8
8
  import { array } from "./schema/array";
9
- import { i18n as initI18nSchema } from "./schema/i18n";
10
- import { i18n as initI18nSource } from "./source/i18n";
11
9
  import { number } from "./schema/number";
12
10
  import { object } from "./schema/object";
13
11
  import { string, StringSchema } from "./schema/string";
14
12
  import { union } from "./schema/union";
15
- import { SourceOrExpr } from "./selector";
13
+ import { GetSource } from "./selector";
16
14
  import { newSelectorProxy } from "./selector/SelectorProxy";
17
15
  import { ModulePath, SourcePath } from "./val";
18
16
  import { literal } from "./schema/literal";
19
17
 
20
- const i18n = initI18nSchema(["en_US", "nb_NO"] as const);
21
- const val = {
22
- i18n: initI18nSource(["en_US", "nb_NO"] as const),
23
- };
18
+ // import { i18n as initI18nSchema } from "./schema/i18n";
19
+ // import { i18n as initI18nSource } from "./source/i18n";
20
+ // const i18n = initI18nSchema(["en_US", "nb_NO"] as const);
21
+ // const val = {
22
+ // i18n: initI18nSource(["en_US", "nb_NO"] as const),
23
+ // };
24
24
  describe("module", () => {
25
25
  test("parse path", () => {
26
26
  expect(parsePath('"foo"."bar".1."zoo"' as ModulePath)).toStrictEqual([
@@ -58,7 +58,7 @@ describe("module", () => {
58
58
  },
59
59
  })
60
60
  );
61
- expect(resolvedModuleAtPath[SourceOrExpr]).toStrictEqual("zoo2");
61
+ expect(resolvedModuleAtPath[GetSource]).toStrictEqual("zoo2");
62
62
  });
63
63
 
64
64
  test("getSourceAtPath: basic source", () => {
@@ -82,7 +82,7 @@ describe("module", () => {
82
82
  },
83
83
  })
84
84
  );
85
- expect(resolvedModuleAtPath[SourceOrExpr]).toStrictEqual("zoo2");
85
+ expect(resolvedModuleAtPath[GetSource]).toStrictEqual("zoo2");
86
86
  });
87
87
 
88
88
  test("getSchemaAtPath: array & object", () => {
@@ -110,37 +110,37 @@ describe("module", () => {
110
110
  expect(source).toStrictEqual("bar1");
111
111
  });
112
112
 
113
- test("getSchemaAtPath: i18n", () => {
114
- const basicSchema = array(
115
- object({
116
- foo: i18n(array(object({ bar: string() }))),
117
- zoo: number(),
118
- })
119
- );
120
- const res = resolveAtPath(
121
- '0."foo"."nb_NO".0."bar"' as ModulePath,
122
- [
123
- {
124
- foo: val.i18n({
125
- en_US: [
126
- {
127
- bar: "dive",
128
- },
129
- ],
130
- nb_NO: [
131
- {
132
- bar: "brun",
133
- },
134
- ],
135
- }),
136
- zoo: 1,
137
- },
138
- ] as SchemaTypeOf<typeof basicSchema>,
139
- basicSchema.serialize()
140
- );
141
- expect(res.schema).toStrictEqual(string().serialize());
142
- expect(res.source).toStrictEqual("brun");
143
- });
113
+ // test("getSchemaAtPath: i18n", () => {
114
+ // const basicSchema = array(
115
+ // object({
116
+ // foo: i18n(array(object({ bar: string() }))),
117
+ // zoo: number(),
118
+ // })
119
+ // );
120
+ // const res = resolveAtPath(
121
+ // '0."foo"."nb_NO".0."bar"' as ModulePath,
122
+ // [
123
+ // {
124
+ // foo: val.i18n({
125
+ // en_US: [
126
+ // {
127
+ // bar: "dive",
128
+ // },
129
+ // ],
130
+ // nb_NO: [
131
+ // {
132
+ // bar: "brun",
133
+ // },
134
+ // ],
135
+ // }),
136
+ // zoo: 1,
137
+ // },
138
+ // ] as SchemaTypeOf<typeof basicSchema>,
139
+ // basicSchema.serialize()
140
+ // );
141
+ // expect(res.schema).toStrictEqual(string().serialize());
142
+ // expect(res.source).toStrictEqual("brun");
143
+ // });
144
144
 
145
145
  test("getSchemaAtPath: union", () => {
146
146
  const basicSchema = array(