@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.
Files changed (100) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +537 -0
  3. package/dist/createClass-012eebbf.esm.js +109 -0
  4. package/dist/createClass-a436dbfe.cjs.dev.js +116 -0
  5. package/dist/createClass-de7426aa.cjs.prod.js +116 -0
  6. package/dist/declarations/src/Json.d.ts +6 -0
  7. package/dist/declarations/src/expr/eval.d.ts +19 -0
  8. package/dist/declarations/src/expr/expr.d.ts +32 -0
  9. package/dist/declarations/src/expr/index.d.ts +3 -0
  10. package/dist/declarations/src/expr/parser.d.ts +8 -0
  11. package/dist/declarations/src/expr/tokenizer.d.ts +7 -0
  12. package/dist/declarations/src/fetchVal.d.ts +5 -0
  13. package/dist/declarations/src/fp/array.d.ts +8 -0
  14. package/dist/declarations/src/fp/index.d.ts +3 -0
  15. package/dist/declarations/src/fp/result.d.ts +67 -0
  16. package/dist/declarations/src/fp/util.d.ts +12 -0
  17. package/dist/declarations/src/index.d.ts +32 -0
  18. package/dist/declarations/src/initSchema.d.ts +57 -0
  19. package/dist/declarations/src/initVal.d.ts +39 -0
  20. package/dist/declarations/src/module.d.ts +38 -0
  21. package/dist/declarations/src/patch/deref.d.ts +13 -0
  22. package/dist/declarations/src/patch/index.d.ts +6 -0
  23. package/dist/declarations/src/patch/json.d.ts +11 -0
  24. package/dist/declarations/src/patch/operation.d.ts +59 -0
  25. package/dist/declarations/src/patch/ops.d.ts +40 -0
  26. package/dist/declarations/src/patch/parse.d.ts +19 -0
  27. package/dist/declarations/src/patch/patch.d.ts +6 -0
  28. package/dist/declarations/src/patch/util.d.ts +6 -0
  29. package/dist/declarations/src/schema/array.d.ts +18 -0
  30. package/dist/declarations/src/schema/boolean.d.ts +15 -0
  31. package/dist/declarations/src/schema/i18n.d.ts +21 -0
  32. package/dist/declarations/src/schema/image.d.ts +32 -0
  33. package/dist/declarations/src/schema/index.d.ts +23 -0
  34. package/dist/declarations/src/schema/literal.d.ts +17 -0
  35. package/dist/declarations/src/schema/number.d.ts +22 -0
  36. package/dist/declarations/src/schema/object.d.ts +25 -0
  37. package/dist/declarations/src/schema/oneOf.d.ts +22 -0
  38. package/dist/declarations/src/schema/richtext.d.ts +76 -0
  39. package/dist/declarations/src/schema/string.d.ts +22 -0
  40. package/dist/declarations/src/schema/union.d.ts +36 -0
  41. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  42. package/dist/declarations/src/selector/array.d.ts +17 -0
  43. package/dist/declarations/src/selector/boolean.d.ts +2 -0
  44. package/dist/declarations/src/selector/file.d.ts +9 -0
  45. package/dist/declarations/src/selector/i18n.d.ts +11 -0
  46. package/dist/declarations/src/selector/index.d.ts +81 -0
  47. package/dist/declarations/src/selector/number.d.ts +2 -0
  48. package/dist/declarations/src/selector/object.d.ts +10 -0
  49. package/dist/declarations/src/selector/primitive.d.ts +9 -0
  50. package/dist/declarations/src/selector/remote.d.ts +7 -0
  51. package/dist/declarations/src/selector/string.d.ts +2 -0
  52. package/dist/declarations/src/source/file.d.ts +23 -0
  53. package/dist/declarations/src/source/i18n.d.ts +29 -0
  54. package/dist/declarations/src/source/index.d.ts +33 -0
  55. package/dist/declarations/src/source/remote.d.ts +29 -0
  56. package/dist/declarations/src/val/array.d.ts +9 -0
  57. package/dist/declarations/src/val/index.d.ts +53 -0
  58. package/dist/declarations/src/val/object.d.ts +9 -0
  59. package/dist/declarations/src/val/primitive.d.ts +7 -0
  60. package/dist/index-2f1631cf.cjs.prod.js +1031 -0
  61. package/dist/index-55916dcd.esm.js +1000 -0
  62. package/dist/index-b49a2c60.cjs.dev.js +1031 -0
  63. package/dist/ops-6fae92a1.esm.js +12 -0
  64. package/dist/ops-87cdbafc.cjs.dev.js +14 -0
  65. package/dist/ops-ae4d1bc2.cjs.prod.js +14 -0
  66. package/dist/result-26f67b40.cjs.prod.js +299 -0
  67. package/dist/result-48320acd.cjs.dev.js +299 -0
  68. package/dist/result-b96df128.esm.js +279 -0
  69. package/dist/util-030d8a1f.cjs.prod.js +29 -0
  70. package/dist/util-18613e99.esm.js +26 -0
  71. package/dist/util-b213092b.cjs.dev.js +29 -0
  72. package/dist/valbuild-core.cjs.d.ts +2 -0
  73. package/dist/valbuild-core.cjs.d.ts.map +1 -0
  74. package/dist/valbuild-core.cjs.dev.js +1276 -0
  75. package/dist/valbuild-core.cjs.js +7 -0
  76. package/dist/valbuild-core.cjs.prod.js +1276 -0
  77. package/dist/valbuild-core.esm.js +1265 -0
  78. package/expr/dist/valbuild-core-expr.cjs.d.ts +2 -0
  79. package/expr/dist/valbuild-core-expr.cjs.d.ts.map +1 -0
  80. package/expr/dist/valbuild-core-expr.cjs.dev.js +18 -0
  81. package/expr/dist/valbuild-core-expr.cjs.js +7 -0
  82. package/expr/dist/valbuild-core-expr.cjs.prod.js +18 -0
  83. package/expr/dist/valbuild-core-expr.esm.js +3 -0
  84. package/expr/package.json +4 -0
  85. package/fp/dist/valbuild-core-fp.cjs.d.ts +2 -0
  86. package/fp/dist/valbuild-core-fp.cjs.d.ts.map +1 -0
  87. package/fp/dist/valbuild-core-fp.cjs.dev.js +13 -0
  88. package/fp/dist/valbuild-core-fp.cjs.js +7 -0
  89. package/fp/dist/valbuild-core-fp.cjs.prod.js +13 -0
  90. package/fp/dist/valbuild-core-fp.esm.js +2 -0
  91. package/fp/package.json +4 -0
  92. package/package.json +43 -0
  93. package/patch/dist/valbuild-core-patch.cjs.d.ts +2 -0
  94. package/patch/dist/valbuild-core-patch.cjs.d.ts.map +1 -0
  95. package/patch/dist/valbuild-core-patch.cjs.dev.js +443 -0
  96. package/patch/dist/valbuild-core-patch.cjs.js +7 -0
  97. package/patch/dist/valbuild-core-patch.cjs.prod.js +443 -0
  98. package/patch/dist/valbuild-core-patch.esm.js +431 -0
  99. package/patch/package.json +4 -0
  100. package/tsconfig.json +7 -0
@@ -0,0 +1,2 @@
1
+ import { Selector as PrimitiveSelector } from "./primitive";
2
+ export type Selector<T extends string> = PrimitiveSelector<T>;
@@ -0,0 +1,23 @@
1
+ import { VAL_EXTENSION } from ".";
2
+ import { JsonPrimitive } from "../Json";
3
+ export declare const FILE_REF_PROP: "_ref";
4
+ /**
5
+ * A file source represents the path to a (local) file.
6
+ *
7
+ * It will be resolved into a Asset object.
8
+ *
9
+ */
10
+ export type FileSource<Metadata extends {
11
+ readonly [key: string]: JsonPrimitive;
12
+ } | undefined = {
13
+ readonly [key: string]: JsonPrimitive;
14
+ } | undefined> = {
15
+ readonly [FILE_REF_PROP]: string;
16
+ readonly [VAL_EXTENSION]: "file";
17
+ readonly metadata?: Metadata;
18
+ };
19
+ export declare function file<Metadata extends {
20
+ readonly [key: string]: JsonPrimitive;
21
+ }>(ref: string, metadata: Metadata): FileSource<Metadata>;
22
+ export declare function file(ref: string, metadata?: undefined): FileSource<undefined>;
23
+ export declare function isFile(obj: unknown): obj is FileSource;
@@ -0,0 +1,29 @@
1
+ import { F } from "ts-toolbelt";
2
+ import { SourcePrimitive, VAL_EXTENSION } from ".";
3
+ import { FileSource } from "./file";
4
+ /**
5
+ * I18n sources cannot have nested remote sources.
6
+ */
7
+ export type I18nCompatibleSource = SourcePrimitive | I18nObject | I18nArray | FileSource;
8
+ export type I18nObject = {
9
+ [key in string]: I18nCompatibleSource;
10
+ };
11
+ export type I18nArray = readonly I18nCompatibleSource[];
12
+ /**
13
+ * An i18n source is a map of locales to sources.
14
+ *
15
+ * Its selector will default to the underlying source. It is possible to call `.all` on i18n sources, which returns an object with all the locales
16
+ *
17
+ */
18
+ export type I18nSource<Locales extends readonly string[], T extends I18nCompatibleSource> = {
19
+ readonly [locale in Locales[number]]: T;
20
+ } & {
21
+ readonly [VAL_EXTENSION]: "i18n";
22
+ };
23
+ export type I18n<Locales extends readonly string[]> = <Src extends I18nCompatibleSource>(source: {
24
+ [locale in Locales[number]]: Src;
25
+ }) => I18nSource<Locales, Src>;
26
+ export declare function i18n<Locales extends readonly string[]>(locales: F.Narrow<Locales>): <Src extends I18nCompatibleSource>(source: {
27
+ [locale in Locales[number]]: Src;
28
+ }) => I18nSource<Locales, Src>;
29
+ export declare function isI18n(obj: unknown): obj is I18nSource<string[], I18nCompatibleSource>;
@@ -0,0 +1,33 @@
1
+ import { FileSource } from "./file";
2
+ import { I18nSource, I18nCompatibleSource } from "./i18n";
3
+ import { RemoteSource, RemoteCompatibleSource } from "./remote";
4
+ export type Source = SourcePrimitive | SourceObject | SourceArray | I18nSource<string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource;
5
+ export type SourceObject = {
6
+ [key in string]: Source;
7
+ } & {
8
+ fold?: never;
9
+ andThen?: never;
10
+ _ref?: never;
11
+ _type?: never;
12
+ val?: never;
13
+ valPath?: never;
14
+ };
15
+ export type SourceArray = readonly Source[];
16
+ export type SourcePrimitive = string | number | boolean | null;
17
+ export declare const VAL_EXTENSION: "_type";
18
+ export declare function getValExtension(source: Source): false | "" | 0 | "file" | "i18n" | "remote" | null | undefined;
19
+ /**
20
+ * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
21
+ *
22
+ * An example where this is useful is remote types, where the type of the remote source is known at compile time,
23
+ * but the value is not there before it is fetched.
24
+ *
25
+ * @example
26
+ * type Example<T> = string & PhantomType<T>;
27
+ *
28
+ **/
29
+ declare const PhantomType: unique symbol;
30
+ export type PhantomType<T> = {
31
+ [PhantomType]: T;
32
+ };
33
+ export {};
@@ -0,0 +1,29 @@
1
+ import { SourcePrimitive, VAL_EXTENSION, PhantomType } from ".";
2
+ import { RichText } from "../schema/richtext";
3
+ import { FileSource } from "./file";
4
+ import { I18nCompatibleSource, I18nSource } from "./i18n";
5
+ /**
6
+ * Remote sources cannot include other remote sources.
7
+ */
8
+ export type RemoteCompatibleSource = SourcePrimitive | RemoteObject | RemoteArray | RichText | FileSource | I18nSource<string[], I18nCompatibleSource>;
9
+ export type RemoteObject = {
10
+ [key in string]: RemoteCompatibleSource;
11
+ };
12
+ export type RemoteArray = readonly RemoteCompatibleSource[];
13
+ export declare const REMOTE_REF_PROP: "_ref";
14
+ declare const brand: unique symbol;
15
+ export type RemoteRef = string & {
16
+ readonly [brand]: "RemoteRef";
17
+ };
18
+ /**
19
+ * A remote source is a hash that represents a remote object.
20
+ *
21
+ * It will be resolved into a ValRemote object.
22
+ */
23
+ export type RemoteSource<Src extends RemoteCompatibleSource> = {
24
+ readonly [REMOTE_REF_PROP]: RemoteRef;
25
+ readonly [VAL_EXTENSION]: "remote";
26
+ } & PhantomType<Src>;
27
+ export declare function remote<Src extends RemoteCompatibleSource>(ref: string): RemoteSource<Src>;
28
+ export declare function isRemote(obj: unknown): obj is RemoteSource<RemoteCompatibleSource>;
29
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SourcePath, Val as UnknownVal } from ".";
2
+ import { JsonArray } from "../Json";
3
+ import { Path } from "../selector";
4
+ export type Val<T extends JsonArray> = {
5
+ readonly [key in keyof T]: UnknownVal<T[key]>;
6
+ } & {
7
+ readonly [Path]: SourcePath | undefined;
8
+ readonly val: T;
9
+ };
@@ -0,0 +1,53 @@
1
+ import { Source, SourceArray, SourceObject } from "../source";
2
+ import { Val as ObjectVal } from "./object";
3
+ import { Val as ArrayVal } from "./array";
4
+ import { Val as PrimitiveVal } from "./primitive";
5
+ import { Json, JsonArray, JsonObject, JsonPrimitive } from "../Json";
6
+ import { Path, Selector } from "../selector";
7
+ import { I18nSource } from "../source/i18n";
8
+ import { RemoteSource } from "../source/remote";
9
+ import { FileSource } from "../source/file";
10
+ export type SerializedVal = {
11
+ val: SerializedVal | Json;
12
+ valPath: SourcePath | undefined;
13
+ };
14
+ export declare function isSerializedVal(val: unknown): val is SerializedVal;
15
+ export type JsonOfSource<T extends Source> = Json extends T ? Json : T extends I18nSource<readonly string[], infer U> ? JsonOfSource<U> : T extends RemoteSource<infer U> ? JsonOfSource<U> : T extends FileSource ? {
16
+ url: string;
17
+ } : T extends SourceObject ? {
18
+ [key in keyof T]: JsonOfSource<T[key]>;
19
+ } : T extends SourceArray ? JsonOfSource<T[number]>[] : T extends JsonPrimitive ? T : never;
20
+ export type Val<T extends Json> = Json extends T ? {
21
+ readonly [Path]: SourcePath | undefined;
22
+ readonly val: Source;
23
+ } : T extends JsonObject ? ObjectVal<T> : T extends JsonArray ? ArrayVal<T> : T extends JsonPrimitive ? PrimitiveVal<T> : never;
24
+ declare const brand: unique symbol;
25
+ /**
26
+ * The path of the source value.
27
+ *
28
+ * @example
29
+ * '/app/blogs.0.text' // the text property of the first element of the /app/blogs module
30
+ */
31
+ export type SourcePath = string & {
32
+ [brand]: "SourcePath";
33
+ };
34
+ /**
35
+ * The path inside the module.
36
+ *
37
+ * @example
38
+ * '0."text"' // the text property of the first element of the module
39
+ */
40
+ export type ModulePath = string & {
41
+ [brand]: "ModulePath";
42
+ };
43
+ /**
44
+ * The id of the module.
45
+ *
46
+ * @example
47
+ * '/app/blogs' // the /app/blogs module
48
+ */
49
+ export type ModuleId = string & {
50
+ [brand]: "ModuleId";
51
+ };
52
+ export declare function getValPath(valOrSelector: Val<Json> | Selector<Source>): SourcePath | undefined;
53
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SourcePath, Val as UnknownVal } from ".";
2
+ import { JsonObject } from "../Json";
3
+ import { Path } from "../selector";
4
+ export type Val<T extends JsonObject> = Omit<{
5
+ readonly [key in keyof T]: UnknownVal<T[key]>;
6
+ }, "valPath" | "val"> & {
7
+ readonly [Path]: SourcePath | undefined;
8
+ readonly val: T;
9
+ };
@@ -0,0 +1,7 @@
1
+ import { SourcePath } from ".";
2
+ import { JsonPrimitive } from "../Json";
3
+ import { Path } from "../selector";
4
+ export type Val<T extends JsonPrimitive> = {
5
+ [Path]: SourcePath | undefined;
6
+ val: T;
7
+ };