@valbuild/core 0.12.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/CHANGELOG.md +0 -0
- package/README.md +537 -0
- package/dist/createClass-012eebbf.esm.js +109 -0
- package/dist/createClass-a436dbfe.cjs.dev.js +116 -0
- package/dist/createClass-de7426aa.cjs.prod.js +116 -0
- package/dist/declarations/src/Json.d.ts +6 -0
- package/dist/declarations/src/expr/eval.d.ts +19 -0
- package/dist/declarations/src/expr/expr.d.ts +32 -0
- package/dist/declarations/src/expr/index.d.ts +3 -0
- package/dist/declarations/src/expr/parser.d.ts +8 -0
- package/dist/declarations/src/expr/tokenizer.d.ts +7 -0
- package/dist/declarations/src/fetchVal.d.ts +5 -0
- package/dist/declarations/src/fp/array.d.ts +8 -0
- package/dist/declarations/src/fp/index.d.ts +3 -0
- package/dist/declarations/src/fp/result.d.ts +67 -0
- package/dist/declarations/src/fp/util.d.ts +12 -0
- package/dist/declarations/src/index.d.ts +32 -0
- package/dist/declarations/src/initSchema.d.ts +57 -0
- package/dist/declarations/src/initVal.d.ts +39 -0
- package/dist/declarations/src/module.d.ts +38 -0
- package/dist/declarations/src/patch/deref.d.ts +13 -0
- package/dist/declarations/src/patch/index.d.ts +6 -0
- package/dist/declarations/src/patch/json.d.ts +11 -0
- package/dist/declarations/src/patch/operation.d.ts +59 -0
- package/dist/declarations/src/patch/ops.d.ts +40 -0
- package/dist/declarations/src/patch/parse.d.ts +19 -0
- package/dist/declarations/src/patch/patch.d.ts +6 -0
- package/dist/declarations/src/patch/util.d.ts +6 -0
- package/dist/declarations/src/schema/array.d.ts +18 -0
- package/dist/declarations/src/schema/boolean.d.ts +15 -0
- package/dist/declarations/src/schema/i18n.d.ts +21 -0
- package/dist/declarations/src/schema/image.d.ts +32 -0
- package/dist/declarations/src/schema/index.d.ts +23 -0
- package/dist/declarations/src/schema/literal.d.ts +17 -0
- package/dist/declarations/src/schema/number.d.ts +22 -0
- package/dist/declarations/src/schema/object.d.ts +25 -0
- package/dist/declarations/src/schema/oneOf.d.ts +22 -0
- package/dist/declarations/src/schema/richtext.d.ts +76 -0
- package/dist/declarations/src/schema/string.d.ts +22 -0
- package/dist/declarations/src/schema/union.d.ts +36 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +17 -0
- package/dist/declarations/src/selector/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/file.d.ts +9 -0
- package/dist/declarations/src/selector/i18n.d.ts +11 -0
- package/dist/declarations/src/selector/index.d.ts +81 -0
- package/dist/declarations/src/selector/number.d.ts +2 -0
- package/dist/declarations/src/selector/object.d.ts +10 -0
- package/dist/declarations/src/selector/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/remote.d.ts +7 -0
- package/dist/declarations/src/selector/string.d.ts +2 -0
- package/dist/declarations/src/source/file.d.ts +23 -0
- package/dist/declarations/src/source/i18n.d.ts +29 -0
- package/dist/declarations/src/source/index.d.ts +33 -0
- package/dist/declarations/src/source/remote.d.ts +29 -0
- package/dist/declarations/src/val/array.d.ts +9 -0
- package/dist/declarations/src/val/index.d.ts +53 -0
- package/dist/declarations/src/val/object.d.ts +9 -0
- package/dist/declarations/src/val/primitive.d.ts +7 -0
- package/dist/index-2f1631cf.cjs.prod.js +1031 -0
- package/dist/index-55916dcd.esm.js +1000 -0
- package/dist/index-b49a2c60.cjs.dev.js +1031 -0
- package/dist/ops-6fae92a1.esm.js +12 -0
- package/dist/ops-87cdbafc.cjs.dev.js +14 -0
- package/dist/ops-ae4d1bc2.cjs.prod.js +14 -0
- package/dist/result-26f67b40.cjs.prod.js +299 -0
- package/dist/result-48320acd.cjs.dev.js +299 -0
- package/dist/result-b96df128.esm.js +279 -0
- package/dist/util-030d8a1f.cjs.prod.js +29 -0
- package/dist/util-18613e99.esm.js +26 -0
- package/dist/util-b213092b.cjs.dev.js +29 -0
- package/dist/valbuild-core.cjs.d.ts +2 -0
- package/dist/valbuild-core.cjs.d.ts.map +1 -0
- package/dist/valbuild-core.cjs.dev.js +1276 -0
- package/dist/valbuild-core.cjs.js +7 -0
- package/dist/valbuild-core.cjs.prod.js +1276 -0
- package/dist/valbuild-core.esm.js +1265 -0
- package/expr/dist/valbuild-core-expr.cjs.d.ts +2 -0
- package/expr/dist/valbuild-core-expr.cjs.d.ts.map +1 -0
- package/expr/dist/valbuild-core-expr.cjs.dev.js +18 -0
- package/expr/dist/valbuild-core-expr.cjs.js +7 -0
- package/expr/dist/valbuild-core-expr.cjs.prod.js +18 -0
- package/expr/dist/valbuild-core-expr.esm.js +3 -0
- package/expr/package.json +4 -0
- package/fp/dist/valbuild-core-fp.cjs.d.ts +2 -0
- package/fp/dist/valbuild-core-fp.cjs.d.ts.map +1 -0
- package/fp/dist/valbuild-core-fp.cjs.dev.js +13 -0
- package/fp/dist/valbuild-core-fp.cjs.js +7 -0
- package/fp/dist/valbuild-core-fp.cjs.prod.js +13 -0
- package/fp/dist/valbuild-core-fp.esm.js +2 -0
- package/fp/package.json +4 -0
- package/package.json +43 -0
- package/patch/dist/valbuild-core-patch.cjs.d.ts +2 -0
- package/patch/dist/valbuild-core-patch.cjs.d.ts.map +1 -0
- package/patch/dist/valbuild-core-patch.cjs.dev.js +443 -0
- package/patch/dist/valbuild-core-patch.cjs.js +7 -0
- package/patch/dist/valbuild-core-patch.cjs.prod.js +443 -0
- package/patch/dist/valbuild-core-patch.esm.js +431 -0
- package/patch/package.json +4 -0
- package/tsconfig.json +7 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
import { array } from "../fp";
|
2
|
+
import type { JSONValue } from "./ops";
|
3
|
+
/**
|
4
|
+
* Raw JSON patch operation.
|
5
|
+
*/
|
6
|
+
export type OperationJSON = {
|
7
|
+
op: "add";
|
8
|
+
path: string;
|
9
|
+
value: JSONValue;
|
10
|
+
} | {
|
11
|
+
op: "remove";
|
12
|
+
path: string;
|
13
|
+
} | {
|
14
|
+
op: "replace";
|
15
|
+
path: string;
|
16
|
+
value: JSONValue;
|
17
|
+
} | {
|
18
|
+
op: "move";
|
19
|
+
from: string;
|
20
|
+
path: string;
|
21
|
+
} | {
|
22
|
+
op: "copy";
|
23
|
+
from: string;
|
24
|
+
path: string;
|
25
|
+
} | {
|
26
|
+
op: "test";
|
27
|
+
path: string;
|
28
|
+
value: JSONValue;
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* Parsed form of JSON patch operation.
|
32
|
+
*/
|
33
|
+
export type Operation = {
|
34
|
+
op: "add";
|
35
|
+
path: string[];
|
36
|
+
value: JSONValue;
|
37
|
+
} | {
|
38
|
+
op: "remove";
|
39
|
+
path: array.NonEmptyArray<string>;
|
40
|
+
} | {
|
41
|
+
op: "replace";
|
42
|
+
path: string[];
|
43
|
+
value: JSONValue;
|
44
|
+
} | {
|
45
|
+
op: "move";
|
46
|
+
/**
|
47
|
+
* Must be non-root and not a proper prefix of "path".
|
48
|
+
*/
|
49
|
+
from: array.NonEmptyArray<string>;
|
50
|
+
path: string[];
|
51
|
+
} | {
|
52
|
+
op: "copy";
|
53
|
+
from: string[];
|
54
|
+
path: string[];
|
55
|
+
} | {
|
56
|
+
op: "test";
|
57
|
+
path: string[];
|
58
|
+
value: JSONValue;
|
59
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { result, array } from "../fp";
|
2
|
+
export declare class PatchError {
|
3
|
+
message: string;
|
4
|
+
constructor(message: string);
|
5
|
+
}
|
6
|
+
export type ReadonlyJSONValue = string | number | boolean | null | readonly ReadonlyJSONValue[] | {
|
7
|
+
readonly [key: string]: ReadonlyJSONValue;
|
8
|
+
};
|
9
|
+
export type JSONValue = string | number | boolean | null | JSONValue[] | {
|
10
|
+
[key: string]: JSONValue;
|
11
|
+
};
|
12
|
+
type ToMutableJSONArray<T extends readonly ReadonlyJSONValue[]> = {
|
13
|
+
[P in keyof T]: ToMutable<T[P]>;
|
14
|
+
};
|
15
|
+
export type ToMutable<T extends ReadonlyJSONValue> = JSONValue extends T ? JSONValue : T extends readonly ReadonlyJSONValue[] ? ToMutableJSONArray<T> : T extends {
|
16
|
+
readonly [key: string]: ReadonlyJSONValue;
|
17
|
+
} ? {
|
18
|
+
-readonly [P in keyof T]: ToMutable<T[P]>;
|
19
|
+
} : T;
|
20
|
+
type ToReadonlyJSONArray<T extends readonly ReadonlyJSONValue[]> = {
|
21
|
+
readonly [P in keyof T]: ToReadonly<T[P]>;
|
22
|
+
};
|
23
|
+
export type ToReadonly<T extends ReadonlyJSONValue> = JSONValue extends T ? ReadonlyJSONValue : T extends readonly ReadonlyJSONValue[] ? ToReadonlyJSONArray<T> : T extends {
|
24
|
+
readonly [key: string]: ReadonlyJSONValue;
|
25
|
+
} ? {
|
26
|
+
readonly [P in keyof T]: ToReadonly<T[P]>;
|
27
|
+
} : T;
|
28
|
+
/**
|
29
|
+
* NOTE: MAY mutate the input document.
|
30
|
+
*/
|
31
|
+
export interface Ops<T, E> {
|
32
|
+
add(document: T, path: string[], value: JSONValue): result.Result<T, E | PatchError>;
|
33
|
+
remove(document: T, path: array.NonEmptyArray<string>): result.Result<T, E | PatchError>;
|
34
|
+
replace(document: T, path: string[], value: JSONValue): result.Result<T, E | PatchError>;
|
35
|
+
move(document: T, from: array.NonEmptyArray<string>, path: string[]): result.Result<T, E | PatchError>;
|
36
|
+
copy(document: T, from: string[], path: string[]): result.Result<T, E | PatchError>;
|
37
|
+
test(document: T, path: string[], value: JSONValue): result.Result<boolean, E | PatchError>;
|
38
|
+
get(document: T, path: string[]): result.Result<JSONValue, E | PatchError>;
|
39
|
+
}
|
40
|
+
export {};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { array, result } from "../fp";
|
2
|
+
import { Operation, OperationJSON } from "./operation";
|
3
|
+
import { Patch, PatchJSON } from "./patch";
|
4
|
+
export declare function parseJSONPointer(pointer: string): result.Result<string[], string>;
|
5
|
+
export declare function formatJSONPointerReferenceToken(key: string): string;
|
6
|
+
export declare function formatJSONPointer(path: string[]): string;
|
7
|
+
/**
|
8
|
+
* A signifies an issue that makes a PatchJSON or an OperationJSON invalid.
|
9
|
+
* Unlike PatchError, a StaticPatchIssue indicates an issue with the patch
|
10
|
+
* document itself; it is independent of any document which the patch or
|
11
|
+
* might be applied to.
|
12
|
+
*/
|
13
|
+
export type StaticPatchIssue = {
|
14
|
+
path: string[];
|
15
|
+
message: string;
|
16
|
+
};
|
17
|
+
export declare function prefixIssuePath(prefix: string, { path, message }: StaticPatchIssue): StaticPatchIssue;
|
18
|
+
export declare function parseOperation(operation: OperationJSON): result.Result<Operation, array.NonEmptyArray<StaticPatchIssue>>;
|
19
|
+
export declare function parsePatch(patch: PatchJSON): result.Result<Patch, array.NonEmptyArray<StaticPatchIssue>>;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { result } from "../fp";
|
2
|
+
import { Ops, PatchError } from "./ops";
|
3
|
+
import { Operation, OperationJSON } from "./operation";
|
4
|
+
export type Patch = Operation[];
|
5
|
+
export type PatchJSON = OperationJSON[];
|
6
|
+
export declare function applyPatch<T, E>(document: T, ops: Ops<T, E>, patch: Operation[]): result.Result<T, E | PatchError>;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { array, result } from "../fp";
|
2
|
+
import { PatchError, ReadonlyJSONValue, ToMutable } from "./ops";
|
3
|
+
export declare function isNotRoot(path: string[]): path is array.NonEmptyArray<string>;
|
4
|
+
export declare function deepEqual(a: ReadonlyJSONValue, b: ReadonlyJSONValue): boolean;
|
5
|
+
export declare function deepClone<T extends ReadonlyJSONValue>(value: T): ToMutable<T>;
|
6
|
+
export declare function parseAndValidateArrayIndex(value: string): result.Result<number, PatchError>;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Schema, SchemaTypeOf, SerializedSchema } from ".";
|
2
|
+
import { SelectorSource } from "../selector";
|
3
|
+
import { SourcePath } from "../val";
|
4
|
+
export type SerializedArraySchema = {
|
5
|
+
type: "array";
|
6
|
+
item: SerializedSchema;
|
7
|
+
opt: boolean;
|
8
|
+
};
|
9
|
+
export declare class ArraySchema<T extends Schema<SelectorSource>> extends Schema<SchemaTypeOf<T>[]> {
|
10
|
+
readonly item: T;
|
11
|
+
readonly opt: boolean;
|
12
|
+
constructor(item: T, opt?: boolean);
|
13
|
+
validate(src: SchemaTypeOf<T>[]): false | Record<SourcePath, string[]>;
|
14
|
+
match(src: SchemaTypeOf<T>[]): boolean;
|
15
|
+
optional(): Schema<SchemaTypeOf<T>[] | null>;
|
16
|
+
serialize(): SerializedArraySchema;
|
17
|
+
}
|
18
|
+
export declare const array: <S extends Schema<SelectorSource>>(schema: S) => Schema<SchemaTypeOf<S>[]>;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { SourcePath } from "../val";
|
3
|
+
export type SerializedBooleanSchema = {
|
4
|
+
type: "boolean";
|
5
|
+
opt: boolean;
|
6
|
+
};
|
7
|
+
export declare class BooleanSchema<Src extends boolean | null> extends Schema<Src> {
|
8
|
+
readonly opt: boolean;
|
9
|
+
constructor(opt?: boolean);
|
10
|
+
validate(src: Src): false | Record<SourcePath, string[]>;
|
11
|
+
match(src: Src): boolean;
|
12
|
+
optional(): Schema<Src | null>;
|
13
|
+
serialize(): SerializedSchema;
|
14
|
+
}
|
15
|
+
export declare const boolean: () => Schema<boolean>;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Schema, SchemaTypeOf, SerializedSchema } from ".";
|
2
|
+
import { I18nCompatibleSource, I18nSource } from "../source/i18n";
|
3
|
+
import { SourcePath } from "../val";
|
4
|
+
export type SerializedI18nSchema = {
|
5
|
+
type: "i18n";
|
6
|
+
locales: readonly string[];
|
7
|
+
item: SerializedSchema;
|
8
|
+
opt: boolean;
|
9
|
+
};
|
10
|
+
export declare class I18nSchema<Locales extends readonly string[]> extends Schema<I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>> {
|
11
|
+
readonly locales: Locales;
|
12
|
+
readonly item: Schema<SchemaTypeOf<Schema<I18nCompatibleSource>>>;
|
13
|
+
readonly opt: boolean;
|
14
|
+
constructor(locales: Locales, item: Schema<SchemaTypeOf<Schema<I18nCompatibleSource>>>, opt?: boolean);
|
15
|
+
validate(src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>): false | Record<SourcePath, string[]>;
|
16
|
+
match(src: I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>>): boolean;
|
17
|
+
optional(): Schema<I18nSource<Locales, SchemaTypeOf<Schema<I18nCompatibleSource>>> | null>;
|
18
|
+
serialize(): SerializedSchema;
|
19
|
+
}
|
20
|
+
export type I18n<Locales extends readonly string[]> = <S extends Schema<I18nCompatibleSource>>(schema: S) => Schema<I18nSource<Locales, SchemaTypeOf<S>>>;
|
21
|
+
export declare const i18n: <Locales extends readonly string[]>(locales: Locales) => <S extends Schema<I18nCompatibleSource>>(schema: S) => Schema<I18nSource<Locales, SchemaTypeOf<S>>>;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { FileSource } from "../source/file";
|
3
|
+
import { SourcePath } from "../val";
|
4
|
+
export type ImageOptions = {
|
5
|
+
ext: ["jpg"] | ["webp"];
|
6
|
+
directory?: string;
|
7
|
+
prefix?: string;
|
8
|
+
};
|
9
|
+
export type SerializedImageSchema = {
|
10
|
+
type: "image";
|
11
|
+
options?: ImageOptions;
|
12
|
+
opt: boolean;
|
13
|
+
};
|
14
|
+
export type ImageMetadata = {
|
15
|
+
width: number;
|
16
|
+
height: number;
|
17
|
+
sha256: string;
|
18
|
+
} | undefined;
|
19
|
+
export declare class ImageSchema<Src extends FileSource<ImageMetadata> | null> extends Schema<Src> {
|
20
|
+
readonly options?: ImageOptions | undefined;
|
21
|
+
readonly opt: boolean;
|
22
|
+
constructor(options?: ImageOptions | undefined, opt?: boolean);
|
23
|
+
validate(src: Src): false | Record<SourcePath, string[]>;
|
24
|
+
match(src: Src): boolean;
|
25
|
+
optional(): Schema<Src | null>;
|
26
|
+
serialize(): SerializedSchema;
|
27
|
+
}
|
28
|
+
export declare const image: (options?: ImageOptions) => Schema<FileSource<ImageMetadata>>;
|
29
|
+
export declare const convertImageSource: (src: FileSource<ImageMetadata>) => {
|
30
|
+
url: string;
|
31
|
+
metadata?: ImageMetadata;
|
32
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { SelectorSource } from "../selector";
|
2
|
+
import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
|
3
|
+
import { SourcePath } from "../val";
|
4
|
+
import { SerializedArraySchema } from "./array";
|
5
|
+
import { SerializedBooleanSchema } from "./boolean";
|
6
|
+
import { SerializedI18nSchema } from "./i18n";
|
7
|
+
import { SerializedImageSchema } from "./image";
|
8
|
+
import { SerializedLiteralSchema } from "./literal";
|
9
|
+
import { SerializedNumberSchema } from "./number";
|
10
|
+
import { SerializedObjectSchema } from "./object";
|
11
|
+
import { SerializedOneOfSchema } from "./oneOf";
|
12
|
+
import { SerializedRichTextSchema } from "./richtext";
|
13
|
+
import { SerializedStringSchema } from "./string";
|
14
|
+
import { SerializedUnionSchema } from "./union";
|
15
|
+
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedOneOfSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedImageSchema | SerializedI18nSchema;
|
16
|
+
export declare abstract class Schema<Src extends SelectorSource> {
|
17
|
+
abstract validate(src: Src): false | Record<SourcePath, string[]>;
|
18
|
+
abstract match(src: Src): boolean;
|
19
|
+
abstract optional(): Schema<Src | null>;
|
20
|
+
abstract serialize(): SerializedSchema;
|
21
|
+
remote(): Src extends RemoteCompatibleSource ? Schema<RemoteSource<Src>> : never;
|
22
|
+
}
|
23
|
+
export type SchemaTypeOf<T extends Schema<SelectorSource>> = T extends Schema<infer Src> ? Src : never;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { SourcePath } from "../val";
|
3
|
+
export type SerializedLiteralSchema = {
|
4
|
+
type: "literal";
|
5
|
+
value: string;
|
6
|
+
opt: boolean;
|
7
|
+
};
|
8
|
+
export declare class LiteralSchema<Src extends string | null> extends Schema<Src> {
|
9
|
+
readonly value: string;
|
10
|
+
readonly opt: boolean;
|
11
|
+
constructor(value: string, opt?: boolean);
|
12
|
+
validate(src: Src): false | Record<SourcePath, string[]>;
|
13
|
+
match(src: Src): boolean;
|
14
|
+
optional(): Schema<Src | null>;
|
15
|
+
serialize(): SerializedSchema;
|
16
|
+
}
|
17
|
+
export declare const literal: <T extends string>(value: T) => Schema<T>;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { SourcePath } from "../val";
|
3
|
+
type NumberOptions = {
|
4
|
+
max?: number;
|
5
|
+
min?: number;
|
6
|
+
};
|
7
|
+
export type SerializedNumberSchema = {
|
8
|
+
type: "number";
|
9
|
+
options?: NumberOptions;
|
10
|
+
opt: boolean;
|
11
|
+
};
|
12
|
+
export declare class NumberSchema<Src extends number | null> extends Schema<Src> {
|
13
|
+
readonly options?: NumberOptions | undefined;
|
14
|
+
readonly opt: boolean;
|
15
|
+
constructor(options?: NumberOptions | undefined, opt?: boolean);
|
16
|
+
validate(src: Src): false | Record<SourcePath, string[]>;
|
17
|
+
match(src: Src): boolean;
|
18
|
+
optional(): Schema<Src | null>;
|
19
|
+
serialize(): SerializedSchema;
|
20
|
+
}
|
21
|
+
export declare const number: (options?: NumberOptions) => Schema<number>;
|
22
|
+
export {};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { Schema, SchemaTypeOf, SerializedSchema } from ".";
|
2
|
+
import { SelectorSource } from "../selector";
|
3
|
+
import { SourcePath } from "../val";
|
4
|
+
export type SerializedObjectSchema = {
|
5
|
+
type: "object";
|
6
|
+
items: Record<string, SerializedSchema>;
|
7
|
+
opt: boolean;
|
8
|
+
};
|
9
|
+
type ObjectSchemaProps = {
|
10
|
+
[key: string]: Schema<SelectorSource>;
|
11
|
+
};
|
12
|
+
type ObjectSchemaSrcOf<Props extends ObjectSchemaProps> = {
|
13
|
+
[key in keyof Props]: SchemaTypeOf<Props[key]>;
|
14
|
+
};
|
15
|
+
export declare class ObjectSchema<Props extends ObjectSchemaProps> extends Schema<ObjectSchemaSrcOf<Props>> {
|
16
|
+
readonly items: Props;
|
17
|
+
readonly opt: boolean;
|
18
|
+
constructor(items: Props, opt?: boolean);
|
19
|
+
validate(src: ObjectSchemaSrcOf<Props>): false | Record<SourcePath, string[]>;
|
20
|
+
match(src: ObjectSchemaSrcOf<Props>): boolean;
|
21
|
+
optional(): Schema<ObjectSchemaSrcOf<Props> | null>;
|
22
|
+
serialize(): SerializedSchema;
|
23
|
+
}
|
24
|
+
export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => Schema<{ [key in keyof Props]: SchemaTypeOf<Props[key]>; }>;
|
25
|
+
export {};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { ValModuleBrand } from "../module";
|
3
|
+
import { GenericSelector } from "../selector";
|
4
|
+
import { Source, SourceArray } from "../source";
|
5
|
+
import { SourcePath } from "../val";
|
6
|
+
export type SerializedOneOfSchema = {
|
7
|
+
type: "oneOf";
|
8
|
+
selector: SourcePath;
|
9
|
+
opt: boolean;
|
10
|
+
};
|
11
|
+
type OneOfSelector<Sel extends GenericSelector<SourceArray>> = Sel extends GenericSelector<infer S> ? S extends (infer IS)[] ? IS extends Source ? GenericSelector<IS> : never : never : never;
|
12
|
+
export declare class OneOfSchema<Sel extends GenericSelector<SourceArray>> extends Schema<OneOfSelector<Sel>> {
|
13
|
+
readonly selector: Sel;
|
14
|
+
readonly opt: boolean;
|
15
|
+
constructor(selector: Sel, opt?: boolean);
|
16
|
+
validate(src: OneOfSelector<Sel>): false | Record<SourcePath, string[]>;
|
17
|
+
match(src: OneOfSelector<Sel>): boolean;
|
18
|
+
optional(): Schema<OneOfSelector<Sel> | null>;
|
19
|
+
serialize(): SerializedSchema;
|
20
|
+
}
|
21
|
+
export declare const oneOf: <Src extends GenericSelector<SourceArray, undefined> & ValModuleBrand>(valModule: Src) => Schema<OneOfSelector<Src>>;
|
22
|
+
export {};
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { SourcePath } from "../val";
|
3
|
+
export type SerializedRichTextSchema = {
|
4
|
+
type: "richtext";
|
5
|
+
opt: boolean;
|
6
|
+
};
|
7
|
+
type Node = {
|
8
|
+
version: 1;
|
9
|
+
};
|
10
|
+
type NodeType = Node & {
|
11
|
+
format: FormatType;
|
12
|
+
direction: DirectionType;
|
13
|
+
indent: number;
|
14
|
+
};
|
15
|
+
type FormatType = "left" | "start" | "center" | "right" | "end" | "justify" | "";
|
16
|
+
type DirectionType = "ltr" | "rtl" | null;
|
17
|
+
export type TextNode = Node & {
|
18
|
+
format: FormatType | number;
|
19
|
+
detail: number;
|
20
|
+
mode: "normal" | "code" | "quote";
|
21
|
+
style: string;
|
22
|
+
text: string;
|
23
|
+
type: "text";
|
24
|
+
direction?: DirectionType;
|
25
|
+
indent?: number;
|
26
|
+
};
|
27
|
+
export type ImageNode = Node & {
|
28
|
+
altText: string;
|
29
|
+
height: number;
|
30
|
+
width: number;
|
31
|
+
maxWidth: number;
|
32
|
+
src: string;
|
33
|
+
type: "image";
|
34
|
+
};
|
35
|
+
export type ParagraphNode<VN = TextNode> = NodeType & {
|
36
|
+
children: (TextNode | VN)[];
|
37
|
+
type: "paragraph";
|
38
|
+
};
|
39
|
+
export type HeadingNode<HT extends HeadingTags = HeadingTags> = NodeType & {
|
40
|
+
children: TextNode[];
|
41
|
+
type: "heading";
|
42
|
+
tag: HT;
|
43
|
+
};
|
44
|
+
export type ListItemNode<VN = TextNode> = NodeType & {
|
45
|
+
children: (TextNode | VN)[];
|
46
|
+
type: "listitem";
|
47
|
+
value: number;
|
48
|
+
checked?: boolean;
|
49
|
+
};
|
50
|
+
export type ListNode<VN = TextNode> = NodeType & {
|
51
|
+
children: ListItemNode<VN>[];
|
52
|
+
type: "list";
|
53
|
+
tag: "ol" | "ul";
|
54
|
+
listType: "number" | "bullet" | "check";
|
55
|
+
start?: number;
|
56
|
+
};
|
57
|
+
type HeadingTags = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
58
|
+
export type RootNode<HT extends HeadingTags, VN> = Node & {
|
59
|
+
children: (HeadingNode<HT> | ParagraphNode<VN> | ListNode<VN>)[];
|
60
|
+
type: "root";
|
61
|
+
format: FormatType;
|
62
|
+
direction: DirectionType;
|
63
|
+
indent: number;
|
64
|
+
};
|
65
|
+
type ValNode = ImageNode;
|
66
|
+
export type RichText<HT extends HeadingTags = HeadingTags, VN extends TextNode | ValNode = TextNode> = RootNode<HT, VN>;
|
67
|
+
export declare class RichTextSchema<Src extends RichText | null> extends Schema<Src> {
|
68
|
+
readonly opt: boolean;
|
69
|
+
validate(src: Src): false | Record<SourcePath, string[]>;
|
70
|
+
match(src: Src): boolean;
|
71
|
+
optional(): Schema<RichText<HeadingTags, TextNode> | null>;
|
72
|
+
serialize(): SerializedSchema;
|
73
|
+
constructor(opt?: boolean);
|
74
|
+
}
|
75
|
+
export declare const richtext: () => Schema<RichText>;
|
76
|
+
export {};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { SourcePath } from "../val";
|
3
|
+
type StringOptions = {
|
4
|
+
maxLength?: number;
|
5
|
+
minLength?: number;
|
6
|
+
};
|
7
|
+
export type SerializedStringSchema = {
|
8
|
+
type: "string";
|
9
|
+
options?: StringOptions;
|
10
|
+
opt: boolean;
|
11
|
+
};
|
12
|
+
export declare class StringSchema<Src extends string | null> extends Schema<Src> {
|
13
|
+
readonly options?: StringOptions | undefined;
|
14
|
+
readonly opt: boolean;
|
15
|
+
constructor(options?: StringOptions | undefined, opt?: boolean);
|
16
|
+
validate(src: Src): false | Record<SourcePath, string[]>;
|
17
|
+
match(src: Src): boolean;
|
18
|
+
optional(): Schema<Src | null>;
|
19
|
+
serialize(): SerializedSchema;
|
20
|
+
}
|
21
|
+
export declare const string: <T extends string>(options?: StringOptions) => Schema<T>;
|
22
|
+
export {};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { Schema, SerializedSchema } from ".";
|
2
|
+
import { SelectorSource } from "../selector";
|
3
|
+
import { SourceObject } from "../source";
|
4
|
+
import { SourcePath } from "../val";
|
5
|
+
export type SerializedUnionSchema = {
|
6
|
+
type: "union";
|
7
|
+
key: string;
|
8
|
+
items: SerializedSchema[];
|
9
|
+
opt: boolean;
|
10
|
+
};
|
11
|
+
type SourceOf<Key extends string, T extends Schema<SourceObject & {
|
12
|
+
[k in Key]: string;
|
13
|
+
}>[]> = T extends Schema<infer S>[] ? S extends SelectorSource ? S : never : never;
|
14
|
+
export declare class UnionSchema<Key extends string, T extends Schema<SourceObject & {
|
15
|
+
[k in Key]: string;
|
16
|
+
}>[]> extends Schema<SourceOf<Key, T>> {
|
17
|
+
readonly key: Key;
|
18
|
+
readonly items: T;
|
19
|
+
readonly opt: boolean;
|
20
|
+
validate(src: SourceOf<Key, T>): false | Record<SourcePath, string[]>;
|
21
|
+
match(src: SourceOf<Key, T>): boolean;
|
22
|
+
optional(): Schema<SourceOf<Key, T> | null>;
|
23
|
+
serialize(): SerializedSchema;
|
24
|
+
constructor(key: Key, items: T, opt?: boolean);
|
25
|
+
}
|
26
|
+
export declare const union: <Key extends string, T extends Schema<{
|
27
|
+
[x: string]: import("../source").Source;
|
28
|
+
} & {
|
29
|
+
fold?: undefined;
|
30
|
+
andThen?: undefined;
|
31
|
+
_ref?: undefined;
|
32
|
+
_type?: undefined;
|
33
|
+
val?: undefined;
|
34
|
+
valPath?: undefined;
|
35
|
+
} & { [k in Key]: string; }>[]>(key: Key, ...objects: T) => Schema<SourceOf<Key, T>>;
|
36
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
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;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from ".";
|
2
|
+
import { Schema } from "../schema";
|
3
|
+
import { Source, SourceArray } from "../source";
|
4
|
+
import { Selector as BooleanSelector } from "./boolean";
|
5
|
+
import { Selector as NumberSelector } from "./number";
|
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 ".";
|
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
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { SourceArray, SourceObject, SourcePrimitive } from "../source";
|
2
|
+
import { Selector as UnknownSelector } from ".";
|
3
|
+
import { FileSource } from "../source/file";
|
4
|
+
declare const brand: unique symbol;
|
5
|
+
export type I18nSelector<Locales extends readonly string[], T extends SourcePrimitive | SourceObject | SourceArray | FileSource> = UnknownSelector<T> & {
|
6
|
+
readonly [brand]: "I18nSelector";
|
7
|
+
all(): {
|
8
|
+
[locale in Locales[number]]: UnknownSelector<T>;
|
9
|
+
};
|
10
|
+
};
|
11
|
+
export {};
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import { I18nSelector } from "./i18n";
|
2
|
+
import { Selector as ObjectSelector } from "./object";
|
3
|
+
import { UndistributedSourceArray as ArraySelector } from "./array";
|
4
|
+
import { Selector as NumberSelector } from "./number";
|
5
|
+
import { Selector as StringSelector } from "./string";
|
6
|
+
import { Selector as BooleanSelector } from "./boolean";
|
7
|
+
import { Selector as PrimitiveSelector } from "./primitive";
|
8
|
+
import { FileSelector } from "./file";
|
9
|
+
import { SourcePath } from "../val";
|
10
|
+
import { Source, SourceArray, SourceObject, SourcePrimitive } from "../source";
|
11
|
+
import { Schema } from "../schema";
|
12
|
+
import { Expr } from "../expr/expr";
|
13
|
+
import { RemoteSelector } from "./remote";
|
14
|
+
import { A } from "ts-toolbelt";
|
15
|
+
import { I18nSource, I18nCompatibleSource } from "../source/i18n";
|
16
|
+
import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
|
17
|
+
import { FileSource } from "../source/file";
|
18
|
+
/**
|
19
|
+
* Selectors can be used to select parts of a Val module.
|
20
|
+
* Unlike queries, joins, aggregates etc is and will not be supported.
|
21
|
+
*
|
22
|
+
* They are designed to be be used as if they were "normal" JSON data,
|
23
|
+
* though some concessions had to be made because of TypeScript limitations.
|
24
|
+
*
|
25
|
+
* Selectors works equally on source content, defined in code, and remote content.
|
26
|
+
*
|
27
|
+
* @example
|
28
|
+
* // Select the title of a document
|
29
|
+
* const titles = useVal(docsVal.map((doc) => doc.title));
|
30
|
+
*
|
31
|
+
* @example
|
32
|
+
* // Match on a union type
|
33
|
+
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
34
|
+
* newsletter: (newsletter) => newsletter.title,
|
35
|
+
* email: (email) => email.subject,
|
36
|
+
* }));
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
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 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;
|
40
|
+
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
41
|
+
[key: string]: SelectorSource;
|
42
|
+
} | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | GenericSelector<Source>;
|
43
|
+
/**
|
44
|
+
* @internal
|
45
|
+
*/
|
46
|
+
export declare const GetSchema: unique symbol;
|
47
|
+
/**
|
48
|
+
/**
|
49
|
+
* @internal
|
50
|
+
*/
|
51
|
+
export declare const Path: unique symbol;
|
52
|
+
/**
|
53
|
+
* @internal
|
54
|
+
*/
|
55
|
+
export declare const SourceOrExpr: unique symbol;
|
56
|
+
/**
|
57
|
+
* @internal
|
58
|
+
*/
|
59
|
+
export declare const ValError: unique symbol;
|
60
|
+
export declare abstract class GenericSelector<out T extends Source, Error extends string | undefined = undefined> {
|
61
|
+
readonly [Path]: SourcePath | undefined;
|
62
|
+
readonly [SourceOrExpr]: T | Expr;
|
63
|
+
readonly [ValError]: Error | undefined;
|
64
|
+
readonly [GetSchema]: Schema<T> | undefined;
|
65
|
+
constructor(valOrExpr: T, path: SourcePath | undefined, schema?: Schema<T>, error?: Error);
|
66
|
+
assert<U extends Source, E extends Source = null>(schema: Schema<U>, other?: () => E): SelectorOf<U | E>;
|
67
|
+
}
|
68
|
+
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 ? {
|
69
|
+
[key in keyof T]: SourceOf<A.Try<T[key], SelectorSource>>;
|
70
|
+
} : never : T extends {
|
71
|
+
[key: string]: SelectorSource;
|
72
|
+
} ? {
|
73
|
+
[key in keyof T]: SourceOf<A.Try<T[key], SelectorSource>>;
|
74
|
+
} : never;
|
75
|
+
/**
|
76
|
+
* Use this type to convert types that accepts both Source and Selectors
|
77
|
+
*
|
78
|
+
* An example would be where literals are supported like in most higher order functions (e.g. map in array)
|
79
|
+
**/
|
80
|
+
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">;
|
81
|
+
export declare function getSchema(selector: Selector<Source>): Schema<SelectorSource> | undefined;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Selector as UnknownSelector, GenericSelector, SelectorOf, SelectorSource } from ".";
|
2
|
+
import { SourceObject } from "../source";
|
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 ".";
|
2
|
+
import { Source, SourcePrimitive } from "../source";
|
3
|
+
import { Selector as BooleanSelector } from "./boolean";
|
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 {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Selector as UnknownSelector } from ".";
|
2
|
+
import { RemoteCompatibleSource } from "../source/remote";
|
3
|
+
declare const brand: unique symbol;
|
4
|
+
export type RemoteSelector<T extends RemoteCompatibleSource> = UnknownSelector<T> & {
|
5
|
+
readonly [brand]: "RemoteSelector";
|
6
|
+
};
|
7
|
+
export {};
|