@valbuild/core 0.13.7 → 0.14.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 (68) hide show
  1. package/dist/declarations/src/expr/eval.d.ts +7 -6
  2. package/dist/declarations/src/expr/index.d.ts +3 -3
  3. package/dist/declarations/src/expr/parser.d.ts +2 -2
  4. package/dist/declarations/src/fetchVal.d.ts +2 -2
  5. package/dist/declarations/src/fp/index.d.ts +3 -3
  6. package/dist/declarations/src/fp/result.d.ts +1 -1
  7. package/dist/declarations/src/index.d.ts +23 -22
  8. package/dist/declarations/src/initSchema.d.ts +25 -25
  9. package/dist/declarations/src/initVal.d.ts +7 -13
  10. package/dist/declarations/src/module.d.ts +10 -10
  11. package/dist/declarations/src/patch/deref.d.ts +3 -3
  12. package/dist/declarations/src/patch/index.d.ts +6 -6
  13. package/dist/declarations/src/patch/json.d.ts +2 -2
  14. package/dist/declarations/src/patch/operation.d.ts +2 -2
  15. package/dist/declarations/src/patch/ops.d.ts +1 -1
  16. package/dist/declarations/src/patch/parse.d.ts +3 -3
  17. package/dist/declarations/src/patch/patch.d.ts +3 -3
  18. package/dist/declarations/src/patch/util.d.ts +2 -2
  19. package/dist/declarations/src/schema/array.d.ts +3 -3
  20. package/dist/declarations/src/schema/boolean.d.ts +2 -2
  21. package/dist/declarations/src/schema/i18n.d.ts +3 -3
  22. package/dist/declarations/src/schema/image.d.ts +3 -3
  23. package/dist/declarations/src/schema/index.d.ts +14 -14
  24. package/dist/declarations/src/schema/literal.d.ts +2 -2
  25. package/dist/declarations/src/schema/number.d.ts +2 -2
  26. package/dist/declarations/src/schema/object.d.ts +3 -3
  27. package/dist/declarations/src/schema/oneOf.d.ts +5 -5
  28. package/dist/declarations/src/schema/richtext.d.ts +3 -3
  29. package/dist/declarations/src/schema/string.d.ts +2 -2
  30. package/dist/declarations/src/schema/union.d.ts +5 -5
  31. package/dist/declarations/src/selector/array.d.ts +5 -5
  32. package/dist/declarations/src/selector/boolean.d.ts +1 -1
  33. package/dist/declarations/src/selector/file.d.ts +1 -1
  34. package/dist/declarations/src/selector/i18n.d.ts +3 -3
  35. package/dist/declarations/src/selector/index.d.ts +17 -17
  36. package/dist/declarations/src/selector/number.d.ts +1 -1
  37. package/dist/declarations/src/selector/object.d.ts +2 -2
  38. package/dist/declarations/src/selector/primitive.d.ts +3 -3
  39. package/dist/declarations/src/selector/remote.d.ts +2 -2
  40. package/dist/declarations/src/selector/string.d.ts +1 -1
  41. package/dist/declarations/src/source/file.d.ts +2 -2
  42. package/dist/declarations/src/source/i18n.d.ts +2 -2
  43. package/dist/declarations/src/source/index.d.ts +4 -4
  44. package/dist/declarations/src/source/remote.d.ts +4 -4
  45. package/dist/declarations/src/source/richtext.d.ts +2 -2
  46. package/dist/declarations/src/val/array.d.ts +3 -3
  47. package/dist/declarations/src/val/index.d.ts +9 -9
  48. package/dist/declarations/src/val/object.d.ts +3 -3
  49. package/dist/declarations/src/val/primitive.d.ts +3 -3
  50. package/dist/{index-b861a6d2.esm.js → index-06df0a5b.esm.js} +5 -3
  51. package/dist/{index-2f65eaa1.cjs.dev.js → index-9663f28a.cjs.dev.js} +4 -2
  52. package/dist/{index-104b3b67.cjs.prod.js → index-b2270f8f.cjs.prod.js} +4 -2
  53. package/dist/valbuild-core.cjs.dev.js +141 -145
  54. package/dist/valbuild-core.cjs.prod.js +141 -145
  55. package/dist/valbuild-core.esm.js +142 -146
  56. package/expr/dist/valbuild-core-expr.cjs.dev.js +1 -1
  57. package/expr/dist/valbuild-core-expr.cjs.prod.js +1 -1
  58. package/expr/dist/valbuild-core-expr.esm.js +1 -1
  59. package/package.json +1 -1
  60. package/src/expr/eval.test.ts +4 -8
  61. package/src/expr/eval.ts +7 -4
  62. package/src/expr/parser.test.ts +1 -1
  63. package/src/expr/repl.ts +2 -7
  64. package/src/index.ts +3 -2
  65. package/src/initVal.ts +1 -21
  66. package/src/selector/selector.test.ts +2 -6
  67. package/dist/declarations/src/expr/tokenizer.d.ts +0 -7
  68. package/dist/declarations/src/selector/SelectorProxy.d.ts +0 -7
@@ -1,8 +1,7 @@
1
- import { pipe, result } from "../../fp";
1
+ import { pipe, result } from "../fp";
2
2
  import { Path } from "../selector";
3
- import { newSelectorProxy, selectorToVal } from "../selector/SelectorProxy";
3
+ import { selectorToVal } from "../selector/SelectorProxy";
4
4
  import { Source } from "../source";
5
- import { SourcePath } from "../val";
6
5
  import { evaluate } from "./eval";
7
6
  import { parse } from "./parser";
8
7
 
@@ -186,11 +185,8 @@ describe("eval", () => {
186
185
  pipe(
187
186
  evaluate(
188
187
  parseRes.value,
189
- (ref) => {
190
- return newSelectorProxy(
191
- sources[ref as keyof typeof sources],
192
- ref as SourcePath
193
- );
188
+ (path) => {
189
+ return sources[path as keyof typeof sources];
194
190
  },
195
191
  []
196
192
  ),
package/src/expr/eval.ts CHANGED
@@ -5,6 +5,7 @@ import { result } from "../fp";
5
5
  import { Path, SourceOrExpr } from "../selector";
6
6
  import { newSelectorProxy } from "../selector/SelectorProxy";
7
7
  import { isSerializedVal, SourcePath } from "../val";
8
+ import { Json } from "../Json";
8
9
 
9
10
  export class EvalError {
10
11
  constructor(public readonly message: string, public readonly expr: Expr) {}
@@ -26,7 +27,7 @@ type LocalSelector<S extends Source> = {
26
27
  const MAX_STACK_SIZE = 100; // an arbitrary semi-large number
27
28
  function evaluateSync(
28
29
  expr: Expr,
29
- getSource: (ref: string) => LocalSelector<Source>,
30
+ getSource: (path: string) => Json,
30
31
  stack: readonly LocalSelector<Source>[][]
31
32
  ): LocalSelector<Source> {
32
33
  // TODO: amount of evaluates should be limited?
@@ -48,7 +49,8 @@ function evaluateSync(
48
49
  throw new EvalError("cannot call 'val' as anonymous function", expr);
49
50
  }
50
51
  if (expr.children[1] instanceof StringLiteral) {
51
- return getSource(expr.children[1].value);
52
+ const path = expr.children[1].value as SourcePath;
53
+ return newSelectorProxy(getSource(path), path);
52
54
  } else {
53
55
  throw new EvalError(
54
56
  "argument of 'val' must be a string literal",
@@ -148,7 +150,8 @@ function evaluateSync(
148
150
  if (expr.children[0] instanceof Sym) {
149
151
  if (expr.children[0].value === "val") {
150
152
  if (expr.children[1] instanceof StringLiteral) {
151
- return getSource(expr.children[1].value);
153
+ const path = expr.children[1].value as SourcePath;
154
+ return newSelectorProxy(getSource(path), path);
152
155
  } else {
153
156
  throw new EvalError(
154
157
  "argument of 'val' must be a string literal",
@@ -234,7 +237,7 @@ function evaluateSync(
234
237
 
235
238
  export function evaluate(
236
239
  expr: Expr,
237
- source: (ref: string) => LocalSelector<Source>,
240
+ source: (ref: string) => Json,
238
241
  stack: readonly LocalSelector<Source>[][]
239
242
  ): result.Result<LocalSelector<Source>, EvalError> {
240
243
  try {
@@ -1,4 +1,4 @@
1
- import { result } from "../../fp";
1
+ import { result } from "../fp";
2
2
  import { parse } from "./parser";
3
3
 
4
4
  const ParserTestCases: {
package/src/expr/repl.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as repl from "repl";
2
2
  import { result, pipe } from "../../fp";
3
- import { newSelectorProxy, selectorToVal } from "../selector/SelectorProxy";
4
- import { SourcePath } from "../val";
3
+ import { selectorToVal } from "../selector/SelectorProxy";
5
4
  import { evaluate } from "./eval";
6
5
  import { parse } from "./parser";
7
6
 
@@ -57,11 +56,7 @@ repl
57
56
  pipe(
58
57
  evaluate(
59
58
  res.value,
60
- (ref) =>
61
- newSelectorProxy(
62
- sources[ref as keyof typeof sources],
63
- ref as SourcePath
64
- ),
59
+ (path) => sources[path as keyof typeof sources],
65
60
 
66
61
  []
67
62
  ),
package/src/index.ts CHANGED
@@ -22,10 +22,11 @@ export {
22
22
  type SourcePath,
23
23
  type JsonOfSource,
24
24
  } from "./val";
25
- export { type Json } from "./Json";
25
+ export type { Json, JsonPrimitive } from "./Json";
26
26
  export * as expr from "./expr/";
27
27
  export { FILE_REF_PROP } from "./source/file";
28
- export { VAL_EXTENSION } from "./source";
28
+ export { VAL_EXTENSION, type SourceArray } from "./source";
29
+ export type { I18nSource } from "./source/i18n";
29
30
  export { derefPatch } from "./patch/deref";
30
31
  export {
31
32
  type SelectorSource,
package/src/initVal.ts CHANGED
@@ -3,11 +3,7 @@
3
3
  import { content } from "./module";
4
4
  import { i18n, I18n } from "./source/i18n";
5
5
  import { InitSchema, initSchema, InitSchemaLocalized } from "./initSchema";
6
- import { SelectorOf } from "./selector";
7
- import { getValPath as getPath, Val } from "./val";
8
- import { SelectorSource, GenericSelector } from "./selector";
9
- import { JsonOfSource } from "./val";
10
- import { fetchVal } from "./fetchVal";
6
+ import { getValPath as getPath } from "./val";
11
7
  import { remote } from "./source/remote";
12
8
  import { file } from "./source/file";
13
9
  import { richtext } from "./source/richtext";
@@ -15,7 +11,6 @@ import { richtext } from "./source/richtext";
15
11
  type ValConstructor = {
16
12
  content: typeof content;
17
13
  getPath: typeof getPath;
18
- key: typeof getPath;
19
14
  remote: typeof remote;
20
15
  file: typeof file;
21
16
  richtext: typeof richtext;
@@ -27,21 +22,10 @@ export type InitVal<Locales extends readonly string[] | undefined> = [
27
22
  val: ValConstructor & {
28
23
  i18n: I18n<Locales>;
29
24
  };
30
- fetchVal<T extends SelectorSource>(
31
- selector: T,
32
- locale: Locales[number]
33
- ): SelectorOf<T> extends GenericSelector<infer S>
34
- ? Promise<Val<JsonOfSource<S>>>
35
- : never;
36
25
  s: InitSchema & InitSchemaLocalized<Locales>;
37
26
  }
38
27
  : {
39
28
  val: ValConstructor;
40
- fetchVal<T extends SelectorSource>(
41
- selector: T
42
- ): SelectorOf<T> extends GenericSelector<infer S>
43
- ? Promise<Val<JsonOfSource<S>>>
44
- : never;
45
29
  s: InitSchema;
46
30
  };
47
31
 
@@ -72,11 +56,9 @@ export const initVal = <
72
56
  i18n,
73
57
  remote,
74
58
  getPath,
75
- key: getPath,
76
59
  file,
77
60
  richtext,
78
61
  },
79
- fetchVal: fetchVal,
80
62
  s,
81
63
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
64
  } as any;
@@ -86,11 +68,9 @@ export const initVal = <
86
68
  content,
87
69
  remote,
88
70
  getPath,
89
- key: getPath,
90
71
  file,
91
72
  richtext,
92
73
  },
93
- fetchVal: fetchVal,
94
74
  s: {
95
75
  ...s,
96
76
  i18n: undefined,
@@ -6,7 +6,7 @@ import { SourcePath } from "../val";
6
6
  import { Source } from "../source";
7
7
  import { evaluate } from "../expr/eval";
8
8
  import * as expr from "../expr/expr";
9
- import { result } from "../../fp";
9
+ import { result } from "../fp";
10
10
  import { object } from "../schema/object";
11
11
  import { newSelectorProxy, selectorToVal } from "./SelectorProxy";
12
12
  import { newExprSelectorProxy } from "./ExprProxy";
@@ -289,11 +289,7 @@ describe("selector", () => {
289
289
  const res = evaluate(
290
290
  // @ts-expect-error TODO: fix this
291
291
  input()[SourceOrExpr],
292
- (ref) =>
293
- newSelectorProxy(
294
- modules[ref as keyof typeof modules],
295
- ref as SourcePath
296
- ),
292
+ (path) => modules[path as keyof typeof modules],
297
293
  []
298
294
  );
299
295
  if (result.isErr(res)) {
@@ -1,7 +0,0 @@
1
- export type Token = {
2
- readonly type: "!(" | "(" | ")" | "string" | "token" | "ws" | "${" | "}" | "'";
3
- readonly span: [start: number, stop: number];
4
- readonly value?: string;
5
- readonly unescapedValue?: string;
6
- };
7
- export declare function tokenize(input: string): [tokens: Token[], endCursor: number];
@@ -1,7 +0,0 @@
1
- import { GenericSelector } from ".";
2
- import { Source } from "../source";
3
- import { SourcePath } from "../val";
4
- export declare function isSelector(source: any): source is GenericSelector<Source>;
5
- export declare function newSelectorProxy(source: any, path?: SourcePath, moduleSchema?: any): any;
6
- export declare function createValPathOfItem(arrayPath: SourcePath | undefined, prop: string | number | symbol): SourcePath | undefined;
7
- export declare function selectorToVal(s: any): any;