@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.
Files changed (104) 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 +36 -9
  6. package/dist/declarations/src/initSchema.d.ts +8 -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/schema/image.d.ts +1 -1
  10. package/dist/declarations/src/schema/index.d.ts +3 -5
  11. package/dist/declarations/src/schema/keyOf.d.ts +23 -0
  12. package/dist/declarations/src/schema/record.d.ts +19 -0
  13. package/dist/declarations/src/schema/union.d.ts +1 -0
  14. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  15. package/dist/declarations/src/selector/array.d.ts +2 -13
  16. package/dist/declarations/src/selector/file.d.ts +1 -4
  17. package/dist/declarations/src/selector/future/array.d.ts +17 -0
  18. package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
  19. package/dist/declarations/src/selector/future/file.d.ts +9 -0
  20. package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
  21. package/dist/declarations/src/selector/future/index.d.ts +81 -0
  22. package/dist/declarations/src/selector/future/number.d.ts +2 -0
  23. package/dist/declarations/src/selector/future/object.d.ts +10 -0
  24. package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
  25. package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
  26. package/dist/declarations/src/selector/future/string.d.ts +2 -0
  27. package/dist/declarations/src/selector/index.d.ts +5 -32
  28. package/dist/declarations/src/selector/object.d.ts +2 -9
  29. package/dist/declarations/src/selector/primitive.d.ts +3 -9
  30. package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
  31. package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
  32. package/dist/declarations/src/source/index.d.ts +4 -3
  33. package/dist/declarations/src/val/index.d.ts +2 -2
  34. package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
  35. package/dist/{index-af761363.esm.js → index-4abf3a1f.esm.js} +189 -1
  36. package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
  37. package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
  38. package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
  39. package/dist/{SelectorProxy-63c2d0e2.esm.js → index-a9235737.esm.js} +23 -195
  40. package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
  41. package/dist/{ops-74661336.esm.js → ops-a2a295f8.esm.js} +195 -65
  42. package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
  43. package/dist/valbuild-core.cjs.dev.js +784 -197
  44. package/dist/valbuild-core.cjs.prod.js +784 -197
  45. package/dist/valbuild-core.esm.js +719 -133
  46. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  47. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  48. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  49. package/package.json +2 -3
  50. package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
  51. package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
  52. package/patch/dist/valbuild-core-patch.esm.js +3 -3
  53. package/src/ValApi.ts +85 -0
  54. package/src/expr/eval.test.ts +2 -2
  55. package/src/expr/eval.ts +2 -2
  56. package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
  57. package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
  58. package/src/index.ts +46 -14
  59. package/src/initSchema.ts +17 -12
  60. package/src/initVal.ts +42 -52
  61. package/src/module.test.ts +40 -40
  62. package/src/module.ts +53 -43
  63. package/src/patch/deref.test.ts +1 -1
  64. package/src/patch/deref.ts +1 -1
  65. package/src/patch/json.test.ts +0 -1
  66. package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
  67. package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
  68. package/src/schema/image.ts +1 -1
  69. package/src/schema/index.ts +16 -13
  70. package/src/schema/keyOf.ts +167 -0
  71. package/src/schema/record.ts +103 -0
  72. package/src/schema/union.ts +1 -1
  73. package/src/schema/validation.test.ts +195 -130
  74. package/src/selector/SelectorProxy.ts +15 -15
  75. package/src/selector/array.ts +2 -26
  76. package/src/selector/file.ts +1 -9
  77. package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
  78. package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
  79. package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
  80. package/src/selector/future/SelectorProxy.ts +238 -0
  81. package/src/selector/future/array.ts +37 -0
  82. package/src/selector/future/boolean.ts +4 -0
  83. package/src/selector/future/file.ts +14 -0
  84. package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
  85. package/src/selector/future/index.ts +165 -0
  86. package/src/selector/future/number.ts +4 -0
  87. package/src/selector/future/object.ts +22 -0
  88. package/src/selector/future/primitive.ts +17 -0
  89. package/src/selector/{remote.ts → future/remote.ts} +1 -1
  90. package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
  91. package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
  92. package/src/selector/future/string.ts +4 -0
  93. package/src/selector/index.ts +4 -46
  94. package/src/selector/object.ts +2 -19
  95. package/src/selector/primitive.ts +3 -16
  96. package/src/source/{i18n.ts → future/i18n.ts} +2 -2
  97. package/src/source/{remote.ts → future/remote.ts} +3 -3
  98. package/src/source/index.ts +3 -2
  99. package/src/val/array.ts +1 -1
  100. package/src/val/index.ts +2 -2
  101. package/src/val/object.ts +1 -1
  102. package/dist/declarations/src/fetchVal.d.ts +0 -5
  103. package/dist/declarations/src/schema/i18n.d.ts +0 -22
  104. package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -0,0 +1,10 @@
1
+ import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from "./index.js";
2
+ import { SourceObject } from "../../source/index.js";
3
+ export type Selector<T extends SourceObject> = GenericSelector<T> & {
4
+ fold<Tag extends string>(key: Tag): <U extends SelectorSource>(cases: {
5
+ [key in T[Tag & keyof T] & string]: (v: UnknownSelector<T>) => U;
6
+ }) => SelectorOf<U>;
7
+ andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<T>>) => U): SelectorOf<U>;
8
+ } & {
9
+ readonly [key in keyof T]: UnknownSelector<T[key]>;
10
+ };
@@ -0,0 +1,9 @@
1
+ import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from "./index.js";
2
+ import { Source, SourcePrimitive } from "../../source/index.js";
3
+ import { Selector as BooleanSelector } from "./boolean.js";
4
+ export type Selector<T extends SourcePrimitive> = GenericSelector<T> & {
5
+ eq(other: Source): BooleanSelector<boolean>;
6
+ andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<T>>) => U): SelectorOf<U | NullableOf<T>>;
7
+ };
8
+ type NullableOf<T extends Source> = T extends null ? null : never;
9
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { Selector as UnknownSelector } from "./index.js";
2
- import { RemoteCompatibleSource } from "../source/remote.js";
2
+ import { RemoteCompatibleSource } from "../../source/future/remote.js";
3
3
  declare const brand: unique symbol;
4
4
  export type RemoteSelector<T extends RemoteCompatibleSource> = UnknownSelector<T> & {
5
5
  readonly [brand]: "RemoteSelector";
@@ -0,0 +1,2 @@
1
+ import { Selector as PrimitiveSelector } from "./primitive.js";
2
+ export type Selector<T extends string> = PrimitiveSelector<T>;
@@ -1,4 +1,3 @@
1
- import { I18nSelector } from "./i18n.js";
2
1
  import { Selector as ObjectSelector } from "./object.js";
3
2
  import { UndistributedSourceArray as ArraySelector } from "./array.js";
4
3
  import { Selector as NumberSelector } from "./number.js";
@@ -9,38 +8,13 @@ import { FileSelector } from "./file.js";
9
8
  import { SourcePath } from "../val/index.js";
10
9
  import { Source, SourceArray, SourceObject, SourcePrimitive } from "../source/index.js";
11
10
  import { Schema } from "../schema/index.js";
12
- import { Expr } from "../expr/expr.js";
13
- import { RemoteSelector } from "./remote.js";
14
- import { A } from "ts-toolbelt";
15
- import { I18nSource, I18nCompatibleSource } from "../source/i18n.js";
16
- import { RemoteCompatibleSource, RemoteSource } from "../source/remote.js";
11
+ import type { A } from "ts-toolbelt";
17
12
  import { FileSource } from "../source/file.js";
18
13
  import { RichText, RichTextSource } from "../source/richtext.js";
19
- /**
20
- * Selectors can be used to select parts of a Val module.
21
- * Unlike queries, joins, aggregates etc is and will not be supported.
22
- *
23
- * They are designed to be be used as if they were "normal" JSON data,
24
- * though some concessions had to be made because of TypeScript limitations.
25
- *
26
- * Selectors works equally on source content, defined in code, and remote content.
27
- *
28
- * @example
29
- * // Select the title of a document
30
- * const titles = useVal(docsVal.map((doc) => doc.title));
31
- *
32
- * @example
33
- * // Match on a union type
34
- * const titles = useVal(docsVal.map((doc) => doc.fold("type")({
35
- * newsletter: (newsletter) => newsletter.title,
36
- * email: (email) => email.subject,
37
- * }));
38
- *
39
- */
40
- export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends I18nSource<infer L, infer S> ? I18nSelector<L, S> : T extends RemoteSource<infer S> ? S extends RemoteCompatibleSource ? RemoteSelector<S> : GenericSelector<Source, "Could not determine remote source"> : T extends FileSource ? FileSelector : T extends RichTextSource ? RichText : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
14
+ export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource ? FileSelector : T extends RichTextSource ? RichText : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
41
15
  export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
42
16
  [key: string]: SelectorSource;
43
- } | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource | GenericSelector<Source>;
17
+ } | FileSource | RichTextSource | GenericSelector<Source>;
44
18
  /**
45
19
  * @internal
46
20
  */
@@ -53,18 +27,17 @@ export declare const Path: unique symbol;
53
27
  /**
54
28
  * @internal
55
29
  */
56
- export declare const SourceOrExpr: unique symbol;
30
+ export declare const GetSource: unique symbol;
57
31
  /**
58
32
  * @internal
59
33
  */
60
34
  export declare const ValError: unique symbol;
61
35
  export declare abstract class GenericSelector<out T extends Source, Error extends string | undefined = undefined> {
62
36
  readonly [Path]: SourcePath | undefined;
63
- readonly [SourceOrExpr]: T | Expr;
37
+ readonly [GetSource]: T;
64
38
  readonly [ValError]: Error | undefined;
65
39
  readonly [GetSchema]: Schema<T> | undefined;
66
40
  constructor(valOrExpr: T, path: SourcePath | undefined, schema?: Schema<T>, error?: Error);
67
- assert<U extends Source, E extends Source = null>(schema: Schema<U>, other?: () => E): SelectorOf<U | E>;
68
41
  }
69
42
  export type SourceOf<T extends SelectorSource> = Source extends T ? Source : T extends Source ? T : T extends undefined ? null : T extends GenericSelector<infer S> ? S : T extends readonly (infer S)[] ? S extends SelectorSource ? {
70
43
  [key in keyof T]: SourceOf<A.Try<T[key], SelectorSource>>;
@@ -1,10 +1,3 @@
1
- import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from "./index.js";
1
+ import { GenericSelector } from "./index.js";
2
2
  import { SourceObject } from "../source/index.js";
3
- export type Selector<T extends SourceObject> = GenericSelector<T> & {
4
- fold<Tag extends string>(key: Tag): <U extends SelectorSource>(cases: {
5
- [key in T[Tag & keyof T] & string]: (v: UnknownSelector<T>) => U;
6
- }) => SelectorOf<U>;
7
- andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<T>>) => U): SelectorOf<U>;
8
- } & {
9
- readonly [key in keyof T]: UnknownSelector<T[key]>;
10
- };
3
+ export type Selector<T extends SourceObject> = GenericSelector<T>;
@@ -1,9 +1,3 @@
1
- import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from "./index.js";
2
- import { Source, SourcePrimitive } from "../source/index.js";
3
- import { Selector as BooleanSelector } from "./boolean.js";
4
- export type Selector<T extends SourcePrimitive> = GenericSelector<T> & {
5
- eq(other: Source): BooleanSelector<boolean>;
6
- andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<T>>) => U): SelectorOf<U | NullableOf<T>>;
7
- };
8
- type NullableOf<T extends Source> = T extends null ? null : never;
9
- export {};
1
+ import { GenericSelector } from "./index.js";
2
+ import { SourcePrimitive } from "../source/index.js";
3
+ export type Selector<T extends SourcePrimitive> = GenericSelector<T>;
@@ -1,6 +1,6 @@
1
1
  import { F } from "ts-toolbelt";
2
- import { SourcePrimitive, VAL_EXTENSION } from "./index.js";
3
- import { FileSource } from "./file.js";
2
+ import { SourcePrimitive, VAL_EXTENSION } from "../index.js";
3
+ import { FileSource } from "../file.js";
4
4
  /**
5
5
  * I18n sources cannot have nested remote sources.
6
6
  */
@@ -1,7 +1,7 @@
1
- import { SourcePrimitive, VAL_EXTENSION, PhantomType } from "./index.js";
2
- import { FileSource } from "./file.js";
1
+ import { SourcePrimitive, VAL_EXTENSION, PhantomType } from "../index.js";
2
+ import { FileSource } from "../file.js";
3
3
  import { I18nCompatibleSource, I18nSource } from "./i18n.js";
4
- import { RichTextSource } from "./richtext.js";
4
+ import { RichTextSource } from "../richtext.js";
5
5
  /**
6
6
  * Remote sources cannot include other remote sources.
7
7
  */
@@ -1,12 +1,13 @@
1
1
  import { FileSource } from "./file.js";
2
- import { I18nSource, I18nCompatibleSource } from "./i18n.js";
3
- import { RemoteSource, RemoteCompatibleSource } from "./remote.js";
2
+ import { I18nSource, I18nCompatibleSource } from "./future/i18n.js";
3
+ import { RemoteSource, RemoteCompatibleSource } from "./future/remote.js";
4
4
  import { RichTextSource } from "./richtext.js";
5
5
  export type Source = SourcePrimitive | SourceObject | SourceArray | I18nSource<string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource;
6
6
  export type SourceObject = {
7
7
  [key in string]: Source;
8
8
  } & {
9
9
  fold?: never;
10
+ assert?: never;
10
11
  andThen?: never;
11
12
  _ref?: never;
12
13
  _type?: never;
@@ -16,7 +17,7 @@ export type SourceObject = {
16
17
  export type SourceArray = readonly Source[];
17
18
  export type SourcePrimitive = string | number | boolean | null;
18
19
  export declare const VAL_EXTENSION: "_type";
19
- export declare function getValExtension(source: Source): false | "" | 0 | "richtext" | "file" | "i18n" | "remote" | null | undefined;
20
+ export declare function getValExtension(source: Source): false | "" | 0 | "richtext" | "remote" | "file" | "i18n" | null | undefined;
20
21
  /**
21
22
  * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
22
23
  *
@@ -4,8 +4,8 @@ import { Val as ArrayVal } from "./array.js";
4
4
  import { Val as PrimitiveVal } from "./primitive.js";
5
5
  import { Json, JsonArray, JsonObject, JsonPrimitive } from "../Json.js";
6
6
  import { Path, Selector } from "../selector/index.js";
7
- import { I18nSource } from "../source/i18n.js";
8
- import { RemoteSource } from "../source/remote.js";
7
+ import { I18nSource } from "../source/future/i18n.js";
8
+ import { RemoteSource } from "../source/future/remote.js";
9
9
  import { FileSource } from "../source/file.js";
10
10
  export type SerializedVal = {
11
11
  val: SerializedVal | Json;