@valbuild/core 0.15.0 → 0.17.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 +38 -9
- package/dist/declarations/src/initSchema.d.ts +2 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/patch/index.d.ts +1 -1
- package/dist/declarations/src/patch/util.d.ts +2 -0
- package/dist/declarations/src/schema/array.d.ts +3 -2
- package/dist/declarations/src/schema/boolean.d.ts +3 -2
- package/dist/declarations/src/schema/image.d.ts +4 -3
- package/dist/declarations/src/schema/index.d.ts +8 -7
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/literal.d.ts +3 -2
- package/dist/declarations/src/schema/number.d.ts +3 -2
- package/dist/declarations/src/schema/object.d.ts +3 -2
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/richtext.d.ts +3 -2
- package/dist/declarations/src/schema/string.d.ts +3 -2
- package/dist/declarations/src/schema/union.d.ts +4 -2
- package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -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-369caccf.esm.js +550 -0
- package/dist/{index-06df0a5b.esm.js → index-3e3e839e.esm.js} +190 -555
- package/dist/{index-9663f28a.cjs.dev.js → index-486c7fbf.cjs.dev.js} +224 -617
- package/dist/{index-b2270f8f.cjs.prod.js → index-601a7d73.cjs.prod.js} +224 -617
- package/dist/index-8706c87e.cjs.prod.js +582 -0
- package/dist/index-a6e642dd.cjs.dev.js +582 -0
- package/dist/ops-0d09f8ee.cjs.prod.js +684 -0
- package/dist/ops-23a5abb2.esm.js +671 -0
- package/dist/ops-f3015423.cjs.dev.js +684 -0
- package/dist/valbuild-core.cjs.dev.js +640 -633
- package/dist/valbuild-core.cjs.prod.js +640 -633
- package/dist/valbuild-core.esm.js +578 -572
- 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 -2
- package/patch/dist/valbuild-core-patch.cjs.dev.js +32 -23
- package/patch/dist/valbuild-core-patch.cjs.prod.js +32 -23
- package/patch/dist/valbuild-core-patch.esm.js +12 -4
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/expr/repl.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 +51 -14
- package/src/initSchema.ts +11 -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/index.ts +1 -0
- package/src/patch/json.test.ts +0 -1
- package/src/patch/util.ts +7 -0
- package/src/schema/array.ts +45 -4
- package/src/schema/boolean.ts +14 -3
- package/src/schema/{i18n.ts → future/i18n.ts} +15 -11
- package/src/schema/{oneOf.ts → future/oneOf.ts} +21 -18
- package/src/schema/image.ts +66 -6
- package/src/schema/index.ts +37 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/literal.ts +24 -3
- package/src/schema/number.ts +14 -3
- package/src/schema/object.ts +50 -7
- package/src/schema/record.ts +103 -0
- package/src/schema/richtext.ts +63 -3
- package/src/schema/string.ts +14 -3
- package/src/schema/union.ts +4 -3
- package/src/schema/validation/ValidationError.ts +16 -0
- package/src/schema/validation/ValidationFix.ts +6 -0
- package/src/schema/validation.test.ts +291 -0
- package/src/selector/SelectorProxy.ts +16 -16
- 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/createClass-012eebbf.esm.js +0 -109
- package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
- package/dist/createClass-de7426aa.cjs.prod.js +0 -116
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -21
- package/dist/declarations/src/schema/oneOf.d.ts +0 -22
- package/dist/ops-6fae92a1.esm.js +0 -12
- package/dist/ops-87cdbafc.cjs.dev.js +0 -14
- package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -0,0 +1,14 @@
|
|
1
|
+
import { SourcePath } from "../../val/index.js";
|
2
|
+
import { ValidationFix } from "./ValidationFix.js";
|
3
|
+
export type ValidationError = {
|
4
|
+
message: string;
|
5
|
+
value?: unknown;
|
6
|
+
fixes?: ValidationFix[];
|
7
|
+
};
|
8
|
+
/**
|
9
|
+
* Equals `false` if no validation errors were found.
|
10
|
+
* Errors are indexed by the full source path.
|
11
|
+
*
|
12
|
+
* Global errors have the path `"/"`.
|
13
|
+
*/
|
14
|
+
export type ValidationErrors = false | Record<SourcePath, ValidationError[]>;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { GenericSelector } from "./index.js";
|
2
|
+
import { Source } from "../source/index.js";
|
3
|
+
import { SourcePath } from "../val/index.js";
|
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;
|
@@ -1,17 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { Schema } from "../schema/index.js";
|
1
|
+
import { GenericSelector } from "./index.js";
|
3
2
|
import { Source, SourceArray } from "../source/index.js";
|
4
|
-
import { Selector as BooleanSelector } from "./boolean.js";
|
5
|
-
import { Selector as NumberSelector } from "./number.js";
|
6
3
|
export type UndistributedSourceArray<T extends SourceArray> = [T] extends [
|
7
4
|
infer U
|
8
5
|
] ? U extends Source[] ? Selector<U> : never : never;
|
9
|
-
export type Selector<T extends SourceArray> = GenericSelector<T
|
10
|
-
readonly [key: number]: UnknownSelector<T[number]>;
|
11
|
-
} & {
|
12
|
-
length: NumberSelector<number>;
|
13
|
-
filter(predicate: (v: UnknownSelector<T[number]>) => BooleanSelector<boolean> | boolean): Selector<T>;
|
14
|
-
filter<U extends Source>(schema: Schema<U>): Selector<U[]>;
|
15
|
-
map<U extends SelectorSource>(f: (v: UnknownSelector<T[number]>, i: UnknownSelector<number>) => U): SelectorOf<U[]>;
|
16
|
-
andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<T>>) => U): SelectorOf<U | T>;
|
17
|
-
};
|
6
|
+
export type Selector<T extends SourceArray> = GenericSelector<T>;
|
@@ -1,9 +1,6 @@
|
|
1
|
-
import { Selector as UnknownSelector, GenericSelector
|
1
|
+
import { Selector as UnknownSelector, GenericSelector } from "./index.js";
|
2
2
|
export type FileSelector = GenericSelector<{
|
3
3
|
url: string;
|
4
4
|
}> & {
|
5
5
|
readonly url: UnknownSelector<string>;
|
6
|
-
andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<{
|
7
|
-
url: string;
|
8
|
-
}>>) => U): SelectorOf<U> | UnknownSelector<boolean>;
|
9
6
|
};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from "./index.js";
|
2
|
+
import { Schema } from "../../schema/index.js";
|
3
|
+
import { Source, SourceArray } from "../../source/index.js";
|
4
|
+
import { Selector as BooleanSelector } from "./boolean.js";
|
5
|
+
import { Selector as NumberSelector } from "./number.js";
|
6
|
+
export type UndistributedSourceArray<T extends SourceArray> = [T] extends [
|
7
|
+
infer U
|
8
|
+
] ? U extends Source[] ? Selector<U> : never : never;
|
9
|
+
export type Selector<T extends SourceArray> = GenericSelector<T> & {
|
10
|
+
readonly [key: number]: UnknownSelector<T[number]>;
|
11
|
+
} & {
|
12
|
+
length: NumberSelector<number>;
|
13
|
+
filter(predicate: (v: UnknownSelector<T[number]>) => BooleanSelector<boolean> | boolean): Selector<T>;
|
14
|
+
filter<U extends Source>(schema: Schema<U>): Selector<U[]>;
|
15
|
+
map<U extends SelectorSource>(f: (v: UnknownSelector<T[number]>, i: UnknownSelector<number>) => U): SelectorOf<U[]>;
|
16
|
+
andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<T>>) => U): SelectorOf<U | T>;
|
17
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from "./index.js";
|
2
|
+
export type FileSelector = GenericSelector<{
|
3
|
+
url: string;
|
4
|
+
}> & {
|
5
|
+
readonly url: UnknownSelector<string>;
|
6
|
+
andThen<U extends SelectorSource>(f: (v: UnknownSelector<NonNullable<{
|
7
|
+
url: string;
|
8
|
+
}>>) => U): SelectorOf<U> | UnknownSelector<boolean>;
|
9
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { SourceArray, SourceObject, SourcePrimitive } from "
|
1
|
+
import { SourceArray, SourceObject, SourcePrimitive } from "../../source/index.js";
|
2
2
|
import { Selector as UnknownSelector } from "./index.js";
|
3
|
-
import { FileSource } from "
|
3
|
+
import { FileSource } from "../../source/file.js";
|
4
4
|
declare const brand: unique symbol;
|
5
5
|
export type I18nSelector<Locales extends readonly string[], T extends SourcePrimitive | SourceObject | SourceArray | FileSource> = UnknownSelector<T> & {
|
6
6
|
readonly [brand]: "I18nSelector";
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import { I18nSelector } from "./i18n.js";
|
2
|
+
import { Selector as ObjectSelector } from "./object.js";
|
3
|
+
import { UndistributedSourceArray as ArraySelector } from "./array.js";
|
4
|
+
import { Selector as NumberSelector } from "./number.js";
|
5
|
+
import { Selector as StringSelector } from "./string.js";
|
6
|
+
import { Selector as BooleanSelector } from "./boolean.js";
|
7
|
+
import { Selector as PrimitiveSelector } from "./primitive.js";
|
8
|
+
import { FileSelector } from "./file.js";
|
9
|
+
import { SourcePath } from "../../val/index.js";
|
10
|
+
import { Source, SourceArray, SourceObject, SourcePrimitive } from "../../source/index.js";
|
11
|
+
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/future/i18n.js";
|
16
|
+
import { RemoteCompatibleSource, RemoteSource } from "../../source/future/remote.js";
|
17
|
+
import { FileSource } from "../../source/file.js";
|
18
|
+
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;
|
41
|
+
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
42
|
+
[key: string]: SelectorSource;
|
43
|
+
} | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource | GenericSelector<Source>;
|
44
|
+
/**
|
45
|
+
* @internal
|
46
|
+
*/
|
47
|
+
export declare const GetSchema: unique symbol;
|
48
|
+
/**
|
49
|
+
/**
|
50
|
+
* @internal
|
51
|
+
*/
|
52
|
+
export declare const Path: unique symbol;
|
53
|
+
/**
|
54
|
+
* @internal
|
55
|
+
*/
|
56
|
+
export declare const SourceOrExpr: unique symbol;
|
57
|
+
/**
|
58
|
+
* @internal
|
59
|
+
*/
|
60
|
+
export declare const ValError: unique symbol;
|
61
|
+
export declare abstract class GenericSelector<out T extends Source, Error extends string | undefined = undefined> {
|
62
|
+
readonly [Path]: SourcePath | undefined;
|
63
|
+
readonly [SourceOrExpr]: T | Expr;
|
64
|
+
readonly [ValError]: Error | undefined;
|
65
|
+
readonly [GetSchema]: Schema<T> | undefined;
|
66
|
+
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
|
+
}
|
69
|
+
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
|
+
[key in keyof T]: SourceOf<A.Try<T[key], SelectorSource>>;
|
71
|
+
} : never : T extends {
|
72
|
+
[key: string]: SelectorSource;
|
73
|
+
} ? {
|
74
|
+
[key in keyof T]: SourceOf<A.Try<T[key], SelectorSource>>;
|
75
|
+
} : never;
|
76
|
+
/**
|
77
|
+
* Use this type to convert types that accepts both Source and Selectors
|
78
|
+
*
|
79
|
+
* An example would be where literals are supported like in most higher order functions (e.g. map in array)
|
80
|
+
**/
|
81
|
+
export type SelectorOf<U extends SelectorSource> = Source extends U ? GenericSelector<Source> : SourceOf<U> extends infer S ? S extends Source ? Selector<S> : GenericSelector<Source, "Could not determine selector of source"> : GenericSelector<Source, "Could not determine source">;
|
@@ -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;
|