@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,12 @@
|
|
1
|
+
import { a as _createClass, _ as _classCallCheck } from './createClass-012eebbf.esm.js';
|
2
|
+
|
3
|
+
var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
4
|
+
_classCallCheck(this, PatchError);
|
5
|
+
this.message = message;
|
6
|
+
});
|
7
|
+
|
8
|
+
/**
|
9
|
+
* NOTE: MAY mutate the input document.
|
10
|
+
*/
|
11
|
+
|
12
|
+
export { PatchError as P };
|
@@ -0,0 +1,14 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var createClass = require('./createClass-a436dbfe.cjs.dev.js');
|
4
|
+
|
5
|
+
var PatchError = /*#__PURE__*/createClass._createClass(function PatchError(message) {
|
6
|
+
createClass._classCallCheck(this, PatchError);
|
7
|
+
this.message = message;
|
8
|
+
});
|
9
|
+
|
10
|
+
/**
|
11
|
+
* NOTE: MAY mutate the input document.
|
12
|
+
*/
|
13
|
+
|
14
|
+
exports.PatchError = PatchError;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var createClass = require('./createClass-de7426aa.cjs.prod.js');
|
4
|
+
|
5
|
+
var PatchError = /*#__PURE__*/createClass._createClass(function PatchError(message) {
|
6
|
+
createClass._classCallCheck(this, PatchError);
|
7
|
+
this.message = message;
|
8
|
+
});
|
9
|
+
|
10
|
+
/**
|
11
|
+
* NOTE: MAY mutate the input document.
|
12
|
+
*/
|
13
|
+
|
14
|
+
exports.PatchError = PatchError;
|
@@ -0,0 +1,299 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
function _arrayLikeToArray(arr, len) {
|
4
|
+
if (len == null || len > arr.length) len = arr.length;
|
5
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
6
|
+
return arr2;
|
7
|
+
}
|
8
|
+
|
9
|
+
function _unsupportedIterableToArray(o, minLen) {
|
10
|
+
if (!o) return;
|
11
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
12
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
13
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
14
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
15
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
16
|
+
}
|
17
|
+
|
18
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
19
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
20
|
+
if (!it) {
|
21
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
22
|
+
if (it) o = it;
|
23
|
+
var i = 0;
|
24
|
+
var F = function () {};
|
25
|
+
return {
|
26
|
+
s: F,
|
27
|
+
n: function () {
|
28
|
+
if (i >= o.length) return {
|
29
|
+
done: true
|
30
|
+
};
|
31
|
+
return {
|
32
|
+
done: false,
|
33
|
+
value: o[i++]
|
34
|
+
};
|
35
|
+
},
|
36
|
+
e: function (e) {
|
37
|
+
throw e;
|
38
|
+
},
|
39
|
+
f: F
|
40
|
+
};
|
41
|
+
}
|
42
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
43
|
+
}
|
44
|
+
var normalCompletion = true,
|
45
|
+
didErr = false,
|
46
|
+
err;
|
47
|
+
return {
|
48
|
+
s: function () {
|
49
|
+
it = it.call(o);
|
50
|
+
},
|
51
|
+
n: function () {
|
52
|
+
var step = it.next();
|
53
|
+
normalCompletion = step.done;
|
54
|
+
return step;
|
55
|
+
},
|
56
|
+
e: function (e) {
|
57
|
+
didErr = true;
|
58
|
+
err = e;
|
59
|
+
},
|
60
|
+
f: function () {
|
61
|
+
try {
|
62
|
+
if (!normalCompletion && it.return != null) it.return();
|
63
|
+
} finally {
|
64
|
+
if (didErr) throw err;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
function isNonEmpty(array) {
|
71
|
+
return array.length > 0;
|
72
|
+
}
|
73
|
+
function flatten(array) {
|
74
|
+
return array.flat(1);
|
75
|
+
}
|
76
|
+
function map$1(fn) {
|
77
|
+
function mapFn(array) {
|
78
|
+
return array.map(fn);
|
79
|
+
}
|
80
|
+
return mapFn;
|
81
|
+
}
|
82
|
+
|
83
|
+
var array = /*#__PURE__*/Object.freeze({
|
84
|
+
__proto__: null,
|
85
|
+
isNonEmpty: isNonEmpty,
|
86
|
+
flatten: flatten,
|
87
|
+
map: map$1
|
88
|
+
});
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Singleton instance of Ok<void>. Used to optimize results whose Ok values are
|
92
|
+
* void.
|
93
|
+
*/
|
94
|
+
var voidOk = Object.freeze({
|
95
|
+
kind: "ok",
|
96
|
+
value: undefined
|
97
|
+
});
|
98
|
+
function ok(value) {
|
99
|
+
if (value === undefined) return voidOk;
|
100
|
+
return {
|
101
|
+
kind: "ok",
|
102
|
+
value: value
|
103
|
+
};
|
104
|
+
}
|
105
|
+
function err(error) {
|
106
|
+
return {
|
107
|
+
kind: "err",
|
108
|
+
error: error
|
109
|
+
};
|
110
|
+
}
|
111
|
+
function isOk(result) {
|
112
|
+
return result === voidOk || result.kind === "ok";
|
113
|
+
}
|
114
|
+
function isErr(result) {
|
115
|
+
return result !== voidOk && result.kind === "err";
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* If all results are Ok (or if results is empty), returns Ok with all the Ok
|
119
|
+
* values concatenated into an array. If any result is Err, returns Err with all
|
120
|
+
* Err values concatenated into an array.
|
121
|
+
*
|
122
|
+
* @see {@link all} for use with simple array types.
|
123
|
+
*/
|
124
|
+
function allT(results) {
|
125
|
+
var values = [];
|
126
|
+
var errors = [];
|
127
|
+
var _iterator = _createForOfIteratorHelper(results),
|
128
|
+
_step;
|
129
|
+
try {
|
130
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
131
|
+
var _result = _step.value;
|
132
|
+
if (isOk(_result)) {
|
133
|
+
values.push(_result.value);
|
134
|
+
} else {
|
135
|
+
errors.push(_result.error);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
} catch (err) {
|
139
|
+
_iterator.e(err);
|
140
|
+
} finally {
|
141
|
+
_iterator.f();
|
142
|
+
}
|
143
|
+
if (isNonEmpty(errors)) {
|
144
|
+
return err(errors);
|
145
|
+
} else {
|
146
|
+
return ok(values);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* If all results are Ok (or if results is empty), returns Ok with all the Ok
|
152
|
+
* values concatenated into an array. If any result is Err, returns Err with all
|
153
|
+
* Err values concatenated into an array.
|
154
|
+
*
|
155
|
+
* @see {@link allT} for use with tuple types.
|
156
|
+
*/
|
157
|
+
function all(results) {
|
158
|
+
return allT(results);
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* If all results are Ok (or if results is empty), returns Ok. If any result is
|
163
|
+
* Err, returns Err with all Err values concatenated into an array.
|
164
|
+
*/
|
165
|
+
function allV(results) {
|
166
|
+
var errs = [];
|
167
|
+
var _iterator2 = _createForOfIteratorHelper(results),
|
168
|
+
_step2;
|
169
|
+
try {
|
170
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
171
|
+
var _result2 = _step2.value;
|
172
|
+
if (isErr(_result2)) {
|
173
|
+
errs.push(_result2.error);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
} catch (err) {
|
177
|
+
_iterator2.e(err);
|
178
|
+
} finally {
|
179
|
+
_iterator2.f();
|
180
|
+
}
|
181
|
+
if (isNonEmpty(errs)) {
|
182
|
+
return err(errs);
|
183
|
+
}
|
184
|
+
return voidOk;
|
185
|
+
}
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Perform a reduction over an array with a Result-returning reducer. If the
|
189
|
+
* reducer returns Ok, its value is used as the next value. If the reducer
|
190
|
+
* returns Err, it is returned immediately.
|
191
|
+
*
|
192
|
+
* flatMapReduce is a short-circuiting equivalent to:
|
193
|
+
* ```
|
194
|
+
* arr.reduce(
|
195
|
+
* (accRes, current, currentIndex) =>
|
196
|
+
* flatMap((acc) => reducer(acc, current, currentIndex))(accRes),
|
197
|
+
* ok(initVal)
|
198
|
+
* )
|
199
|
+
* ```
|
200
|
+
*/
|
201
|
+
function flatMapReduce(reducer, initVal) {
|
202
|
+
return function (arr) {
|
203
|
+
var val = ok(initVal);
|
204
|
+
for (var i = 0; i < arr.length && isOk(val); ++i) {
|
205
|
+
val = reducer(val.value, arr[i], i);
|
206
|
+
}
|
207
|
+
return val;
|
208
|
+
};
|
209
|
+
}
|
210
|
+
function map(onOk) {
|
211
|
+
return function (result) {
|
212
|
+
if (isOk(result)) {
|
213
|
+
return ok(onOk(result.value));
|
214
|
+
} else {
|
215
|
+
return result;
|
216
|
+
}
|
217
|
+
};
|
218
|
+
}
|
219
|
+
function flatMap(onOk) {
|
220
|
+
return function (result) {
|
221
|
+
if (isOk(result)) {
|
222
|
+
return onOk(result.value);
|
223
|
+
} else {
|
224
|
+
return result;
|
225
|
+
}
|
226
|
+
};
|
227
|
+
}
|
228
|
+
function mapErr(onErr) {
|
229
|
+
return function (result) {
|
230
|
+
if (isErr(result)) {
|
231
|
+
return err(onErr(result.error));
|
232
|
+
} else {
|
233
|
+
return result;
|
234
|
+
}
|
235
|
+
};
|
236
|
+
}
|
237
|
+
function fromPredicate(refinement, onFalse) {
|
238
|
+
return function (value) {
|
239
|
+
if (refinement(value)) {
|
240
|
+
return ok(value);
|
241
|
+
} else {
|
242
|
+
return err(onFalse(value));
|
243
|
+
}
|
244
|
+
};
|
245
|
+
}
|
246
|
+
|
247
|
+
// NOTE: Function overload resolution seems to fail when declared as overloaded
|
248
|
+
// function type, so a value with a callable type is used instead.
|
249
|
+
var filterOrElse = function filterOrElse(refinement, onFalse) {
|
250
|
+
return function (result) {
|
251
|
+
if (isOk(result)) {
|
252
|
+
if (refinement(result.value)) {
|
253
|
+
return result;
|
254
|
+
} else {
|
255
|
+
return err(onFalse(result.value));
|
256
|
+
}
|
257
|
+
} else {
|
258
|
+
return result;
|
259
|
+
}
|
260
|
+
};
|
261
|
+
};
|
262
|
+
|
263
|
+
var result = /*#__PURE__*/Object.freeze({
|
264
|
+
__proto__: null,
|
265
|
+
voidOk: voidOk,
|
266
|
+
ok: ok,
|
267
|
+
err: err,
|
268
|
+
isOk: isOk,
|
269
|
+
isErr: isErr,
|
270
|
+
allT: allT,
|
271
|
+
all: all,
|
272
|
+
allV: allV,
|
273
|
+
flatMapReduce: flatMapReduce,
|
274
|
+
map: map,
|
275
|
+
flatMap: flatMap,
|
276
|
+
mapErr: mapErr,
|
277
|
+
fromPredicate: fromPredicate,
|
278
|
+
filterOrElse: filterOrElse
|
279
|
+
});
|
280
|
+
|
281
|
+
exports._arrayLikeToArray = _arrayLikeToArray;
|
282
|
+
exports._createForOfIteratorHelper = _createForOfIteratorHelper;
|
283
|
+
exports._unsupportedIterableToArray = _unsupportedIterableToArray;
|
284
|
+
exports.all = all;
|
285
|
+
exports.allT = allT;
|
286
|
+
exports.array = array;
|
287
|
+
exports.err = err;
|
288
|
+
exports.filterOrElse = filterOrElse;
|
289
|
+
exports.flatMap = flatMap;
|
290
|
+
exports.flatMapReduce = flatMapReduce;
|
291
|
+
exports.flatten = flatten;
|
292
|
+
exports.isErr = isErr;
|
293
|
+
exports.isNonEmpty = isNonEmpty;
|
294
|
+
exports.isOk = isOk;
|
295
|
+
exports.map = map;
|
296
|
+
exports.map$1 = map$1;
|
297
|
+
exports.mapErr = mapErr;
|
298
|
+
exports.ok = ok;
|
299
|
+
exports.result = result;
|
@@ -0,0 +1,299 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
function _arrayLikeToArray(arr, len) {
|
4
|
+
if (len == null || len > arr.length) len = arr.length;
|
5
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
6
|
+
return arr2;
|
7
|
+
}
|
8
|
+
|
9
|
+
function _unsupportedIterableToArray(o, minLen) {
|
10
|
+
if (!o) return;
|
11
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
12
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
13
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
14
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
15
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
16
|
+
}
|
17
|
+
|
18
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
19
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
20
|
+
if (!it) {
|
21
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
22
|
+
if (it) o = it;
|
23
|
+
var i = 0;
|
24
|
+
var F = function () {};
|
25
|
+
return {
|
26
|
+
s: F,
|
27
|
+
n: function () {
|
28
|
+
if (i >= o.length) return {
|
29
|
+
done: true
|
30
|
+
};
|
31
|
+
return {
|
32
|
+
done: false,
|
33
|
+
value: o[i++]
|
34
|
+
};
|
35
|
+
},
|
36
|
+
e: function (e) {
|
37
|
+
throw e;
|
38
|
+
},
|
39
|
+
f: F
|
40
|
+
};
|
41
|
+
}
|
42
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
43
|
+
}
|
44
|
+
var normalCompletion = true,
|
45
|
+
didErr = false,
|
46
|
+
err;
|
47
|
+
return {
|
48
|
+
s: function () {
|
49
|
+
it = it.call(o);
|
50
|
+
},
|
51
|
+
n: function () {
|
52
|
+
var step = it.next();
|
53
|
+
normalCompletion = step.done;
|
54
|
+
return step;
|
55
|
+
},
|
56
|
+
e: function (e) {
|
57
|
+
didErr = true;
|
58
|
+
err = e;
|
59
|
+
},
|
60
|
+
f: function () {
|
61
|
+
try {
|
62
|
+
if (!normalCompletion && it.return != null) it.return();
|
63
|
+
} finally {
|
64
|
+
if (didErr) throw err;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
function isNonEmpty(array) {
|
71
|
+
return array.length > 0;
|
72
|
+
}
|
73
|
+
function flatten(array) {
|
74
|
+
return array.flat(1);
|
75
|
+
}
|
76
|
+
function map$1(fn) {
|
77
|
+
function mapFn(array) {
|
78
|
+
return array.map(fn);
|
79
|
+
}
|
80
|
+
return mapFn;
|
81
|
+
}
|
82
|
+
|
83
|
+
var array = /*#__PURE__*/Object.freeze({
|
84
|
+
__proto__: null,
|
85
|
+
isNonEmpty: isNonEmpty,
|
86
|
+
flatten: flatten,
|
87
|
+
map: map$1
|
88
|
+
});
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Singleton instance of Ok<void>. Used to optimize results whose Ok values are
|
92
|
+
* void.
|
93
|
+
*/
|
94
|
+
var voidOk = Object.freeze({
|
95
|
+
kind: "ok",
|
96
|
+
value: undefined
|
97
|
+
});
|
98
|
+
function ok(value) {
|
99
|
+
if (value === undefined) return voidOk;
|
100
|
+
return {
|
101
|
+
kind: "ok",
|
102
|
+
value: value
|
103
|
+
};
|
104
|
+
}
|
105
|
+
function err(error) {
|
106
|
+
return {
|
107
|
+
kind: "err",
|
108
|
+
error: error
|
109
|
+
};
|
110
|
+
}
|
111
|
+
function isOk(result) {
|
112
|
+
return result === voidOk || result.kind === "ok";
|
113
|
+
}
|
114
|
+
function isErr(result) {
|
115
|
+
return result !== voidOk && result.kind === "err";
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* If all results are Ok (or if results is empty), returns Ok with all the Ok
|
119
|
+
* values concatenated into an array. If any result is Err, returns Err with all
|
120
|
+
* Err values concatenated into an array.
|
121
|
+
*
|
122
|
+
* @see {@link all} for use with simple array types.
|
123
|
+
*/
|
124
|
+
function allT(results) {
|
125
|
+
var values = [];
|
126
|
+
var errors = [];
|
127
|
+
var _iterator = _createForOfIteratorHelper(results),
|
128
|
+
_step;
|
129
|
+
try {
|
130
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
131
|
+
var _result = _step.value;
|
132
|
+
if (isOk(_result)) {
|
133
|
+
values.push(_result.value);
|
134
|
+
} else {
|
135
|
+
errors.push(_result.error);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
} catch (err) {
|
139
|
+
_iterator.e(err);
|
140
|
+
} finally {
|
141
|
+
_iterator.f();
|
142
|
+
}
|
143
|
+
if (isNonEmpty(errors)) {
|
144
|
+
return err(errors);
|
145
|
+
} else {
|
146
|
+
return ok(values);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* If all results are Ok (or if results is empty), returns Ok with all the Ok
|
152
|
+
* values concatenated into an array. If any result is Err, returns Err with all
|
153
|
+
* Err values concatenated into an array.
|
154
|
+
*
|
155
|
+
* @see {@link allT} for use with tuple types.
|
156
|
+
*/
|
157
|
+
function all(results) {
|
158
|
+
return allT(results);
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* If all results are Ok (or if results is empty), returns Ok. If any result is
|
163
|
+
* Err, returns Err with all Err values concatenated into an array.
|
164
|
+
*/
|
165
|
+
function allV(results) {
|
166
|
+
var errs = [];
|
167
|
+
var _iterator2 = _createForOfIteratorHelper(results),
|
168
|
+
_step2;
|
169
|
+
try {
|
170
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
171
|
+
var _result2 = _step2.value;
|
172
|
+
if (isErr(_result2)) {
|
173
|
+
errs.push(_result2.error);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
} catch (err) {
|
177
|
+
_iterator2.e(err);
|
178
|
+
} finally {
|
179
|
+
_iterator2.f();
|
180
|
+
}
|
181
|
+
if (isNonEmpty(errs)) {
|
182
|
+
return err(errs);
|
183
|
+
}
|
184
|
+
return voidOk;
|
185
|
+
}
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Perform a reduction over an array with a Result-returning reducer. If the
|
189
|
+
* reducer returns Ok, its value is used as the next value. If the reducer
|
190
|
+
* returns Err, it is returned immediately.
|
191
|
+
*
|
192
|
+
* flatMapReduce is a short-circuiting equivalent to:
|
193
|
+
* ```
|
194
|
+
* arr.reduce(
|
195
|
+
* (accRes, current, currentIndex) =>
|
196
|
+
* flatMap((acc) => reducer(acc, current, currentIndex))(accRes),
|
197
|
+
* ok(initVal)
|
198
|
+
* )
|
199
|
+
* ```
|
200
|
+
*/
|
201
|
+
function flatMapReduce(reducer, initVal) {
|
202
|
+
return function (arr) {
|
203
|
+
var val = ok(initVal);
|
204
|
+
for (var i = 0; i < arr.length && isOk(val); ++i) {
|
205
|
+
val = reducer(val.value, arr[i], i);
|
206
|
+
}
|
207
|
+
return val;
|
208
|
+
};
|
209
|
+
}
|
210
|
+
function map(onOk) {
|
211
|
+
return function (result) {
|
212
|
+
if (isOk(result)) {
|
213
|
+
return ok(onOk(result.value));
|
214
|
+
} else {
|
215
|
+
return result;
|
216
|
+
}
|
217
|
+
};
|
218
|
+
}
|
219
|
+
function flatMap(onOk) {
|
220
|
+
return function (result) {
|
221
|
+
if (isOk(result)) {
|
222
|
+
return onOk(result.value);
|
223
|
+
} else {
|
224
|
+
return result;
|
225
|
+
}
|
226
|
+
};
|
227
|
+
}
|
228
|
+
function mapErr(onErr) {
|
229
|
+
return function (result) {
|
230
|
+
if (isErr(result)) {
|
231
|
+
return err(onErr(result.error));
|
232
|
+
} else {
|
233
|
+
return result;
|
234
|
+
}
|
235
|
+
};
|
236
|
+
}
|
237
|
+
function fromPredicate(refinement, onFalse) {
|
238
|
+
return function (value) {
|
239
|
+
if (refinement(value)) {
|
240
|
+
return ok(value);
|
241
|
+
} else {
|
242
|
+
return err(onFalse(value));
|
243
|
+
}
|
244
|
+
};
|
245
|
+
}
|
246
|
+
|
247
|
+
// NOTE: Function overload resolution seems to fail when declared as overloaded
|
248
|
+
// function type, so a value with a callable type is used instead.
|
249
|
+
var filterOrElse = function filterOrElse(refinement, onFalse) {
|
250
|
+
return function (result) {
|
251
|
+
if (isOk(result)) {
|
252
|
+
if (refinement(result.value)) {
|
253
|
+
return result;
|
254
|
+
} else {
|
255
|
+
return err(onFalse(result.value));
|
256
|
+
}
|
257
|
+
} else {
|
258
|
+
return result;
|
259
|
+
}
|
260
|
+
};
|
261
|
+
};
|
262
|
+
|
263
|
+
var result = /*#__PURE__*/Object.freeze({
|
264
|
+
__proto__: null,
|
265
|
+
voidOk: voidOk,
|
266
|
+
ok: ok,
|
267
|
+
err: err,
|
268
|
+
isOk: isOk,
|
269
|
+
isErr: isErr,
|
270
|
+
allT: allT,
|
271
|
+
all: all,
|
272
|
+
allV: allV,
|
273
|
+
flatMapReduce: flatMapReduce,
|
274
|
+
map: map,
|
275
|
+
flatMap: flatMap,
|
276
|
+
mapErr: mapErr,
|
277
|
+
fromPredicate: fromPredicate,
|
278
|
+
filterOrElse: filterOrElse
|
279
|
+
});
|
280
|
+
|
281
|
+
exports._arrayLikeToArray = _arrayLikeToArray;
|
282
|
+
exports._createForOfIteratorHelper = _createForOfIteratorHelper;
|
283
|
+
exports._unsupportedIterableToArray = _unsupportedIterableToArray;
|
284
|
+
exports.all = all;
|
285
|
+
exports.allT = allT;
|
286
|
+
exports.array = array;
|
287
|
+
exports.err = err;
|
288
|
+
exports.filterOrElse = filterOrElse;
|
289
|
+
exports.flatMap = flatMap;
|
290
|
+
exports.flatMapReduce = flatMapReduce;
|
291
|
+
exports.flatten = flatten;
|
292
|
+
exports.isErr = isErr;
|
293
|
+
exports.isNonEmpty = isNonEmpty;
|
294
|
+
exports.isOk = isOk;
|
295
|
+
exports.map = map;
|
296
|
+
exports.map$1 = map$1;
|
297
|
+
exports.mapErr = mapErr;
|
298
|
+
exports.ok = ok;
|
299
|
+
exports.result = result;
|