@valbuild/core 0.16.0 → 0.18.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/ROADMAP.md +106 -0
- package/dist/declarations/src/ValApi.d.ts +26 -0
- package/dist/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/future/fetchVal.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +36 -9
- package/dist/declarations/src/initSchema.d.ts +8 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/schema/image.d.ts +1 -1
- package/dist/declarations/src/schema/index.d.ts +3 -5
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/union.d.ts +1 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +2 -13
- package/dist/declarations/src/selector/file.d.ts +1 -4
- package/dist/declarations/src/selector/future/array.d.ts +17 -0
- package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/future/file.d.ts +9 -0
- package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/selector/future/index.d.ts +81 -0
- package/dist/declarations/src/selector/future/number.d.ts +2 -0
- package/dist/declarations/src/selector/future/object.d.ts +10 -0
- package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
- package/dist/declarations/src/selector/future/string.d.ts +2 -0
- package/dist/declarations/src/selector/index.d.ts +5 -32
- package/dist/declarations/src/selector/object.d.ts +2 -9
- package/dist/declarations/src/selector/primitive.d.ts +3 -9
- package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
- package/dist/declarations/src/source/index.d.ts +4 -3
- package/dist/declarations/src/val/index.d.ts +2 -2
- package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
- package/dist/{index-af761363.esm.js → index-4abf3a1f.esm.js} +189 -1
- package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
- package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
- package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
- package/dist/{SelectorProxy-63c2d0e2.esm.js → index-a9235737.esm.js} +23 -195
- package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
- package/dist/{ops-74661336.esm.js → ops-a2a295f8.esm.js} +195 -65
- package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
- package/dist/valbuild-core.cjs.dev.js +784 -197
- package/dist/valbuild-core.cjs.prod.js +784 -197
- package/dist/valbuild-core.esm.js +719 -133
- package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +2 -3
- package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
- package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
- package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
- package/src/index.ts +46 -14
- package/src/initSchema.ts +17 -12
- package/src/initVal.ts +42 -52
- package/src/module.test.ts +40 -40
- package/src/module.ts +53 -43
- package/src/patch/deref.test.ts +1 -1
- package/src/patch/deref.ts +1 -1
- package/src/patch/json.test.ts +0 -1
- package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
- package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
- package/src/schema/image.ts +1 -1
- package/src/schema/index.ts +16 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/record.ts +103 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/validation.test.ts +195 -130
- package/src/selector/SelectorProxy.ts +15 -15
- package/src/selector/array.ts +2 -26
- package/src/selector/file.ts +1 -9
- package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
- package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
- package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
- package/src/selector/future/SelectorProxy.ts +238 -0
- package/src/selector/future/array.ts +37 -0
- package/src/selector/future/boolean.ts +4 -0
- package/src/selector/future/file.ts +14 -0
- package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
- package/src/selector/future/index.ts +165 -0
- package/src/selector/future/number.ts +4 -0
- package/src/selector/future/object.ts +22 -0
- package/src/selector/future/primitive.ts +17 -0
- package/src/selector/{remote.ts → future/remote.ts} +1 -1
- package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
- package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
- package/src/selector/future/string.ts +4 -0
- package/src/selector/index.ts +4 -46
- package/src/selector/object.ts +2 -19
- package/src/selector/primitive.ts +3 -16
- package/src/source/{i18n.ts → future/i18n.ts} +2 -2
- package/src/source/{remote.ts → future/remote.ts} +3 -3
- package/src/source/index.ts +3 -2
- package/src/val/array.ts +1 -1
- package/src/val/index.ts +2 -2
- package/src/val/object.ts +1 -1
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -22
- package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -1,9 +1,9 @@
|
|
1
|
-
import { initSchema } from "
|
2
|
-
import { content } from "
|
3
|
-
import { getValPath } from "
|
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(
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
});
|
126
|
-
|
127
|
-
test("valuate: 2 modules with oneOf", async () => {
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
7
|
-
} from "
|
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 "
|
14
|
+
} from "../val";
|
15
15
|
import {
|
16
16
|
createValPathOfItem,
|
17
17
|
isSelector,
|
18
18
|
newSelectorProxy,
|
19
|
-
} from "
|
20
|
-
import { Json } from "
|
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
|
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[
|
54
|
-
typeof child[
|
55
|
-
Array.isArray(child[
|
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[
|
66
|
-
typeof child[
|
67
|
-
!Array.isArray(child[
|
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
|
-
|
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[
|
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,
|
@@ -31,34 +30,67 @@ export type { ValidationFix } from "./schema/validation/ValidationFix";
|
|
31
30
|
export * as expr from "./expr/";
|
32
31
|
export { FILE_REF_PROP } from "./source/file";
|
33
32
|
export { VAL_EXTENSION, type SourceArray } from "./source";
|
34
|
-
export type { I18nSource } from "./source/i18n";
|
35
33
|
export { derefPatch } from "./patch/deref";
|
36
34
|
export {
|
37
35
|
type SelectorSource,
|
38
36
|
type SelectorOf,
|
39
37
|
GenericSelector,
|
40
38
|
} from "./selector";
|
41
|
-
import {
|
42
|
-
import {
|
43
|
-
getRawSource,
|
44
|
-
resolvePath,
|
45
|
-
splitModuleIdAndModulePath,
|
46
|
-
} from "./module";
|
39
|
+
import { getSource, resolvePath, splitModuleIdAndModulePath } from "./module";
|
47
40
|
import { getSchema } from "./selector";
|
48
|
-
import { getValPath, isVal } from "./val";
|
49
|
-
import {
|
50
|
-
import {
|
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[]>;
|
51
68
|
|
52
69
|
const Internal = {
|
53
|
-
|
70
|
+
convertFileSource,
|
54
71
|
getSchema,
|
55
72
|
getValPath,
|
56
73
|
getVal,
|
57
|
-
|
74
|
+
getSource,
|
58
75
|
resolvePath,
|
59
76
|
splitModuleIdAndModulePath,
|
60
|
-
fetchVal,
|
61
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",
|
62
94
|
};
|
63
95
|
|
64
96
|
export { Internal };
|
package/src/initSchema.ts
CHANGED
@@ -1,15 +1,17 @@
|
|
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 { keyOf } from "./schema/keyOf";
|
12
|
+
import { record } from "./schema/record";
|
13
|
+
// import { i18n, I18n } from "./schema/future/i18n";
|
14
|
+
// import { oneOf } from "./schema/future/oneOf";
|
13
15
|
|
14
16
|
export type InitSchema = {
|
15
17
|
readonly string: typeof string;
|
@@ -18,17 +20,18 @@ export type InitSchema = {
|
|
18
20
|
readonly object: typeof object;
|
19
21
|
readonly number: typeof number;
|
20
22
|
readonly union: typeof union;
|
21
|
-
readonly oneOf: typeof oneOf;
|
23
|
+
// readonly oneOf: typeof oneOf;
|
22
24
|
readonly richtext: typeof richtext;
|
23
25
|
readonly image: typeof image;
|
24
26
|
readonly literal: typeof literal;
|
27
|
+
readonly keyOf: typeof keyOf;
|
28
|
+
readonly record: typeof record;
|
25
29
|
};
|
26
|
-
export type InitSchemaLocalized<Locales extends readonly string[]> = {
|
27
|
-
|
28
|
-
};
|
29
|
-
export function initSchema
|
30
|
-
locales: F.Narrow<Locales>
|
31
|
-
) {
|
30
|
+
// export type InitSchemaLocalized<Locales extends readonly string[]> = {
|
31
|
+
// readonly i18n: I18n<Locales>;
|
32
|
+
// };
|
33
|
+
export function initSchema() {
|
34
|
+
// locales: F.Narrow<Locales>
|
32
35
|
return {
|
33
36
|
string,
|
34
37
|
boolean,
|
@@ -36,10 +39,12 @@ export function initSchema<Locales extends readonly string[]>(
|
|
36
39
|
object,
|
37
40
|
number,
|
38
41
|
union,
|
39
|
-
oneOf,
|
42
|
+
// oneOf,
|
40
43
|
richtext,
|
41
44
|
image,
|
42
45
|
literal,
|
43
|
-
|
46
|
+
keyOf,
|
47
|
+
record,
|
48
|
+
// i18n: i18n(locales),
|
44
49
|
};
|
45
50
|
}
|
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 {
|
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
|
19
|
-
|
20
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
const locales = options?.locales;
|
50
|
-
const s = initSchema(
|
51
|
-
if (locales?.required) {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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;
|
package/src/module.test.ts
CHANGED
@@ -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 {
|
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
|
-
|
21
|
-
|
22
|
-
|
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[
|
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[
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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(
|