@valbuild/core 0.25.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.
Files changed (94) hide show
  1. package/dist/declarations/src/selector/future/index.d.ts +1 -1
  2. package/dist/declarations/src/source/future/i18n.d.ts +1 -1
  3. package/package.json +12 -3
  4. package/CHANGELOG.md +0 -0
  5. package/ROADMAP.md +0 -106
  6. package/jest.config.js +0 -4
  7. package/src/Json.ts +0 -4
  8. package/src/ValApi.ts +0 -81
  9. package/src/expr/README.md +0 -193
  10. package/src/expr/eval.test.ts +0 -198
  11. package/src/expr/eval.ts +0 -251
  12. package/src/expr/expr.ts +0 -91
  13. package/src/expr/index.ts +0 -3
  14. package/src/expr/parser.test.ts +0 -158
  15. package/src/expr/parser.ts +0 -229
  16. package/src/expr/repl.ts +0 -88
  17. package/src/expr/tokenizer.test.ts +0 -539
  18. package/src/expr/tokenizer.ts +0 -117
  19. package/src/fp/array.ts +0 -30
  20. package/src/fp/index.ts +0 -3
  21. package/src/fp/result.ts +0 -214
  22. package/src/fp/util.ts +0 -52
  23. package/src/future/fetchVal.test.ts +0 -164
  24. package/src/future/fetchVal.ts +0 -206
  25. package/src/getSha256.ts +0 -8
  26. package/src/index.ts +0 -132
  27. package/src/initSchema.ts +0 -50
  28. package/src/initVal.ts +0 -73
  29. package/src/module.test.ts +0 -170
  30. package/src/module.ts +0 -397
  31. package/src/patch/deref.test.ts +0 -298
  32. package/src/patch/deref.ts +0 -136
  33. package/src/patch/index.ts +0 -12
  34. package/src/patch/json.test.ts +0 -582
  35. package/src/patch/json.ts +0 -304
  36. package/src/patch/operation.ts +0 -86
  37. package/src/patch/ops.ts +0 -83
  38. package/src/patch/parse.test.ts +0 -202
  39. package/src/patch/parse.ts +0 -202
  40. package/src/patch/patch.ts +0 -49
  41. package/src/patch/util.ts +0 -74
  42. package/src/schema/array.ts +0 -93
  43. package/src/schema/boolean.ts +0 -49
  44. package/src/schema/future/i18n.ts +0 -69
  45. package/src/schema/future/oneOf.ts +0 -63
  46. package/src/schema/image.ts +0 -137
  47. package/src/schema/index.ts +0 -70
  48. package/src/schema/keyOf.ts +0 -167
  49. package/src/schema/literal.ts +0 -63
  50. package/src/schema/number.ts +0 -56
  51. package/src/schema/object.ts +0 -110
  52. package/src/schema/record.ts +0 -103
  53. package/src/schema/richtext.ts +0 -44
  54. package/src/schema/string.ts +0 -95
  55. package/src/schema/union.ts +0 -63
  56. package/src/schema/validation/ValidationError.ts +0 -16
  57. package/src/schema/validation/ValidationFix.ts +0 -6
  58. package/src/schema/validation.test.ts +0 -291
  59. package/src/selector/SelectorProxy.ts +0 -238
  60. package/src/selector/array.ts +0 -13
  61. package/src/selector/boolean.ts +0 -4
  62. package/src/selector/file.ts +0 -6
  63. package/src/selector/future/ExprProxy.test.ts +0 -203
  64. package/src/selector/future/ExprProxy.ts +0 -216
  65. package/src/selector/future/SelectorProxy.test.ts +0 -172
  66. package/src/selector/future/SelectorProxy.ts +0 -238
  67. package/src/selector/future/array.ts +0 -37
  68. package/src/selector/future/boolean.ts +0 -4
  69. package/src/selector/future/file.ts +0 -14
  70. package/src/selector/future/i18n.ts +0 -13
  71. package/src/selector/future/index.ts +0 -169
  72. package/src/selector/future/number.ts +0 -4
  73. package/src/selector/future/object.ts +0 -22
  74. package/src/selector/future/primitive.ts +0 -17
  75. package/src/selector/future/remote.ts +0 -9
  76. package/src/selector/future/selector.test.ts +0 -429
  77. package/src/selector/future/selectorOf.ts +0 -7
  78. package/src/selector/future/string.ts +0 -4
  79. package/src/selector/index.ts +0 -121
  80. package/src/selector/number.ts +0 -4
  81. package/src/selector/object.ts +0 -5
  82. package/src/selector/primitive.ts +0 -4
  83. package/src/selector/string.ts +0 -4
  84. package/src/source/file.ts +0 -45
  85. package/src/source/future/i18n.ts +0 -60
  86. package/src/source/future/remote.ts +0 -54
  87. package/src/source/index.ts +0 -53
  88. package/src/source/link.ts +0 -14
  89. package/src/source/richtext.ts +0 -178
  90. package/src/val/array.ts +0 -10
  91. package/src/val/index.ts +0 -100
  92. package/src/val/object.ts +0 -13
  93. package/src/val/primitive.ts +0 -8
  94. package/tsconfig.json +0 -8
package/src/index.ts DELETED
@@ -1,132 +0,0 @@
1
- export { initVal } from "./initVal";
2
- export type { InitVal } from "./initVal";
3
- export { Schema, type SerializedSchema } from "./schema";
4
- export type { ImageMetadata } from "./schema/image";
5
- export type { LinkSource } from "./source/link";
6
- export type { ValModule, SerializedModule } from "./module";
7
- export type { SourceObject, SourcePrimitive, Source } from "./source";
8
- export type { FileSource } from "./source/file";
9
- export type {
10
- AnyRichTextOptions,
11
- Bold,
12
- Classes,
13
- HeadingNode,
14
- ImageNode,
15
- Italic,
16
- LineThrough,
17
- ListItemNode,
18
- LinkNode,
19
- OrderedListNode,
20
- ParagraphNode,
21
- BrNode,
22
- RichText,
23
- RichTextNode,
24
- RichTextOptions,
25
- RichTextSource,
26
- RootNode,
27
- SpanNode,
28
- UnorderedListNode,
29
- } from "./source/richtext";
30
- export {
31
- type Val,
32
- type SerializedVal,
33
- type ModuleId,
34
- type ModulePath,
35
- type SourcePath,
36
- type JsonOfSource,
37
- } from "./val";
38
- export type { Json, JsonPrimitive, JsonArray, JsonObject } from "./Json";
39
- export type {
40
- ValidationError,
41
- ValidationErrors,
42
- } from "./schema/validation/ValidationError";
43
- import type { ValidationErrors } from "./schema/validation/ValidationError";
44
- export type { ValidationFix } from "./schema/validation/ValidationFix";
45
- export * as expr from "./expr/";
46
- export { FILE_REF_PROP } from "./source/file";
47
- export { VAL_EXTENSION, type SourceArray } from "./source";
48
- export { derefPatch } from "./patch/deref";
49
- export {
50
- type SelectorSource,
51
- type SelectorOf,
52
- GenericSelector,
53
- } from "./selector";
54
- import { getSource, resolvePath, splitModuleIdAndModulePath } from "./module";
55
- import { getSchema } from "./selector";
56
- import { ModuleId, ModulePath, getValPath, isVal } from "./val";
57
- import { convertFileSource } from "./schema/image";
58
- import { createValPathOfItem } from "./selector/SelectorProxy";
59
- import { getVal } from "./future/fetchVal";
60
- import type { Json } from "./Json";
61
- import { SerializedSchema } from "./schema";
62
- import { getSHA256Hash } from "./getSha256";
63
- export { ValApi } from "./ValApi";
64
- export type { SerializedArraySchema } from "./schema/array";
65
- export type { SerializedObjectSchema } from "./schema/object";
66
- export type { SerializedRecordSchema } from "./schema/record";
67
- export type { SerializedStringSchema } from "./schema/string";
68
- export type { SerializedNumberSchema } from "./schema/number";
69
- export type { SerializedBooleanSchema } from "./schema/boolean";
70
- export type { SerializedImageSchema } from "./schema/image";
71
- export type { SerializedRichTextSchema } from "./schema/richtext";
72
-
73
- export type ApiTreeResponse = {
74
- git: {
75
- commit?: string;
76
- branch?: string;
77
- };
78
- modules: Record<
79
- ModuleId,
80
- {
81
- schema?: SerializedSchema;
82
- patches?: {
83
- applied: string[];
84
- failed?: string[];
85
- };
86
- source?: Json;
87
- errors?:
88
- | false
89
- | {
90
- invalidModuleId?: ModuleId;
91
- validation?: ValidationErrors;
92
- fatal?: {
93
- message: string;
94
- stack?: string;
95
- type?: string;
96
- }[];
97
- };
98
- }
99
- >;
100
- };
101
-
102
- export type ApiPatchResponse = Record<ModuleId, string[]>;
103
-
104
- const Internal = {
105
- convertFileSource,
106
- getSchema,
107
- getValPath,
108
- getVal,
109
- getSource,
110
- resolvePath,
111
- splitModuleIdAndModulePath,
112
- isVal,
113
- createValPathOfItem,
114
- getSHA256Hash,
115
- createPatchJSONPath: (modulePath: ModulePath) =>
116
- `/${modulePath
117
- .split(".")
118
- .map((segment) => JSON.parse(segment))
119
- .join("/")}`,
120
- /**
121
- * Enables draft mode: updates all Val modules with patches
122
- */
123
- VAL_DRAFT_MODE_COOKIE: "val_draft_mode",
124
- /**
125
- * Enables Val: show the overlay / menu
126
- */
127
- VAL_ENABLE_COOKIE_NAME: "val_enable",
128
- VAL_STATE_COOKIE: "val_state",
129
- VAL_SESSION_COOKIE: "val_session",
130
- };
131
-
132
- export { Internal };
package/src/initSchema.ts DELETED
@@ -1,50 +0,0 @@
1
- // import type { F } from "ts-toolbelt";
2
- import { array } from "./schema/array";
3
- import { number } from "./schema/number";
4
- import { object } from "./schema/object";
5
- import { string } from "./schema/string";
6
- import { boolean } from "./schema/boolean";
7
- import { union } from "./schema/union";
8
- import { richtext } from "./schema/richtext";
9
- import { image } from "./schema/image";
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";
15
-
16
- export type InitSchema = {
17
- readonly string: typeof string;
18
- readonly boolean: typeof boolean;
19
- readonly array: typeof array;
20
- readonly object: typeof object;
21
- readonly number: typeof number;
22
- readonly union: typeof union;
23
- // readonly oneOf: typeof oneOf;
24
- readonly richtext: typeof richtext;
25
- readonly image: typeof image;
26
- readonly literal: typeof literal;
27
- readonly keyOf: typeof keyOf;
28
- readonly record: typeof record;
29
- };
30
- // export type InitSchemaLocalized<Locales extends readonly string[]> = {
31
- // readonly i18n: I18n<Locales>;
32
- // };
33
- export function initSchema() {
34
- // locales: F.Narrow<Locales>
35
- return {
36
- string,
37
- boolean,
38
- array,
39
- object,
40
- number,
41
- union,
42
- // oneOf,
43
- richtext,
44
- image,
45
- literal,
46
- keyOf,
47
- record,
48
- // i18n: i18n(locales),
49
- };
50
- }
package/src/initVal.ts DELETED
@@ -1,73 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
- /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
- import { content } from "./module";
4
- import { InitSchema, initSchema } from "./initSchema";
5
- import { getValPath as getPath } from "./val";
6
- import { file } from "./source/file";
7
- import { richtext } from "./source/richtext";
8
- import { link } from "./source/link";
9
- // import { i18n, I18n } from "./source/future/i18n";
10
- // import { remote } from "./source/future/remote";
11
-
12
- type ValConstructor = {
13
- content: typeof content;
14
- getPath: typeof getPath;
15
- // remote: typeof remote;
16
- file: typeof file;
17
- link: typeof link;
18
- richtext: typeof richtext;
19
- };
20
- export type InitVal = {
21
- val: ValConstructor;
22
- s: InitSchema;
23
- };
24
-
25
- // type NarrowStrings<A> =
26
- // | (A extends [] ? [] : never)
27
- // | (A extends string ? A : never)
28
- // | {
29
- // [K in keyof A]: NarrowStrings<A[K]>;
30
- // };
31
-
32
- // TODO: Rename to createValSystem (only to be used by internal things), we can then export * from '@valbuild/core' in the next package then.
33
- export const initVal = (): // options?: {
34
- // readonly locales?: NarrowStrings<{
35
- // readonly required: Locales;
36
- // readonly default: Locales extends readonly string[]
37
- // ? Locales[number]
38
- // : never;
39
- // }>;
40
- // }
41
- InitVal => {
42
- // const locales = options?.locales;
43
- const s = initSchema();
44
- // if (locales?.required) {
45
- // console.error("Locales / i18n currently not implemented");
46
- // return {
47
- // val: {
48
- // content,
49
- // i18n,
50
- // remote,
51
- // getPath,
52
- // file,
53
- // richtext,
54
- // },
55
- // s,
56
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
- // } as any;
58
- // }
59
- return {
60
- val: {
61
- content,
62
- // remote,
63
- getPath,
64
- file,
65
- richtext,
66
- link,
67
- },
68
- s: {
69
- ...s,
70
- },
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- } as any;
73
- };
@@ -1,170 +0,0 @@
1
- import {
2
- resolvePath as resolveAtPath,
3
- getSourceAtPath,
4
- parsePath,
5
- splitModuleIdAndModulePath,
6
- } from "./module";
7
- import { SchemaTypeOf } from "./schema";
8
- import { array } from "./schema/array";
9
- import { number } from "./schema/number";
10
- import { object } from "./schema/object";
11
- import { string, StringSchema } from "./schema/string";
12
- import { union } from "./schema/union";
13
- import { GetSource } from "./selector";
14
- import { newSelectorProxy } from "./selector/SelectorProxy";
15
- import { ModulePath, SourcePath } from "./val";
16
- import { literal } from "./schema/literal";
17
-
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
- describe("module", () => {
25
- test("parse path", () => {
26
- expect(parsePath('"foo"."bar".1."zoo"' as ModulePath)).toStrictEqual([
27
- "foo",
28
- "bar",
29
- "1",
30
- "zoo",
31
- ]);
32
-
33
- expect(parsePath('"foo"."bar".1."z\\"oo"' as ModulePath)).toStrictEqual([
34
- "foo",
35
- "bar",
36
- "1",
37
- 'z"oo',
38
- ]);
39
-
40
- expect(parsePath('"foo"."b.ar".1."z\\"oo"' as ModulePath)).toStrictEqual([
41
- "foo",
42
- "b.ar",
43
- "1",
44
- 'z"oo',
45
- ]);
46
- });
47
-
48
- test("getSourceAtPath: basic selector", () => {
49
- const [, modulePath] = splitModuleIdAndModulePath(
50
- '/app."foo"."bar".1."zoo"' as SourcePath
51
- );
52
- expect(modulePath).toStrictEqual('"foo"."bar".1."zoo"');
53
- const resolvedModuleAtPath = getSourceAtPath(
54
- modulePath,
55
- newSelectorProxy({
56
- foo: {
57
- bar: [{ zoo: "zoo1" }, { zoo: "zoo2" }],
58
- },
59
- })
60
- );
61
- expect(resolvedModuleAtPath[GetSource]).toStrictEqual("zoo2");
62
- });
63
-
64
- test("getSourceAtPath: basic source", () => {
65
- const resolvedModuleAtPath = getSourceAtPath(
66
- '"foo"."bar".1."zoo"' as ModulePath,
67
- {
68
- foo: {
69
- bar: [{ zoo: "zoo1" }, { zoo: "zoo2" }],
70
- },
71
- }
72
- );
73
- expect(resolvedModuleAtPath).toStrictEqual("zoo2");
74
- });
75
-
76
- test("getSourceAtPath: with dots and escaped quotes", () => {
77
- const resolvedModuleAtPath = getSourceAtPath(
78
- '"foo"."b.ar".1."z\\"oo"' as ModulePath,
79
- newSelectorProxy({
80
- foo: {
81
- "b.ar": [{ 'z"oo': "zoo1" }, { 'z"oo': "zoo2" }],
82
- },
83
- })
84
- );
85
- expect(resolvedModuleAtPath[GetSource]).toStrictEqual("zoo2");
86
- });
87
-
88
- test("getSchemaAtPath: array & object", () => {
89
- const basicSchema = array(
90
- object({
91
- foo: array(object({ bar: string() })),
92
- zoo: number(),
93
- })
94
- );
95
- const { schema, source } = resolveAtPath(
96
- '0."foo".0."bar"' as ModulePath,
97
- [
98
- {
99
- foo: [
100
- {
101
- bar: "bar1",
102
- },
103
- ],
104
- zoo: 1,
105
- },
106
- ] as SchemaTypeOf<typeof basicSchema>,
107
- basicSchema
108
- );
109
- expect(schema).toBeInstanceOf(StringSchema);
110
- expect(source).toStrictEqual("bar1");
111
- });
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
- // });
144
-
145
- test("getSchemaAtPath: union", () => {
146
- const basicSchema = array(
147
- object({
148
- foo: union(
149
- "type",
150
- object({ type: literal("test1"), bar: object({ zoo: string() }) }),
151
- object({ type: literal("test2"), bar: object({ zoo: number() }) })
152
- ),
153
- })
154
- );
155
- const res = resolveAtPath(
156
- '0."foo"."bar"."zoo"' as ModulePath,
157
- [
158
- {
159
- foo: {
160
- type: "test2",
161
- bar: { zoo: 1 },
162
- },
163
- },
164
- ] as SchemaTypeOf<typeof basicSchema>,
165
- basicSchema.serialize()
166
- );
167
- expect(res.schema).toStrictEqual(number().serialize());
168
- expect(res.source).toStrictEqual(1);
169
- });
170
- });