@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
@@ -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 "
|
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";
|
@@ -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 {
|
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
|
-
} |
|
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
|
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 [
|
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 {
|
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 {
|
2
|
-
import {
|
3
|
-
|
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 "
|
3
|
-
import { FileSource } from "
|
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 "
|
2
|
-
import { FileSource } from "
|
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 "
|
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" | "
|
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;
|