@naturalcycles/nodejs-lib 15.122.0 → 15.122.2
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.
|
@@ -543,10 +543,15 @@ export class JString extends JBuilder {
|
|
|
543
543
|
}
|
|
544
544
|
pattern(pattern, opt) {
|
|
545
545
|
const clone = this.cloneAndUpdateSchema({ pattern });
|
|
546
|
-
if (opt?.
|
|
547
|
-
clone.setErrorMessage('pattern', `is not a valid ${opt.name}`);
|
|
548
|
-
if (opt?.msg)
|
|
546
|
+
if (opt?.msg) {
|
|
549
547
|
clone.setErrorMessage('pattern', opt.msg);
|
|
548
|
+
}
|
|
549
|
+
else if (opt?.name) {
|
|
550
|
+
clone.setErrorMessage('pattern', `is not a valid ${opt.name}`);
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
clone.setErrorMessage('pattern', 'is not matching the expected pattern');
|
|
554
|
+
}
|
|
550
555
|
return clone;
|
|
551
556
|
}
|
|
552
557
|
minLength(minLength) {
|
|
@@ -1202,22 +1207,28 @@ function executeValidation(fn, builtSchema, input, opt = {}, defaultInputName) {
|
|
|
1202
1207
|
// rewritten into below (a property name may itself contain a dot).
|
|
1203
1208
|
// Root errors (empty instancePath) resolve to undefined - there the value is the whole Input,
|
|
1204
1209
|
// which is printed anyway.
|
|
1210
|
+
// `required` errors also resolve to undefined - their instancePath points at the parent object
|
|
1211
|
+
// that lacks the property, so `got:` would print that whole object - noise next to the Input print.
|
|
1205
1212
|
const failingValueByError = new Map(errors.map(e => [
|
|
1206
1213
|
e,
|
|
1207
|
-
e.instancePath
|
|
1214
|
+
e.instancePath && e.keyword !== 'required'
|
|
1215
|
+
? getValueAtJsonPointer(inputForPrint, e.instancePath)
|
|
1216
|
+
: undefined,
|
|
1208
1217
|
]));
|
|
1209
1218
|
applyImprovementsOnErrorMessages(errors, builtSchema);
|
|
1210
1219
|
// Same line format as Ajv's errorsText().
|
|
1211
|
-
// Each
|
|
1220
|
+
// Each error line is followed by a `Got: ...` line printing the narrow failing value itself,
|
|
1212
1221
|
// so it stays visible even when the Input print below gets truncated for large inputs.
|
|
1222
|
+
// `Got` is a separate line (and is allowed to print multi-line) on purpose: consumers that
|
|
1223
|
+
// only take the first line of the message keep getting the unchanged (pre-Got) error line.
|
|
1213
1224
|
let message = errors
|
|
1214
|
-
.
|
|
1215
|
-
|
|
1225
|
+
.flatMap(e => {
|
|
1226
|
+
const lines = [`${dataVar}${e.instancePath} ${e.message}`];
|
|
1216
1227
|
const value = failingValueByError.get(e);
|
|
1217
1228
|
if (value !== undefined) {
|
|
1218
|
-
|
|
1229
|
+
lines.push(`Got: ${_inspect(value, { maxLen: 500 })}`);
|
|
1219
1230
|
}
|
|
1220
|
-
return
|
|
1231
|
+
return lines;
|
|
1221
1232
|
})
|
|
1222
1233
|
.join(separator);
|
|
1223
1234
|
const inputStringified = _inspect(inputForPrint, { maxLen: 4000 });
|
package/dist/zip/zipInternal.js
CHANGED
|
@@ -60,8 +60,13 @@ const MAX_DOS_DATE = new Date(2107, 11, 31, 23, 59, 58);
|
|
|
60
60
|
* timestamp is rendered in the local timezone. Out-of-range dates are clamped to 1980-2107.
|
|
61
61
|
*/
|
|
62
62
|
export function unixToDosDateTime(ts) {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
let d = new Date(ts * 1000);
|
|
64
|
+
if (d < MIN_DOS_DATE) {
|
|
65
|
+
d = MIN_DOS_DATE;
|
|
66
|
+
}
|
|
67
|
+
else if (d > MAX_DOS_DATE) {
|
|
68
|
+
d = MAX_DOS_DATE;
|
|
69
|
+
}
|
|
65
70
|
const date = (d.getDate() & 0x1f) | // 1-31
|
|
66
71
|
(((d.getMonth() + 1) & 0x0f) << 5) | // 1-12
|
|
67
72
|
(((d.getFullYear() - 1980) & 0x7f) << 9); // 1980-2107
|
package/package.json
CHANGED
|
@@ -734,8 +734,14 @@ export class JString<
|
|
|
734
734
|
|
|
735
735
|
pattern(pattern: string, opt?: JsonBuilderRuleOpt): this {
|
|
736
736
|
const clone = this.cloneAndUpdateSchema({ pattern })
|
|
737
|
-
if (opt?.
|
|
738
|
-
|
|
737
|
+
if (opt?.msg) {
|
|
738
|
+
clone.setErrorMessage('pattern', opt.msg)
|
|
739
|
+
} else if (opt?.name) {
|
|
740
|
+
clone.setErrorMessage('pattern', `is not a valid ${opt.name}`)
|
|
741
|
+
} else {
|
|
742
|
+
clone.setErrorMessage('pattern', 'is not matching the expected pattern')
|
|
743
|
+
}
|
|
744
|
+
|
|
739
745
|
return clone
|
|
740
746
|
}
|
|
741
747
|
|
|
@@ -1732,26 +1738,32 @@ function executeValidation<OUT>(
|
|
|
1732
1738
|
// rewritten into below (a property name may itself contain a dot).
|
|
1733
1739
|
// Root errors (empty instancePath) resolve to undefined - there the value is the whole Input,
|
|
1734
1740
|
// which is printed anyway.
|
|
1741
|
+
// `required` errors also resolve to undefined - their instancePath points at the parent object
|
|
1742
|
+
// that lacks the property, so `got:` would print that whole object - noise next to the Input print.
|
|
1735
1743
|
const failingValueByError = new Map<ErrorObject, unknown>(
|
|
1736
1744
|
errors.map(e => [
|
|
1737
1745
|
e,
|
|
1738
|
-
e.instancePath
|
|
1746
|
+
e.instancePath && e.keyword !== 'required'
|
|
1747
|
+
? getValueAtJsonPointer(inputForPrint, e.instancePath)
|
|
1748
|
+
: undefined,
|
|
1739
1749
|
]),
|
|
1740
1750
|
)
|
|
1741
1751
|
|
|
1742
1752
|
applyImprovementsOnErrorMessages(errors, builtSchema)
|
|
1743
1753
|
|
|
1744
1754
|
// Same line format as Ajv's errorsText().
|
|
1745
|
-
// Each
|
|
1755
|
+
// Each error line is followed by a `Got: ...` line printing the narrow failing value itself,
|
|
1746
1756
|
// so it stays visible even when the Input print below gets truncated for large inputs.
|
|
1757
|
+
// `Got` is a separate line (and is allowed to print multi-line) on purpose: consumers that
|
|
1758
|
+
// only take the first line of the message keep getting the unchanged (pre-Got) error line.
|
|
1747
1759
|
let message = errors
|
|
1748
|
-
.
|
|
1749
|
-
|
|
1760
|
+
.flatMap(e => {
|
|
1761
|
+
const lines = [`${dataVar}${e.instancePath} ${e.message}`]
|
|
1750
1762
|
const value = failingValueByError.get(e)
|
|
1751
1763
|
if (value !== undefined) {
|
|
1752
|
-
|
|
1764
|
+
lines.push(`Got: ${_inspect(value, { maxLen: 500 })}`)
|
|
1753
1765
|
}
|
|
1754
|
-
return
|
|
1766
|
+
return lines
|
|
1755
1767
|
})
|
|
1756
1768
|
.join(separator)
|
|
1757
1769
|
|
package/src/zip/zipInternal.ts
CHANGED
|
@@ -76,8 +76,12 @@ const MAX_DOS_DATE = new Date(2107, 11, 31, 23, 59, 58)
|
|
|
76
76
|
* timestamp is rendered in the local timezone. Out-of-range dates are clamped to 1980-2107.
|
|
77
77
|
*/
|
|
78
78
|
export function unixToDosDateTime(ts: UnixTimestamp): { date: number; time: number } {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
let d = new Date(ts * 1000)
|
|
80
|
+
if (d < MIN_DOS_DATE) {
|
|
81
|
+
d = MIN_DOS_DATE
|
|
82
|
+
} else if (d > MAX_DOS_DATE) {
|
|
83
|
+
d = MAX_DOS_DATE
|
|
84
|
+
}
|
|
81
85
|
|
|
82
86
|
const date =
|
|
83
87
|
(d.getDate() & 0x1f) | // 1-31
|