decoders 2.12.2 → 2.12.3
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/dist/index.cjs +24 -14
- package/dist/index.js +24 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/lib/utils.ts
|
|
2
|
+
var MAX_ERRORS = 3;
|
|
2
3
|
// @__NO_SIDE_EFFECTS__
|
|
3
4
|
function qty(n, unit) {
|
|
4
5
|
return n === 1 ? `${n} ${unit}` : `${n} ${unit}s`;
|
|
@@ -220,8 +221,12 @@ function serializeArray(annotation, prefix) {
|
|
|
220
221
|
return "[]";
|
|
221
222
|
}
|
|
222
223
|
const result = [];
|
|
223
|
-
for (
|
|
224
|
-
const [ser, ann] = serializeAnnotation(
|
|
224
|
+
for (let i = 0; i < items.length; ++i) {
|
|
225
|
+
const [ser, ann] = serializeAnnotation(
|
|
226
|
+
items[i],
|
|
227
|
+
`${prefix}${INDENT}`,
|
|
228
|
+
`(at index ${i})`
|
|
229
|
+
);
|
|
225
230
|
result.push(`${prefix}${INDENT}${ser},`);
|
|
226
231
|
if (ann !== void 0) {
|
|
227
232
|
result.push(indent(ann, `${prefix}${INDENT}`));
|
|
@@ -267,7 +272,7 @@ function serializeValue(value) {
|
|
|
267
272
|
}
|
|
268
273
|
}
|
|
269
274
|
}
|
|
270
|
-
function serializeAnnotation(ann, prefix = "") {
|
|
275
|
+
function serializeAnnotation(ann, prefix = "", location) {
|
|
271
276
|
let serialized;
|
|
272
277
|
if (ann.type === "array") {
|
|
273
278
|
serialized = serializeArray(ann, prefix);
|
|
@@ -283,7 +288,8 @@ function serializeAnnotation(ann, prefix = "") {
|
|
|
283
288
|
const text = ann.text;
|
|
284
289
|
if (text !== void 0) {
|
|
285
290
|
const sep = "^".repeat(isMultiline(serialized) ? 1 : serialized.length);
|
|
286
|
-
|
|
291
|
+
const annotation = isMultiline(text) ? [location ? `${sep} ${location}` : sep, text].join("\n") : [sep, text, location].filter(Boolean).join(" ");
|
|
292
|
+
return [serialized, annotation];
|
|
287
293
|
} else {
|
|
288
294
|
return [serialized, void 0];
|
|
289
295
|
}
|
|
@@ -623,24 +629,25 @@ function array(decoder, options) {
|
|
|
623
629
|
const base = options !== void 0 ? sized(poja, options) : poja;
|
|
624
630
|
return base.chain((inputs, ok2, err2) => {
|
|
625
631
|
const results = [];
|
|
632
|
+
let clone = null;
|
|
633
|
+
let errorCount = 0;
|
|
626
634
|
for (let i = 0; i < inputs.length; ++i) {
|
|
627
635
|
const blob = inputs[i];
|
|
628
636
|
const result = decodeFn(blob);
|
|
629
637
|
if (result.ok) {
|
|
630
|
-
|
|
638
|
+
if (clone === null) {
|
|
639
|
+
results.push(result.value);
|
|
640
|
+
}
|
|
631
641
|
} else {
|
|
632
642
|
results.length = 0;
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
public_annotate(ann, ann.text ? `${ann.text} (at index ${i})` : `index ${i}`)
|
|
639
|
-
);
|
|
640
|
-
return err2(public_annotate(clone));
|
|
643
|
+
clone ??= inputs.slice();
|
|
644
|
+
clone[i] = result.error;
|
|
645
|
+
if (++errorCount >= MAX_ERRORS) {
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
641
648
|
}
|
|
642
649
|
}
|
|
643
|
-
return ok2(results);
|
|
650
|
+
return clone !== null ? err2(public_annotate(clone)) : ok2(results);
|
|
644
651
|
});
|
|
645
652
|
}
|
|
646
653
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -939,6 +946,9 @@ function record(fst, snd) {
|
|
|
939
946
|
errors.set(key, result.error);
|
|
940
947
|
rv = {};
|
|
941
948
|
}
|
|
949
|
+
if (errors.size >= MAX_ERRORS) {
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
942
952
|
}
|
|
943
953
|
if (errors.size > 0) {
|
|
944
954
|
return err2(merge(public_annotateObject(input), errors));
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/lib/utils.ts
|
|
2
|
+
var MAX_ERRORS = 3;
|
|
2
3
|
// @__NO_SIDE_EFFECTS__
|
|
3
4
|
function qty(n, unit) {
|
|
4
5
|
return n === 1 ? `${n} ${unit}` : `${n} ${unit}s`;
|
|
@@ -220,8 +221,12 @@ function serializeArray(annotation, prefix) {
|
|
|
220
221
|
return "[]";
|
|
221
222
|
}
|
|
222
223
|
const result = [];
|
|
223
|
-
for (
|
|
224
|
-
const [ser, ann] = serializeAnnotation(
|
|
224
|
+
for (let i = 0; i < items.length; ++i) {
|
|
225
|
+
const [ser, ann] = serializeAnnotation(
|
|
226
|
+
items[i],
|
|
227
|
+
`${prefix}${INDENT}`,
|
|
228
|
+
`(at index ${i})`
|
|
229
|
+
);
|
|
225
230
|
result.push(`${prefix}${INDENT}${ser},`);
|
|
226
231
|
if (ann !== void 0) {
|
|
227
232
|
result.push(indent(ann, `${prefix}${INDENT}`));
|
|
@@ -267,7 +272,7 @@ function serializeValue(value) {
|
|
|
267
272
|
}
|
|
268
273
|
}
|
|
269
274
|
}
|
|
270
|
-
function serializeAnnotation(ann, prefix = "") {
|
|
275
|
+
function serializeAnnotation(ann, prefix = "", location) {
|
|
271
276
|
let serialized;
|
|
272
277
|
if (ann.type === "array") {
|
|
273
278
|
serialized = serializeArray(ann, prefix);
|
|
@@ -283,7 +288,8 @@ function serializeAnnotation(ann, prefix = "") {
|
|
|
283
288
|
const text = ann.text;
|
|
284
289
|
if (text !== void 0) {
|
|
285
290
|
const sep = "^".repeat(isMultiline(serialized) ? 1 : serialized.length);
|
|
286
|
-
|
|
291
|
+
const annotation = isMultiline(text) ? [location ? `${sep} ${location}` : sep, text].join("\n") : [sep, text, location].filter(Boolean).join(" ");
|
|
292
|
+
return [serialized, annotation];
|
|
287
293
|
} else {
|
|
288
294
|
return [serialized, void 0];
|
|
289
295
|
}
|
|
@@ -623,24 +629,25 @@ function array(decoder, options) {
|
|
|
623
629
|
const base = options !== void 0 ? sized(poja, options) : poja;
|
|
624
630
|
return base.chain((inputs, ok2, err2) => {
|
|
625
631
|
const results = [];
|
|
632
|
+
let clone = null;
|
|
633
|
+
let errorCount = 0;
|
|
626
634
|
for (let i = 0; i < inputs.length; ++i) {
|
|
627
635
|
const blob = inputs[i];
|
|
628
636
|
const result = decodeFn(blob);
|
|
629
637
|
if (result.ok) {
|
|
630
|
-
|
|
638
|
+
if (clone === null) {
|
|
639
|
+
results.push(result.value);
|
|
640
|
+
}
|
|
631
641
|
} else {
|
|
632
642
|
results.length = 0;
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
public_annotate(ann, ann.text ? `${ann.text} (at index ${i})` : `index ${i}`)
|
|
639
|
-
);
|
|
640
|
-
return err2(public_annotate(clone));
|
|
643
|
+
clone ??= inputs.slice();
|
|
644
|
+
clone[i] = result.error;
|
|
645
|
+
if (++errorCount >= MAX_ERRORS) {
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
641
648
|
}
|
|
642
649
|
}
|
|
643
|
-
return ok2(results);
|
|
650
|
+
return clone !== null ? err2(public_annotate(clone)) : ok2(results);
|
|
644
651
|
});
|
|
645
652
|
}
|
|
646
653
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -939,6 +946,9 @@ function record(fst, snd) {
|
|
|
939
946
|
errors.set(key, result.error);
|
|
940
947
|
rv = {};
|
|
941
948
|
}
|
|
949
|
+
if (errors.size >= MAX_ERRORS) {
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
942
952
|
}
|
|
943
953
|
if (errors.size > 0) {
|
|
944
954
|
return err2(merge(public_annotateObject(input), errors));
|