@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,116 @@
1
+ 'use strict';
2
+
3
+ var result = require('./result-48320acd.cjs.dev.js');
4
+
5
+ function _toPrimitive(input, hint) {
6
+ if (typeof input !== "object" || input === null) return input;
7
+ var prim = input[Symbol.toPrimitive];
8
+ if (prim !== undefined) {
9
+ var res = prim.call(input, hint || "default");
10
+ if (typeof res !== "object") return res;
11
+ throw new TypeError("@@toPrimitive must return a primitive value.");
12
+ }
13
+ return (hint === "string" ? String : Number)(input);
14
+ }
15
+
16
+ function _toPropertyKey(arg) {
17
+ var key = _toPrimitive(arg, "string");
18
+ return typeof key === "symbol" ? key : String(key);
19
+ }
20
+
21
+ function _arrayWithoutHoles(arr) {
22
+ if (Array.isArray(arr)) return result._arrayLikeToArray(arr);
23
+ }
24
+
25
+ function _iterableToArray(iter) {
26
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
+ }
28
+
29
+ function _nonIterableSpread() {
30
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
31
+ }
32
+
33
+ function _toConsumableArray(arr) {
34
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || result._unsupportedIterableToArray(arr) || _nonIterableSpread();
35
+ }
36
+
37
+ function _typeof(obj) {
38
+ "@babel/helpers - typeof";
39
+
40
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
41
+ return typeof obj;
42
+ } : function (obj) {
43
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
44
+ }, _typeof(obj);
45
+ }
46
+
47
+ function _arrayWithHoles(arr) {
48
+ if (Array.isArray(arr)) return arr;
49
+ }
50
+
51
+ function _iterableToArrayLimit(arr, i) {
52
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (null != _i) {
54
+ var _s,
55
+ _e,
56
+ _x,
57
+ _r,
58
+ _arr = [],
59
+ _n = !0,
60
+ _d = !1;
61
+ try {
62
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
63
+ if (Object(_i) !== _i) return;
64
+ _n = !1;
65
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
66
+ } catch (err) {
67
+ _d = !0, _e = err;
68
+ } finally {
69
+ try {
70
+ if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
71
+ } finally {
72
+ if (_d) throw _e;
73
+ }
74
+ }
75
+ return _arr;
76
+ }
77
+ }
78
+
79
+ function _nonIterableRest() {
80
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
81
+ }
82
+
83
+ function _slicedToArray(arr, i) {
84
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || result._unsupportedIterableToArray(arr, i) || _nonIterableRest();
85
+ }
86
+
87
+ function _classCallCheck(instance, Constructor) {
88
+ if (!(instance instanceof Constructor)) {
89
+ throw new TypeError("Cannot call a class as a function");
90
+ }
91
+ }
92
+
93
+ function _defineProperties(target, props) {
94
+ for (var i = 0; i < props.length; i++) {
95
+ var descriptor = props[i];
96
+ descriptor.enumerable = descriptor.enumerable || false;
97
+ descriptor.configurable = true;
98
+ if ("value" in descriptor) descriptor.writable = true;
99
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
100
+ }
101
+ }
102
+ function _createClass(Constructor, protoProps, staticProps) {
103
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
104
+ if (staticProps) _defineProperties(Constructor, staticProps);
105
+ Object.defineProperty(Constructor, "prototype", {
106
+ writable: false
107
+ });
108
+ return Constructor;
109
+ }
110
+
111
+ exports._classCallCheck = _classCallCheck;
112
+ exports._createClass = _createClass;
113
+ exports._slicedToArray = _slicedToArray;
114
+ exports._toConsumableArray = _toConsumableArray;
115
+ exports._toPropertyKey = _toPropertyKey;
116
+ exports._typeof = _typeof;
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ var result = require('./result-26f67b40.cjs.prod.js');
4
+
5
+ function _toPrimitive(input, hint) {
6
+ if (typeof input !== "object" || input === null) return input;
7
+ var prim = input[Symbol.toPrimitive];
8
+ if (prim !== undefined) {
9
+ var res = prim.call(input, hint || "default");
10
+ if (typeof res !== "object") return res;
11
+ throw new TypeError("@@toPrimitive must return a primitive value.");
12
+ }
13
+ return (hint === "string" ? String : Number)(input);
14
+ }
15
+
16
+ function _toPropertyKey(arg) {
17
+ var key = _toPrimitive(arg, "string");
18
+ return typeof key === "symbol" ? key : String(key);
19
+ }
20
+
21
+ function _arrayWithoutHoles(arr) {
22
+ if (Array.isArray(arr)) return result._arrayLikeToArray(arr);
23
+ }
24
+
25
+ function _iterableToArray(iter) {
26
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
+ }
28
+
29
+ function _nonIterableSpread() {
30
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
31
+ }
32
+
33
+ function _toConsumableArray(arr) {
34
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || result._unsupportedIterableToArray(arr) || _nonIterableSpread();
35
+ }
36
+
37
+ function _typeof(obj) {
38
+ "@babel/helpers - typeof";
39
+
40
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
41
+ return typeof obj;
42
+ } : function (obj) {
43
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
44
+ }, _typeof(obj);
45
+ }
46
+
47
+ function _arrayWithHoles(arr) {
48
+ if (Array.isArray(arr)) return arr;
49
+ }
50
+
51
+ function _iterableToArrayLimit(arr, i) {
52
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (null != _i) {
54
+ var _s,
55
+ _e,
56
+ _x,
57
+ _r,
58
+ _arr = [],
59
+ _n = !0,
60
+ _d = !1;
61
+ try {
62
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
63
+ if (Object(_i) !== _i) return;
64
+ _n = !1;
65
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
66
+ } catch (err) {
67
+ _d = !0, _e = err;
68
+ } finally {
69
+ try {
70
+ if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
71
+ } finally {
72
+ if (_d) throw _e;
73
+ }
74
+ }
75
+ return _arr;
76
+ }
77
+ }
78
+
79
+ function _nonIterableRest() {
80
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
81
+ }
82
+
83
+ function _slicedToArray(arr, i) {
84
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || result._unsupportedIterableToArray(arr, i) || _nonIterableRest();
85
+ }
86
+
87
+ function _classCallCheck(instance, Constructor) {
88
+ if (!(instance instanceof Constructor)) {
89
+ throw new TypeError("Cannot call a class as a function");
90
+ }
91
+ }
92
+
93
+ function _defineProperties(target, props) {
94
+ for (var i = 0; i < props.length; i++) {
95
+ var descriptor = props[i];
96
+ descriptor.enumerable = descriptor.enumerable || false;
97
+ descriptor.configurable = true;
98
+ if ("value" in descriptor) descriptor.writable = true;
99
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
100
+ }
101
+ }
102
+ function _createClass(Constructor, protoProps, staticProps) {
103
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
104
+ if (staticProps) _defineProperties(Constructor, staticProps);
105
+ Object.defineProperty(Constructor, "prototype", {
106
+ writable: false
107
+ });
108
+ return Constructor;
109
+ }
110
+
111
+ exports._classCallCheck = _classCallCheck;
112
+ exports._createClass = _createClass;
113
+ exports._slicedToArray = _slicedToArray;
114
+ exports._toConsumableArray = _toConsumableArray;
115
+ exports._toPropertyKey = _toPropertyKey;
116
+ exports._typeof = _typeof;
@@ -0,0 +1,6 @@
1
+ export type Json = JsonPrimitive | JsonObject | JsonArray;
2
+ export type JsonPrimitive = string | number | boolean | null;
3
+ export type JsonArray = readonly Json[];
4
+ export type JsonObject = {
5
+ readonly [key in string]: Json;
6
+ };
@@ -0,0 +1,19 @@
1
+ import { Expr } from "./expr";
2
+ import { Source } from "../source";
3
+ import { result } from "../fp";
4
+ import { Path, SourceOrExpr } from "../selector";
5
+ import { SourcePath } from "../val";
6
+ export declare class EvalError {
7
+ readonly message: string;
8
+ readonly expr: Expr;
9
+ constructor(message: string, expr: Expr);
10
+ toString(): string;
11
+ }
12
+ type LocalSelector<S extends Source> = {
13
+ readonly [key: string | number]: LocalSelector<Source> | ((...args: any[]) => any);
14
+ } & {
15
+ [SourceOrExpr]: S;
16
+ [Path]: SourcePath | undefined;
17
+ };
18
+ export declare function evaluate(expr: Expr, source: (ref: string) => LocalSelector<Source>, stack: readonly LocalSelector<Source>[][]): result.Result<LocalSelector<Source>, EvalError>;
19
+ export {};
@@ -0,0 +1,32 @@
1
+ export declare abstract class Expr {
2
+ readonly span?: [number, (number | undefined)?] | undefined;
3
+ abstract type: "StringLiteral" | "Sym" | "StringTemplate" | "Call";
4
+ abstract transpile(): string;
5
+ constructor(span?: [number, (number | undefined)?] | undefined);
6
+ }
7
+ export declare class StringLiteral extends Expr {
8
+ readonly value: string;
9
+ type: "StringLiteral";
10
+ constructor(value: string, span?: [start: number, stop: number]);
11
+ transpile(): string;
12
+ }
13
+ export declare class Sym extends Expr {
14
+ readonly value: string;
15
+ type: "Sym";
16
+ constructor(value: string, span?: [start: number, stop: number]);
17
+ transpile(): string;
18
+ }
19
+ export declare const NilSym: Sym;
20
+ export declare class StringTemplate extends Expr {
21
+ readonly children: readonly Expr[];
22
+ type: "StringTemplate";
23
+ constructor(children: readonly Expr[], span?: [number, number]);
24
+ transpile(): string;
25
+ }
26
+ export declare class Call extends Expr {
27
+ readonly children: readonly Expr[];
28
+ readonly isAnon: boolean;
29
+ type: "Call";
30
+ constructor(children: readonly Expr[], isAnon: boolean, span?: [number, number]);
31
+ transpile(): string;
32
+ }
@@ -0,0 +1,3 @@
1
+ export { parse } from "./parser";
2
+ export { Call, Expr, NilSym, StringLiteral, StringTemplate, Sym } from "./expr";
3
+ export { evaluate } from "./eval";
@@ -0,0 +1,8 @@
1
+ import { result } from "../fp";
2
+ import { Expr } from "./expr";
3
+ export declare class ParserError {
4
+ readonly message: string;
5
+ readonly span?: [number, (number | undefined)?] | undefined;
6
+ constructor(message: string, span?: [number, (number | undefined)?] | undefined);
7
+ }
8
+ export declare function parse(input: string): result.Result<Expr, ParserError>;
@@ -0,0 +1,7 @@
1
+ export type Token = {
2
+ readonly type: "!(" | "(" | ")" | "string" | "token" | "ws" | "${" | "}" | "'";
3
+ readonly span: [start: number, stop: number];
4
+ readonly value?: string;
5
+ readonly unescapedValue?: string;
6
+ };
7
+ export declare function tokenize(input: string): [tokens: Token[], endCursor: number];
@@ -0,0 +1,5 @@
1
+ import { GenericSelector, SelectorOf, SelectorSource } from "./selector";
2
+ import { JsonOfSource, Val } from "./val";
3
+ export declare function fetchVal<T extends SelectorSource>(selector: T, locale?: string): SelectorOf<T> extends GenericSelector<infer S> ? Promise<Val<JsonOfSource<S>>> : never;
4
+ export declare function getVal<T extends SelectorSource>(selector: T, locale?: string): SelectorOf<T> extends GenericSelector<infer S> ? Val<JsonOfSource<S>> : never;
5
+ export declare function serializedValOfSelectorSource<T extends SelectorSource>(selector: T): any;
@@ -0,0 +1,8 @@
1
+ export type NonEmptyArray<T> = [T, ...T[]];
2
+ export type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
3
+ export declare function isNonEmpty<T>(array: Array<T>): array is NonEmptyArray<T>;
4
+ export declare function flatten<T>(array: ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<T>>): NonEmptyArray<T>;
5
+ export declare function map<T, U>(fn: (value: T, index: number) => U): {
6
+ (array: ReadonlyArray<T>): Array<U>;
7
+ (array: ReadonlyNonEmptyArray<T>): NonEmptyArray<U>;
8
+ };
@@ -0,0 +1,3 @@
1
+ export * as result from "./result";
2
+ export * as array from "./array";
3
+ export * from "./util";
@@ -0,0 +1,67 @@
1
+ import { NonEmptyArray } from "./array";
2
+ export type Ok<T> = {
3
+ readonly kind: "ok";
4
+ readonly value: T;
5
+ };
6
+ export type Err<E> = {
7
+ readonly kind: "err";
8
+ readonly error: E;
9
+ };
10
+ export type Result<T, E> = Ok<T> | Err<E>;
11
+ /**
12
+ * Singleton instance of Ok<void>. Used to optimize results whose Ok values are
13
+ * void.
14
+ */
15
+ export declare const voidOk: Ok<void>;
16
+ export declare function ok<T>(value: T): Ok<T>;
17
+ export declare function err<E>(error: E): Err<E>;
18
+ export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
19
+ export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
20
+ export type OkType<R> = R extends Result<infer T, unknown> ? T : never;
21
+ export type ErrType<R> = R extends Result<unknown, infer E> ? E : never;
22
+ /**
23
+ * If all results are Ok (or if results is empty), returns Ok with all the Ok
24
+ * values concatenated into an array. If any result is Err, returns Err with all
25
+ * Err values concatenated into an array.
26
+ *
27
+ * @see {@link all} for use with simple array types.
28
+ */
29
+ export declare function allT<T extends unknown[], E>(results: {
30
+ readonly [P in keyof T]: Result<T[P], E>;
31
+ }): Result<T, NonEmptyArray<E>>;
32
+ /**
33
+ * If all results are Ok (or if results is empty), returns Ok with all the Ok
34
+ * values concatenated into an array. If any result is Err, returns Err with all
35
+ * Err values concatenated into an array.
36
+ *
37
+ * @see {@link allT} for use with tuple types.
38
+ */
39
+ export declare function all<T, E>(results: readonly Result<T, E>[]): Result<T[], NonEmptyArray<E>>;
40
+ /**
41
+ * If all results are Ok (or if results is empty), returns Ok. If any result is
42
+ * Err, returns Err with all Err values concatenated into an array.
43
+ */
44
+ export declare function allV<E>(results: readonly Result<unknown, E>[]): Result<void, NonEmptyArray<E>>;
45
+ /**
46
+ * Perform a reduction over an array with a Result-returning reducer. If the
47
+ * reducer returns Ok, its value is used as the next value. If the reducer
48
+ * returns Err, it is returned immediately.
49
+ *
50
+ * flatMapReduce is a short-circuiting equivalent to:
51
+ * ```
52
+ * arr.reduce(
53
+ * (accRes, current, currentIndex) =>
54
+ * flatMap((acc) => reducer(acc, current, currentIndex))(accRes),
55
+ * ok(initVal)
56
+ * )
57
+ * ```
58
+ */
59
+ export declare function flatMapReduce<T, E, A>(reducer: (acc: T, current: A, currentIndex: number) => Result<T, E>, initVal: T): (arr: readonly A[]) => Result<T, E>;
60
+ export declare function map<T0, T1>(onOk: (value: T0) => T1): <E>(result: Result<T0, E>) => Result<T1, E>;
61
+ export declare function flatMap<T0, T1, E1>(onOk: (value: T0) => Result<T1, E1>): <E>(result: Result<T0, E>) => Result<T1, E | E1>;
62
+ export declare function mapErr<E0, E1>(onErr: (error: E0) => E1): <T>(result: Result<T, E0>) => Result<T, E1>;
63
+ export declare function fromPredicate<T0, T1 extends T0, E>(refinement: (value: T0) => value is T1, onFalse: (value: T0) => E): (value: T0) => Result<T1, E>;
64
+ export declare const filterOrElse: {
65
+ <T0, T1 extends T0, E>(refinement: (value: T0) => value is T1, onFalse: (value: T0) => E): (result: Result<T0, E>) => Result<T1, E>;
66
+ <T0, E>(refinement: (value: T0) => boolean, onFalse: (value: T0) => E): <T1 extends T0>(result: Result<T1, E>) => Result<T1, E>;
67
+ };
@@ -0,0 +1,12 @@
1
+ export declare function pipe<A>(a: A): A;
2
+ export declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
3
+ export declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
4
+ export declare function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
5
+ export declare function pipe<A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
6
+ export declare function pipe<A, B, C, D, E, F>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
7
+ export declare function pipe<A, B, C, D, E, F, G>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G;
8
+ /**
9
+ * Runs the callback with the supplied value, then returns the value. Useful for
10
+ * debugging pipes.
11
+ */
12
+ export declare function tap<T>(callback: (value: T) => void): (value: T) => T;
@@ -0,0 +1,32 @@
1
+ export { initVal } from "./initVal";
2
+ export { fetchVal } from "./fetchVal";
3
+ export type { InitVal } from "./initVal";
4
+ export { Schema, type SerializedSchema } from "./schema";
5
+ export type { ValModule, SerializedModule } from "./module";
6
+ export type { SourceObject, SourcePrimitive, Source } from "./source";
7
+ export type { FileSource } from "./source/file";
8
+ export type { RemoteSource } from "./source/remote";
9
+ export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, } from "./val";
10
+ export * as expr from "./expr/";
11
+ export { FILE_REF_PROP } from "./source/file";
12
+ export { VAL_EXTENSION } from "./source";
13
+ export { derefPatch } from "./patch/deref";
14
+ export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector";
15
+ import { getVal } from "./fetchVal";
16
+ import { getRawSource, resolvePath, splitModuleIdAndModulePath } from "./module";
17
+ import { getSchema } from "./selector";
18
+ import { getValPath } from "./val";
19
+ export type { RichText, TextNode, ParagraphNode, HeadingNode, ImageNode, ListItemNode, ListNode, RootNode, } from "./schema/richtext";
20
+ declare const Internal: {
21
+ convertImageSource: (src: import("./source/file").FileSource<import("./schema/image").ImageMetadata>) => {
22
+ url: string;
23
+ metadata?: import("./schema/image").ImageMetadata;
24
+ };
25
+ getSchema: typeof getSchema;
26
+ getValPath: typeof getValPath;
27
+ getVal: typeof getVal;
28
+ getRawSource: typeof getRawSource;
29
+ resolvePath: typeof resolvePath;
30
+ splitModuleIdAndModulePath: typeof splitModuleIdAndModulePath;
31
+ };
32
+ export { Internal };
@@ -0,0 +1,57 @@
1
+ import { F } from "ts-toolbelt";
2
+ import { array } from "./schema/array";
3
+ import { number } from "./schema/number";
4
+ import { object } from "./schema/object";
5
+ import { string } from "./schema/string";
6
+ import { boolean } from "./schema/boolean";
7
+ import { oneOf } from "./schema/oneOf";
8
+ import { union } from "./schema/union";
9
+ import { I18n } from "./schema/i18n";
10
+ import { richtext } from "./schema/richtext";
11
+ import { image } from "./schema/image";
12
+ import { literal } from "./schema/literal";
13
+ export type InitSchema = {
14
+ readonly string: typeof string;
15
+ readonly boolean: typeof boolean;
16
+ readonly array: typeof array;
17
+ readonly object: typeof object;
18
+ readonly number: typeof number;
19
+ readonly union: typeof union;
20
+ readonly oneOf: typeof oneOf;
21
+ readonly richtext: typeof richtext;
22
+ readonly image: typeof image;
23
+ readonly literal: typeof literal;
24
+ };
25
+ export type InitSchemaLocalized<Locales extends readonly string[]> = {
26
+ readonly i18n: I18n<Locales>;
27
+ };
28
+ export declare function initSchema<Locales extends readonly string[]>(locales: F.Narrow<Locales>): {
29
+ string: <T extends string>(options?: {
30
+ maxLength?: number | undefined;
31
+ minLength?: number | undefined;
32
+ } | undefined) => import("./schema").Schema<T>;
33
+ boolean: () => import("./schema").Schema<boolean>;
34
+ array: <S extends import("./schema").Schema<import("./selector").SelectorSource>>(schema: S) => import("./schema").Schema<import("./schema").SchemaTypeOf<S>[]>;
35
+ object: <Props extends {
36
+ [key: string]: import("./schema").Schema<import("./selector").SelectorSource>;
37
+ }>(schema: Props) => import("./schema").Schema<{ [key in keyof Props]: import("./schema").SchemaTypeOf<Props[key]>; }>;
38
+ number: (options?: {
39
+ max?: number | undefined;
40
+ min?: number | undefined;
41
+ } | undefined) => import("./schema").Schema<number>;
42
+ union: <Key extends string, T_1 extends import("./schema").Schema<{
43
+ [x: string]: import("./source").Source;
44
+ } & {
45
+ fold?: undefined;
46
+ andThen?: undefined;
47
+ _ref?: undefined;
48
+ _type?: undefined;
49
+ val?: undefined;
50
+ valPath?: undefined;
51
+ } & { [k in Key]: string; }>[]>(key: Key, ...objects: T_1) => import("./schema").Schema<T_1 extends import("./schema").Schema<infer S_1 extends import("./selector").SelectorSource>[] ? S_1 extends import("./selector").SelectorSource ? S_1 : never : never>;
52
+ oneOf: <Src extends import("./selector").GenericSelector<import("./source").SourceArray, undefined> & import("./module").ValModuleBrand>(valModule: Src) => import("./schema").Schema<Src extends import("./selector").GenericSelector<infer S_2 extends import("./source").Source, undefined> ? S_2 extends (infer IS)[] ? IS extends import("./source").Source ? import("./selector").GenericSelector<IS, undefined> : never : never : never>;
53
+ richtext: () => import("./schema").Schema<import("./schema/richtext").RichText<"h1" | "h2" | "h3" | "h4" | "h5" | "h6", import("./schema/richtext").TextNode>>;
54
+ image: (options?: import("./schema/image").ImageOptions | undefined) => import("./schema").Schema<import(".").FileSource<import("./schema/image").ImageMetadata>>;
55
+ literal: <T_2 extends string>(value: T_2) => import("./schema").Schema<T_2>;
56
+ i18n: <S_3 extends import("./schema").Schema<import("./source/i18n").I18nCompatibleSource>>(schema: S_3) => import("./schema").Schema<import("./source/i18n").I18nSource<import("ts-toolbelt/out/Any/Try").Try<Locales, [], (Locales extends [] ? [] : never) | (Locales extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? Locales : never) | { [K in keyof Locales]: Locales[K] extends Function ? Locales[K] : (Locales[K] extends infer T_3 ? T_3 extends Locales[K] ? T_3 extends [] ? [] : never : never : never) | (Locales[K] extends infer T_4 ? T_4 extends Locales[K] ? T_4 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_4 : never : never : never) | (Locales[K] extends infer T_5 ? { [K_1 in keyof T_5]: Locales[K][K_1] extends Function ? Locales[K][K_1] : (Locales[K][K_1] extends infer T_6 ? T_6 extends Locales[K][K_1] ? T_6 extends [] ? [] : never : never : never) | (Locales[K][K_1] extends infer T_7 ? T_7 extends Locales[K][K_1] ? T_7 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_7 : never : never : never) | (Locales[K][K_1] extends infer T_8 ? { [K_2 in keyof T_8]: Locales[K][K_1][K_2] extends Function ? Locales[K][K_1][K_2] : (Locales[K][K_1][K_2] extends infer T_9 ? T_9 extends Locales[K][K_1][K_2] ? T_9 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2] extends infer T_10 ? T_10 extends Locales[K][K_1][K_2] ? T_10 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_10 : never : never : never) | (Locales[K][K_1][K_2] extends infer T_11 ? { [K_3 in keyof T_11]: Locales[K][K_1][K_2][K_3] extends Function ? Locales[K][K_1][K_2][K_3] : (Locales[K][K_1][K_2][K_3] extends infer T_12 ? T_12 extends Locales[K][K_1][K_2][K_3] ? T_12 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3] extends infer T_13 ? T_13 extends Locales[K][K_1][K_2][K_3] ? T_13 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_13 : never : never : never) | (Locales[K][K_1][K_2][K_3] extends infer T_14 ? { [K_4 in keyof T_14]: Locales[K][K_1][K_2][K_3][K_4] extends Function ? Locales[K][K_1][K_2][K_3][K_4] : (Locales[K][K_1][K_2][K_3][K_4] extends infer T_15 ? T_15 extends Locales[K][K_1][K_2][K_3][K_4] ? T_15 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4] extends infer T_16 ? T_16 extends Locales[K][K_1][K_2][K_3][K_4] ? T_16 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_16 : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4] extends infer T_17 ? { [K_5 in keyof T_17]: Locales[K][K_1][K_2][K_3][K_4][K_5] extends Function ? Locales[K][K_1][K_2][K_3][K_4][K_5] : (Locales[K][K_1][K_2][K_3][K_4][K_5] extends infer T_18 ? T_18 extends Locales[K][K_1][K_2][K_3][K_4][K_5] ? T_18 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5] extends infer T_19 ? T_19 extends Locales[K][K_1][K_2][K_3][K_4][K_5] ? T_19 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_19 : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5] extends infer T_20 ? { [K_6 in keyof T_20]: Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] extends Function ? Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] : (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] extends infer T_21 ? T_21 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] ? T_21 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] extends infer T_22 ? T_22 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] ? T_22 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_22 : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6] extends infer T_23 ? { [K_7 in keyof T_23]: Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] extends Function ? Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] : (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] extends infer T_24 ? T_24 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] ? T_24 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] extends infer T_25 ? T_25 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] ? T_25 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_25 : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7] extends infer T_26 ? { [K_8 in keyof T_26]: Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] extends Function ? Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] : (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] extends infer T_27 ? T_27 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] ? T_27 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] extends infer T_28 ? T_28 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] ? T_28 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_28 : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8] extends infer T_29 ? { [K_9 in keyof T_29]: Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] extends Function ? Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] : (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] extends infer T_30 ? T_30 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] ? T_30 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] extends infer T_31 ? T_31 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] ? T_31 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_31 : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9] extends infer T_32 ? { [K_10 in keyof T_32]: Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9][K_10] extends Function ? Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9][K_10] : (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9][K_10] extends infer T_33 ? T_33 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9][K_10] ? T_33 extends [] ? [] : never : never : never) | (Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9][K_10] extends infer T_34 ? T_34 extends Locales[K][K_1][K_2][K_3][K_4][K_5][K_6][K_7][K_8][K_9][K_10] ? T_34 extends import("ts-toolbelt/out/Function/_Internal").Narrowable ? T_34 : never : never : never) | any; } : never); } : never); } : never); } : never); } : never); } : never); } : never); } : never); } : never); } : never); }>, import("./schema").SchemaTypeOf<S_3>>>;
57
+ };
@@ -0,0 +1,39 @@
1
+ import { content } from "./module";
2
+ import { I18n } from "./source/i18n";
3
+ import { InitSchema, InitSchemaLocalized } from "./initSchema";
4
+ import { SelectorOf } from "./selector";
5
+ import { getValPath as getPath, Val } from "./val";
6
+ import { SelectorSource, GenericSelector } from "./selector";
7
+ import { JsonOfSource } from "./val";
8
+ import { remote } from "./source/remote";
9
+ import { file } from "./source/file";
10
+ type ValConstructor = {
11
+ content: typeof content;
12
+ getPath: typeof getPath;
13
+ key: typeof getPath;
14
+ remote: typeof remote;
15
+ file: typeof file;
16
+ };
17
+ export type InitVal<Locales extends readonly string[] | undefined> = [
18
+ Locales
19
+ ] extends [readonly string[]] ? {
20
+ val: ValConstructor & {
21
+ i18n: I18n<Locales>;
22
+ };
23
+ fetchVal<T extends SelectorSource>(selector: T, locale: Locales[number]): SelectorOf<T> extends GenericSelector<infer S> ? Promise<Val<JsonOfSource<S>>> : never;
24
+ s: InitSchema & InitSchemaLocalized<Locales>;
25
+ } : {
26
+ val: ValConstructor;
27
+ fetchVal<T extends SelectorSource>(selector: T): SelectorOf<T> extends GenericSelector<infer S> ? Promise<Val<JsonOfSource<S>>> : never;
28
+ s: InitSchema;
29
+ };
30
+ type NarrowStrings<A> = (A extends [] ? [] : never) | (A extends string ? A : never) | {
31
+ [K in keyof A]: NarrowStrings<A[K]>;
32
+ };
33
+ export declare const initVal: <Locales extends readonly string[] | undefined>(options?: {
34
+ readonly locales?: {
35
+ readonly required: NarrowStrings<Locales>;
36
+ readonly fallback: NarrowStrings<Locales extends readonly string[] ? Locales[number] : never>;
37
+ } | undefined;
38
+ } | undefined) => InitVal<Locales>;
39
+ export {};
@@ -0,0 +1,38 @@
1
+ import { Schema, SchemaTypeOf, SerializedSchema } from "./schema";
2
+ import { GenericSelector, SelectorOf, SelectorSource } from "./selector";
3
+ import { Source } from "./source";
4
+ import { ModuleId, ModulePath, SourcePath } from "./val";
5
+ import { Json } from "./Json";
6
+ import { RichText, SerializedRichTextSchema } from "./schema/richtext";
7
+ import { ImageMetadata, ImageSchema, SerializedImageSchema } from "./schema/image";
8
+ import { FileSource } from "./source/file";
9
+ declare const brand: unique symbol;
10
+ export type ValModule<T extends SelectorSource> = SelectorOf<T> & ValModuleBrand;
11
+ export type ValModuleBrand = {
12
+ [brand]: "ValModule";
13
+ };
14
+ export type TypeOfValModule<T extends ValModule<SelectorSource>> = T extends GenericSelector<infer S> ? S : never;
15
+ export declare function content<T extends Schema<SelectorSource>>(id: string, schema: T, source: SchemaTypeOf<T>): ValModule<SchemaTypeOf<T>>;
16
+ export declare function getRawSource(valModule: ValModule<SelectorSource>): Source;
17
+ export declare function splitModuleIdAndModulePath(path: SourcePath): [moduleId: ModuleId, path: ModulePath];
18
+ export declare function getSourceAtPath(modulePath: ModulePath, valModule: ValModule<SelectorSource> | Source): any;
19
+ export declare function resolvePath(path: ModulePath, valModule: ValModule<SelectorSource> | Source, schema: Schema<SelectorSource> | SerializedSchema): {
20
+ path: string;
21
+ schema: SerializedImageSchema | ImageSchema<FileSource<ImageMetadata> | null>;
22
+ source: any;
23
+ } | {
24
+ path: string;
25
+ schema: SerializedRichTextSchema | Schema<RichText<"h1" | "h2" | "h3" | "h4" | "h5" | "h6", import("./schema/richtext").TextNode>>;
26
+ source: any;
27
+ } | {
28
+ path: ModulePath;
29
+ schema: Schema<SelectorSource> | SerializedSchema;
30
+ source: any;
31
+ };
32
+ export declare function parsePath(input: ModulePath): string[];
33
+ export type SerializedModule = {
34
+ source: Json;
35
+ schema: SerializedSchema;
36
+ path: SourcePath;
37
+ };
38
+ export {};
@@ -0,0 +1,13 @@
1
+ import { result } from "../fp";
2
+ import { Ops, PatchError } from "./ops";
3
+ import { Patch } from "./patch";
4
+ export type DerefPatchResult = {
5
+ dereferencedPatch: Patch;
6
+ fileUpdates: {
7
+ [path: string]: string;
8
+ };
9
+ remotePatches: {
10
+ [ref: string]: Patch;
11
+ };
12
+ };
13
+ export declare function derefPatch<D, E>(patch: Patch, document: D, ops: Ops<D, E>): result.Result<DerefPatchResult, E | PatchError>;
@@ -0,0 +1,6 @@
1
+ export { JSONOps } from "./json";
2
+ export { type OperationJSON, type Operation } from "./operation";
3
+ export { parsePatch, parseJSONPointer, formatJSONPointer } from "./parse";
4
+ export { type JSONValue, type Ops, PatchError } from "./ops";
5
+ export { type PatchJSON, type Patch, applyPatch } from "./patch";
6
+ export { isNotRoot, deepEqual, deepClone, parseAndValidateArrayIndex, } from "./util";
@@ -0,0 +1,11 @@
1
+ import { result, array } from "../fp/";
2
+ import { JSONValue, Ops, PatchError } from "./ops";
3
+ export declare class JSONOps implements Ops<JSONValue, never> {
4
+ get(document: JSONValue, path: string[]): result.Result<JSONValue, PatchError>;
5
+ add(document: JSONValue, path: string[], value: JSONValue): result.Result<JSONValue, PatchError>;
6
+ remove(document: JSONValue, path: array.NonEmptyArray<string>): result.Result<JSONValue, PatchError>;
7
+ replace(document: JSONValue, path: string[], value: JSONValue): result.Result<JSONValue, PatchError>;
8
+ move(document: JSONValue, from: array.NonEmptyArray<string>, path: string[]): result.Result<JSONValue, PatchError>;
9
+ copy(document: JSONValue, from: string[], path: string[]): result.Result<JSONValue, PatchError>;
10
+ test(document: JSONValue, path: string[], value: JSONValue): result.Result<boolean, PatchError>;
11
+ }