@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
package/ROADMAP.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Planned features
|
2
|
+
|
3
|
+
## i18n
|
4
|
+
|
5
|
+
Example:
|
6
|
+
|
7
|
+
```tsx
|
8
|
+
// file: ./blogs.val.ts
|
9
|
+
|
10
|
+
export const schema = s.array(
|
11
|
+
s.i18n(s.object({ title: s.string(), text: s.richtext() }))
|
12
|
+
);
|
13
|
+
|
14
|
+
export default val.content("/blogs", schema, [
|
15
|
+
{
|
16
|
+
en_US: {
|
17
|
+
title: "Title 1",
|
18
|
+
text: val.richtext("Richtext 1"),
|
19
|
+
},
|
20
|
+
nb_NO: {
|
21
|
+
title: "Tittel 1",
|
22
|
+
text: val.richtext("Riktekst?"),
|
23
|
+
},
|
24
|
+
},
|
25
|
+
]);
|
26
|
+
|
27
|
+
// file: ./components/ServerComponent.ts
|
28
|
+
|
29
|
+
import blogsVal from "./blogs.val";
|
30
|
+
|
31
|
+
export async function ServerComponent({ index }: { index: number }) {
|
32
|
+
const blogs = await fetchVal(blogVal, getLocale());
|
33
|
+
|
34
|
+
// NOTE: automatically resolves the locale
|
35
|
+
const title = blogs[index].title; // is a string
|
36
|
+
return <div>{title}</div>;
|
37
|
+
}
|
38
|
+
```
|
39
|
+
|
40
|
+
Missing infrastructure: none in particular.
|
41
|
+
|
42
|
+
## remote
|
43
|
+
|
44
|
+
Remote makes it possible to move content to cloud storage (and back again). It uses immutable references, so local work, branches still works.
|
45
|
+
|
46
|
+
Example:
|
47
|
+
|
48
|
+
```tsx
|
49
|
+
// file: ./blogs.val.ts
|
50
|
+
|
51
|
+
export const schema = s
|
52
|
+
.array(s.object({ title: s.string(), text: s.richtext() }))
|
53
|
+
.remote();
|
54
|
+
|
55
|
+
export default val.content(
|
56
|
+
"/blogs",
|
57
|
+
schema,
|
58
|
+
val.remote("4ba7c33b32a60be06b1b26dff8cc5d8d967660ab") // a change in content, will result in a new reference
|
59
|
+
);
|
60
|
+
|
61
|
+
// file: ./components/ServerComponent.ts
|
62
|
+
|
63
|
+
import blogsVal from "./blogs.val";
|
64
|
+
|
65
|
+
export async function ServerComponent({ index }: { index: number }) {
|
66
|
+
const blog = await fetchVal(
|
67
|
+
blogVal[index] // only fetch the blog at index
|
68
|
+
);
|
69
|
+
const title = blog.title;
|
70
|
+
return <div>{title}</div>;
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
Missing infrastructure: cloud support, patch support, selectors proxy needs to be able to switch between remote and source (see selectors/future), editor plugin to improve DX (refactors, ...)?
|
75
|
+
|
76
|
+
## oneOf
|
77
|
+
|
78
|
+
oneOf makes it possible to reference an item in an array of in another val module.
|
79
|
+
|
80
|
+
Example:
|
81
|
+
|
82
|
+
```ts
|
83
|
+
// file: ./employees.val.ts
|
84
|
+
|
85
|
+
export schema = s.array(s.object({ name: s.string() }));
|
86
|
+
|
87
|
+
export default val.content('/employees', schema, [{
|
88
|
+
name: 'John Smith',
|
89
|
+
}]);
|
90
|
+
|
91
|
+
// file: ./contacts.val.ts
|
92
|
+
|
93
|
+
import employeesVal from './employees.val';
|
94
|
+
|
95
|
+
export schema = s.object({
|
96
|
+
hr: s.oneOf(employeesVal),
|
97
|
+
});
|
98
|
+
|
99
|
+
export default val.content('/contacts', schema, {
|
100
|
+
hr: employeesVal[0]
|
101
|
+
});
|
102
|
+
|
103
|
+
|
104
|
+
```
|
105
|
+
|
106
|
+
Missing infrastructure: need a change in how patches are applied for source files to handle selectors inside data.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { ApiPatchResponse, ApiTreeResponse } from "./index.js";
|
2
|
+
import { result } from "./fp/index.js";
|
3
|
+
import { PatchJSON } from "./patch/index.js";
|
4
|
+
import { ModuleId } from "./val/index.js";
|
5
|
+
type FetchError = {
|
6
|
+
message: string;
|
7
|
+
statusCode?: number;
|
8
|
+
};
|
9
|
+
export declare class ValApi {
|
10
|
+
host: string;
|
11
|
+
constructor(host: string);
|
12
|
+
getDisableUrl(): string;
|
13
|
+
postPatches(moduleId: ModuleId, patches: PatchJSON, commit?: string, headers?: Record<string, string> | undefined): Promise<result.Result<ApiPatchResponse, FetchError>>;
|
14
|
+
getSession(): Promise<result.Result<{
|
15
|
+
mode: "proxy" | "local";
|
16
|
+
member_role: "owner" | "developer" | "editor";
|
17
|
+
}, FetchError>>;
|
18
|
+
getModules({ patch, includeSchema, includeSource, treePath, headers, }: {
|
19
|
+
patch?: boolean;
|
20
|
+
includeSchema?: boolean;
|
21
|
+
includeSource?: boolean;
|
22
|
+
treePath?: string;
|
23
|
+
headers?: Record<string, string> | undefined;
|
24
|
+
}): Promise<result.Result<ApiTreeResponse, FetchError>>;
|
25
|
+
}
|
26
|
+
export {};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Expr } from "./expr.js";
|
2
2
|
import { Source } from "../source/index.js";
|
3
3
|
import { result } from "../fp/index.js";
|
4
|
-
import { Path, SourceOrExpr } from "../selector/index.js";
|
4
|
+
import { Path, SourceOrExpr } from "../selector/future/index.js";
|
5
5
|
import { SourcePath } from "../val/index.js";
|
6
6
|
import { Json } from "../Json.js";
|
7
7
|
export declare class EvalError {
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { GenericSelector, SelectorOf, SelectorSource } from "../selector/index.js";
|
2
|
+
import { JsonOfSource, Val } from "../val/index.js";
|
3
|
+
export declare function fetchVal<T extends SelectorSource>(selector: T): SelectorOf<T> extends GenericSelector<infer S> ? Promise<Val<JsonOfSource<S>>> : never;
|
4
|
+
export declare function getVal<T extends SelectorSource>(selector: T): SelectorOf<T> extends GenericSelector<infer S> ? Val<JsonOfSource<S>> : never;
|
5
|
+
export declare function serializedValOfSelectorSource<T extends SelectorSource>(selector: T): any;
|
@@ -4,7 +4,6 @@ export { Schema, type SerializedSchema } from "./schema/index.js";
|
|
4
4
|
export type { ValModule, SerializedModule } from "./module.js";
|
5
5
|
export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
|
6
6
|
export type { FileSource } from "./source/file.js";
|
7
|
-
export type { RemoteSource } from "./source/remote.js";
|
8
7
|
export type { RichTextSource, RichText, TextNode, ParagraphNode, HeadingNode, ListItemNode, ListNode, } from "./source/richtext.js";
|
9
8
|
export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
|
10
9
|
export type { Json, JsonPrimitive } from "./Json.js";
|
@@ -13,26 +12,54 @@ export type { ValidationFix } from "./schema/validation/ValidationFix.js";
|
|
13
12
|
export * as expr from "./expr/index.js";
|
14
13
|
export { FILE_REF_PROP } from "./source/file.js";
|
15
14
|
export { VAL_EXTENSION, type SourceArray } from "./source/index.js";
|
16
|
-
export type { I18nSource } from "./source/i18n.js";
|
17
15
|
export { derefPatch } from "./patch/deref.js";
|
18
16
|
export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector/index.js";
|
19
|
-
import {
|
20
|
-
import { getRawSource, resolvePath, splitModuleIdAndModulePath } from "./module.js";
|
17
|
+
import { getSource, resolvePath, splitModuleIdAndModulePath } from "./module.js";
|
21
18
|
import { getSchema } from "./selector/index.js";
|
22
|
-
import { getValPath, isVal } from "./val/index.js";
|
23
|
-
import {
|
19
|
+
import { ModuleId, ModulePath, getValPath, isVal } from "./val/index.js";
|
20
|
+
import { createValPathOfItem } from "./selector/SelectorProxy.js";
|
21
|
+
import { getVal } from "./future/fetchVal.js";
|
22
|
+
import { Json } from "./Json.js";
|
23
|
+
import { SerializedSchema } from "./schema/index.js";
|
24
|
+
export { ValApi } from "./ValApi.js";
|
25
|
+
export type ApiTreeResponse = {
|
26
|
+
git: {
|
27
|
+
commit?: string;
|
28
|
+
branch?: string;
|
29
|
+
};
|
30
|
+
modules: Record<ModuleId, {
|
31
|
+
schema?: SerializedSchema;
|
32
|
+
patches?: {
|
33
|
+
applied: string[];
|
34
|
+
failed?: string[];
|
35
|
+
};
|
36
|
+
source?: Json;
|
37
|
+
}>;
|
38
|
+
};
|
39
|
+
export type ApiPatchResponse = Record<ModuleId, string[]>;
|
24
40
|
declare const Internal: {
|
25
|
-
|
41
|
+
convertFileSource: (src: import("./source/file.js").FileSource<import("./schema/image.js").ImageMetadata>) => {
|
26
42
|
url: string;
|
27
43
|
metadata?: import("./schema/image.js").ImageMetadata;
|
28
44
|
};
|
29
45
|
getSchema: typeof getSchema;
|
30
46
|
getValPath: typeof getValPath;
|
31
47
|
getVal: typeof getVal;
|
32
|
-
|
48
|
+
getSource: typeof getSource;
|
33
49
|
resolvePath: typeof resolvePath;
|
34
50
|
splitModuleIdAndModulePath: typeof splitModuleIdAndModulePath;
|
35
|
-
fetchVal: typeof fetchVal;
|
36
51
|
isVal: typeof isVal;
|
52
|
+
createValPathOfItem: typeof createValPathOfItem;
|
53
|
+
createPatchJSONPath: (modulePath: ModulePath) => string;
|
54
|
+
/**
|
55
|
+
* Enables draft mode: updates all Val modules with patches
|
56
|
+
*/
|
57
|
+
VAL_DRAFT_MODE_COOKIE: string;
|
58
|
+
/**
|
59
|
+
* Enables Val: show the overlay / menu
|
60
|
+
*/
|
61
|
+
VAL_ENABLE_COOKIE_NAME: string;
|
62
|
+
VAL_STATE_COOKIE: string;
|
63
|
+
VAL_SESSION_COOKIE: string;
|
37
64
|
};
|
38
65
|
export { Internal };
|
@@ -1,15 +1,14 @@
|
|
1
|
-
import { F } from "ts-toolbelt";
|
2
1
|
import { array } from "./schema/array.js";
|
3
2
|
import { number } from "./schema/number.js";
|
4
3
|
import { object } from "./schema/object.js";
|
5
4
|
import { string } from "./schema/string.js";
|
6
5
|
import { boolean } from "./schema/boolean.js";
|
7
|
-
import { oneOf } from "./schema/oneOf.js";
|
8
6
|
import { union } from "./schema/union.js";
|
9
|
-
import { I18n } from "./schema/i18n.js";
|
10
7
|
import { richtext } from "./schema/richtext.js";
|
11
8
|
import { image } from "./schema/image.js";
|
12
9
|
import { literal } from "./schema/literal.js";
|
10
|
+
import { keyOf } from "./schema/keyOf.js";
|
11
|
+
import { record } from "./schema/record.js";
|
13
12
|
export type InitSchema = {
|
14
13
|
readonly string: typeof string;
|
15
14
|
readonly boolean: typeof boolean;
|
@@ -17,15 +16,13 @@ export type InitSchema = {
|
|
17
16
|
readonly object: typeof object;
|
18
17
|
readonly number: typeof number;
|
19
18
|
readonly union: typeof union;
|
20
|
-
readonly oneOf: typeof oneOf;
|
21
19
|
readonly richtext: typeof richtext;
|
22
20
|
readonly image: typeof image;
|
23
21
|
readonly literal: typeof literal;
|
22
|
+
readonly keyOf: typeof keyOf;
|
23
|
+
readonly record: typeof record;
|
24
24
|
};
|
25
|
-
export
|
26
|
-
readonly i18n: I18n<Locales>;
|
27
|
-
};
|
28
|
-
export declare function initSchema<Locales extends readonly string[]>(locales: F.Narrow<Locales>): {
|
25
|
+
export declare function initSchema(): {
|
29
26
|
string: <T extends string>(options?: {
|
30
27
|
maxLength?: number | undefined;
|
31
28
|
minLength?: number | undefined;
|
@@ -43,15 +40,16 @@ export declare function initSchema<Locales extends readonly string[]>(locales: F
|
|
43
40
|
[x: string]: import("./source/index.js").Source;
|
44
41
|
} & {
|
45
42
|
fold?: undefined;
|
43
|
+
assert?: undefined;
|
46
44
|
andThen?: undefined;
|
47
45
|
_ref?: undefined;
|
48
46
|
_type?: undefined;
|
49
47
|
val?: undefined;
|
50
48
|
valPath?: undefined;
|
51
49
|
} & { [k in Key]: string; }>[]>(key: Key, ...objects: T_1) => import("./schema/index.js").Schema<T_1 extends import("./schema/index.js").Schema<infer S_1 extends import("./selector/index.js").SelectorSource>[] ? S_1 extends import("./selector/index.js").SelectorSource ? S_1 : never : never>;
|
52
|
-
oneOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceArray, undefined> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/index.js").Schema<Src extends import("./selector/index.js").GenericSelector<infer S_2 extends import("./source/index.js").Source, undefined> ? S_2 extends (infer IS)[] ? IS extends import("./source/index.js").Source ? import("./selector/index.js").GenericSelector<IS, undefined> : never : never : never>;
|
53
50
|
richtext: () => import("./schema/index.js").Schema<import("./index.js").RichTextSource>;
|
54
51
|
image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").FileSource<import("./schema/image.js").ImageMetadata>>;
|
55
52
|
literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
|
56
|
-
|
53
|
+
keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject | import("./source/index.js").SourceArray, undefined> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/index.js").Schema<Src extends import("./selector/index.js").GenericSelector<infer S_2 extends import("./source/index.js").Source, undefined> ? S_2 extends readonly any[] ? number : S_2 extends import("./source/index.js").SourceObject ? keyof S_2 : S_2 extends Record<string, any> ? string : never : never>;
|
54
|
+
record: <S_3 extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S_3) => import("./schema/index.js").Schema<Record<string, import("./schema/index.js").SchemaTypeOf<S_3>>>;
|
57
55
|
};
|
@@ -1,35 +1,17 @@
|
|
1
1
|
import { content } from "./module.js";
|
2
|
-
import {
|
3
|
-
import { InitSchema, InitSchemaLocalized } from "./initSchema.js";
|
2
|
+
import { InitSchema } from "./initSchema.js";
|
4
3
|
import { getValPath as getPath } from "./val/index.js";
|
5
|
-
import { remote } from "./source/remote.js";
|
6
4
|
import { file } from "./source/file.js";
|
7
5
|
import { richtext } from "./source/richtext.js";
|
8
6
|
type ValConstructor = {
|
9
7
|
content: typeof content;
|
10
8
|
getPath: typeof getPath;
|
11
|
-
remote: typeof remote;
|
12
9
|
file: typeof file;
|
13
10
|
richtext: typeof richtext;
|
14
11
|
};
|
15
|
-
export type InitVal
|
16
|
-
Locales
|
17
|
-
] extends [readonly string[]] ? {
|
18
|
-
val: ValConstructor & {
|
19
|
-
i18n: I18n<Locales>;
|
20
|
-
};
|
21
|
-
s: InitSchema & InitSchemaLocalized<Locales>;
|
22
|
-
} : {
|
12
|
+
export type InitVal = {
|
23
13
|
val: ValConstructor;
|
24
14
|
s: InitSchema;
|
25
15
|
};
|
26
|
-
|
27
|
-
[K in keyof A]: NarrowStrings<A[K]>;
|
28
|
-
};
|
29
|
-
export declare const initVal: <Locales extends readonly string[] | undefined>(options?: {
|
30
|
-
readonly locales?: {
|
31
|
-
readonly required: NarrowStrings<Locales>;
|
32
|
-
readonly default: NarrowStrings<Locales extends readonly string[] ? Locales[number] : never>;
|
33
|
-
} | undefined;
|
34
|
-
} | undefined) => InitVal<Locales>;
|
16
|
+
export declare const initVal: () => InitVal;
|
35
17
|
export {};
|
@@ -3,10 +3,6 @@ import { GenericSelector, SelectorOf, SelectorSource } from "./selector/index.js
|
|
3
3
|
import { Source } from "./source/index.js";
|
4
4
|
import { ModuleId, ModulePath, SourcePath } from "./val/index.js";
|
5
5
|
import { Json } from "./Json.js";
|
6
|
-
import { SerializedRichTextSchema } from "./schema/richtext.js";
|
7
|
-
import { ImageMetadata, ImageSchema, SerializedImageSchema } from "./schema/image.js";
|
8
|
-
import { FileSource } from "./source/file.js";
|
9
|
-
import { RichText } from "./source/richtext.js";
|
10
6
|
declare const brand: unique symbol;
|
11
7
|
export type ValModule<T extends SelectorSource> = SelectorOf<T> & ValModuleBrand;
|
12
8
|
export type ValModuleBrand = {
|
@@ -14,20 +10,12 @@ export type ValModuleBrand = {
|
|
14
10
|
};
|
15
11
|
export type TypeOfValModule<T extends ValModule<SelectorSource>> = T extends GenericSelector<infer S> ? S : never;
|
16
12
|
export declare function content<T extends Schema<SelectorSource>>(id: string, schema: T, source: SchemaTypeOf<T>): ValModule<SchemaTypeOf<T>>;
|
17
|
-
export declare function
|
13
|
+
export declare function getSource(valModule: ValModule<SelectorSource>): Source;
|
18
14
|
export declare function splitModuleIdAndModulePath(path: SourcePath): [moduleId: ModuleId, path: ModulePath];
|
19
15
|
export declare function getSourceAtPath(modulePath: ModulePath, valModule: ValModule<SelectorSource> | Source): any;
|
20
16
|
export declare function resolvePath(path: ModulePath, valModule: ValModule<SelectorSource> | Source, schema: Schema<SelectorSource> | SerializedSchema): {
|
21
17
|
path: string;
|
22
|
-
schema:
|
23
|
-
source: any;
|
24
|
-
} | {
|
25
|
-
path: string;
|
26
|
-
schema: SerializedRichTextSchema | Schema<RichText<"h1" | "h2" | "h3" | "h4" | "h5" | "h6", import("./source/richtext.js").TextNode>>;
|
27
|
-
source: any;
|
28
|
-
} | {
|
29
|
-
path: ModulePath;
|
30
|
-
schema: Schema<SelectorSource> | SerializedSchema;
|
18
|
+
schema: SerializedSchema | Schema<SelectorSource>;
|
31
19
|
source: any;
|
32
20
|
};
|
33
21
|
export declare function parsePath(input: ModulePath): string[];
|
@@ -27,7 +27,7 @@ export declare class ImageSchema<Src extends FileSource<ImageMetadata> | null> e
|
|
27
27
|
serialize(): SerializedSchema;
|
28
28
|
}
|
29
29
|
export declare const image: (options?: ImageOptions) => Schema<FileSource<ImageMetadata>>;
|
30
|
-
export declare const
|
30
|
+
export declare const convertFileSource: (src: FileSource<ImageMetadata>) => {
|
31
31
|
url: string;
|
32
32
|
metadata?: ImageMetadata;
|
33
33
|
};
|
@@ -1,25 +1,23 @@
|
|
1
1
|
import { SelectorSource } from "../selector/index.js";
|
2
|
-
import { RemoteCompatibleSource, RemoteSource } from "../source/remote.js";
|
3
2
|
import { SourcePath } from "../val/index.js";
|
4
3
|
import { SerializedArraySchema } from "./array.js";
|
5
4
|
import { SerializedBooleanSchema } from "./boolean.js";
|
6
|
-
import { SerializedI18nSchema } from "./i18n.js";
|
7
5
|
import { SerializedImageSchema } from "./image.js";
|
6
|
+
import { SerializedKeyOfSchema } from "./keyOf.js";
|
8
7
|
import { SerializedLiteralSchema } from "./literal.js";
|
9
8
|
import { SerializedNumberSchema } from "./number.js";
|
10
9
|
import { SerializedObjectSchema } from "./object.js";
|
11
|
-
import {
|
10
|
+
import { SerializedRecordSchema } from "./record.js";
|
12
11
|
import { SerializedRichTextSchema } from "./richtext.js";
|
13
12
|
import { SerializedStringSchema } from "./string.js";
|
14
13
|
import { SerializedUnionSchema } from "./union.js";
|
15
14
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
16
|
-
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema |
|
15
|
+
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedImageSchema;
|
17
16
|
export declare abstract class Schema<Src extends SelectorSource> {
|
18
17
|
abstract validate(path: SourcePath, src: Src): ValidationErrors;
|
19
18
|
abstract assert(src: Src): boolean;
|
20
19
|
abstract optional(): Schema<Src | null>;
|
21
20
|
abstract serialize(): SerializedSchema;
|
22
|
-
remote(): Src extends RemoteCompatibleSource ? Schema<RemoteSource<Src>> : never;
|
23
21
|
/** MUTATES! since internal and perf sensitive */
|
24
22
|
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value?: unknown): ValidationErrors;
|
25
23
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { Schema, SerializedSchema } from "./index.js";
|
2
|
+
import { ValModuleBrand } from "../module.js";
|
3
|
+
import { GenericSelector } from "../selector/index.js";
|
4
|
+
import { SourceArray, SourceObject } from "../source/index.js";
|
5
|
+
import { SourcePath } from "../val/index.js";
|
6
|
+
import { ValidationErrors } from "./validation/ValidationError.js";
|
7
|
+
export type SerializedKeyOfSchema = {
|
8
|
+
type: "keyOf";
|
9
|
+
selector: SourcePath;
|
10
|
+
opt: boolean;
|
11
|
+
};
|
12
|
+
type KeyOfSelector<Sel extends GenericSelector<SourceArray | SourceObject>> = Sel extends GenericSelector<infer S> ? S extends readonly any[] ? number : S extends SourceObject ? keyof S : S extends Record<string, any> ? string : never : never;
|
13
|
+
export declare class KeyOfSchema<Sel extends GenericSelector<SourceArray | SourceObject>> extends Schema<KeyOfSelector<Sel>> {
|
14
|
+
readonly selector: Sel;
|
15
|
+
readonly opt: boolean;
|
16
|
+
constructor(selector: Sel, opt?: boolean);
|
17
|
+
validate(path: SourcePath, src: KeyOfSelector<Sel>): ValidationErrors;
|
18
|
+
assert(src: KeyOfSelector<Sel>): boolean;
|
19
|
+
optional(): Schema<KeyOfSelector<Sel> | null>;
|
20
|
+
serialize(): SerializedSchema;
|
21
|
+
}
|
22
|
+
export declare const keyOf: <Src extends GenericSelector<SourceObject | SourceArray, undefined> & ValModuleBrand>(valModule: Src) => Schema<KeyOfSelector<Src>>;
|
23
|
+
export {};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Schema, SchemaTypeOf, SerializedSchema } from "./index.js";
|
2
|
+
import { SelectorSource } from "../selector/index.js";
|
3
|
+
import { SourcePath } from "../val/index.js";
|
4
|
+
import { ValidationErrors } from "./validation/ValidationError.js";
|
5
|
+
export type SerializedRecordSchema = {
|
6
|
+
type: "record";
|
7
|
+
item: SerializedSchema;
|
8
|
+
opt: boolean;
|
9
|
+
};
|
10
|
+
export declare class RecordSchema<T extends Schema<SelectorSource>> extends Schema<Record<string, SchemaTypeOf<T>>> {
|
11
|
+
readonly item: T;
|
12
|
+
readonly opt: boolean;
|
13
|
+
constructor(item: T, opt?: boolean);
|
14
|
+
validate(path: SourcePath, src: Record<string, SchemaTypeOf<T>>): ValidationErrors;
|
15
|
+
assert(src: Record<string, SchemaTypeOf<T>>): boolean;
|
16
|
+
optional(): Schema<Record<string, SchemaTypeOf<T>> | null>;
|
17
|
+
serialize(): SerializedRecordSchema;
|
18
|
+
}
|
19
|
+
export declare const record: <S extends Schema<SelectorSource>>(schema: S) => Schema<Record<string, SchemaTypeOf<S>>>;
|
@@ -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">;
|