@evolu/common 8.1.0 → 8.3.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/dist/src/Function.d.ts +1 -0
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Http.d.ts +9 -0
- package/dist/src/Http.d.ts.map +1 -1
- package/dist/src/Number.d.ts +66 -6
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +11 -3
- package/dist/src/Object.d.ts +1 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/RefCount.d.ts +1 -0
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/Relation.d.ts +2 -0
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Resource.d.ts +1 -0
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Result.d.ts +383 -548
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +296 -46
- package/dist/src/Schedule.d.ts +2 -2
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/StackTrace.d.ts +1 -0
- package/dist/src/StackTrace.d.ts.map +1 -1
- package/dist/src/Task.d.ts +978 -1061
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1010 -159
- package/dist/src/Time.d.ts +71 -34
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +77 -1
- package/dist/src/Type.d.ts +1740 -795
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1634 -211
- package/dist/src/Types.d.ts +0 -24
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/intl/_en.d.ts +126 -0
- package/dist/src/intl/_en.d.ts.map +1 -0
- package/dist/src/intl/_en.js +267 -0
- package/dist/src/intl/ar.d.ts +117 -0
- package/dist/src/intl/ar.d.ts.map +1 -0
- package/dist/src/intl/ar.js +245 -0
- package/dist/src/intl/bn.d.ts +117 -0
- package/dist/src/intl/bn.d.ts.map +1 -0
- package/dist/src/intl/bn.js +258 -0
- package/dist/src/intl/ca.d.ts +117 -0
- package/dist/src/intl/ca.d.ts.map +1 -0
- package/dist/src/intl/ca.js +258 -0
- package/dist/src/intl/cs.d.ts +30 -7
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +65 -28
- package/dist/src/intl/da.d.ts +117 -0
- package/dist/src/intl/da.d.ts.map +1 -0
- package/dist/src/intl/da.js +258 -0
- package/dist/src/intl/de.d.ts +117 -0
- package/dist/src/intl/de.d.ts.map +1 -0
- package/dist/src/intl/de.js +258 -0
- package/dist/src/intl/el.d.ts +117 -0
- package/dist/src/intl/el.d.ts.map +1 -0
- package/dist/src/intl/el.js +265 -0
- package/dist/src/intl/es.d.ts +117 -0
- package/dist/src/intl/es.d.ts.map +1 -0
- package/dist/src/intl/es.js +258 -0
- package/dist/src/intl/fa.d.ts +117 -0
- package/dist/src/intl/fa.d.ts.map +1 -0
- package/dist/src/intl/fa.js +258 -0
- package/dist/src/intl/fi.d.ts +117 -0
- package/dist/src/intl/fi.d.ts.map +1 -0
- package/dist/src/intl/fi.js +258 -0
- package/dist/src/intl/fil.d.ts +117 -0
- package/dist/src/intl/fil.d.ts.map +1 -0
- package/dist/src/intl/fil.js +258 -0
- package/dist/src/intl/fr.d.ts +117 -0
- package/dist/src/intl/fr.d.ts.map +1 -0
- package/dist/src/intl/fr.js +258 -0
- package/dist/src/intl/he.d.ts +117 -0
- package/dist/src/intl/he.d.ts.map +1 -0
- package/dist/src/intl/he.js +258 -0
- package/dist/src/intl/hi.d.ts +117 -0
- package/dist/src/intl/hi.d.ts.map +1 -0
- package/dist/src/intl/hi.js +258 -0
- package/dist/src/intl/hr.d.ts +117 -0
- package/dist/src/intl/hr.d.ts.map +1 -0
- package/dist/src/intl/hr.js +265 -0
- package/dist/src/intl/hu.d.ts +63 -0
- package/dist/src/intl/hu.d.ts.map +1 -0
- package/dist/src/intl/hu.js +204 -0
- package/dist/src/intl/id.d.ts +117 -0
- package/dist/src/intl/id.d.ts.map +1 -0
- package/dist/src/intl/id.js +258 -0
- package/dist/src/intl/index.d.ts +42 -0
- package/dist/src/intl/index.d.ts.map +1 -1
- package/dist/src/intl/index.js +42 -0
- package/dist/src/intl/it.d.ts +117 -0
- package/dist/src/intl/it.d.ts.map +1 -0
- package/dist/src/intl/it.js +258 -0
- package/dist/src/intl/ja.d.ts +117 -0
- package/dist/src/intl/ja.d.ts.map +1 -0
- package/dist/src/intl/ja.js +258 -0
- package/dist/src/intl/ko.d.ts +117 -0
- package/dist/src/intl/ko.d.ts.map +1 -0
- package/dist/src/intl/ko.js +258 -0
- package/dist/src/intl/ml.d.ts +117 -0
- package/dist/src/intl/ml.d.ts.map +1 -0
- package/dist/src/intl/ml.js +258 -0
- package/dist/src/intl/mr.d.ts +117 -0
- package/dist/src/intl/mr.d.ts.map +1 -0
- package/dist/src/intl/mr.js +258 -0
- package/dist/src/intl/ms.d.ts +117 -0
- package/dist/src/intl/ms.d.ts.map +1 -0
- package/dist/src/intl/ms.js +245 -0
- package/dist/src/intl/nb.d.ts +63 -0
- package/dist/src/intl/nb.d.ts.map +1 -0
- package/dist/src/intl/nb.js +191 -0
- package/dist/src/intl/nl.d.ts +117 -0
- package/dist/src/intl/nl.d.ts.map +1 -0
- package/dist/src/intl/nl.js +258 -0
- package/dist/src/intl/pa.d.ts +117 -0
- package/dist/src/intl/pa.d.ts.map +1 -0
- package/dist/src/intl/pa.js +258 -0
- package/dist/src/intl/pl.d.ts +117 -0
- package/dist/src/intl/pl.d.ts.map +1 -0
- package/dist/src/intl/pl.js +242 -0
- package/dist/src/intl/pt-BR.d.ts +117 -0
- package/dist/src/intl/pt-BR.d.ts.map +1 -0
- package/dist/src/intl/pt-BR.js +258 -0
- package/dist/src/intl/pt.d.ts +117 -0
- package/dist/src/intl/pt.d.ts.map +1 -0
- package/dist/src/intl/pt.js +246 -0
- package/dist/src/intl/ro.d.ts +117 -0
- package/dist/src/intl/ro.d.ts.map +1 -0
- package/dist/src/intl/ro.js +258 -0
- package/dist/src/intl/sk.d.ts +117 -0
- package/dist/src/intl/sk.d.ts.map +1 -0
- package/dist/src/intl/sk.js +244 -0
- package/dist/src/intl/sl.d.ts +117 -0
- package/dist/src/intl/sl.d.ts.map +1 -0
- package/dist/src/intl/sl.js +258 -0
- package/dist/src/intl/sv.d.ts +117 -0
- package/dist/src/intl/sv.d.ts.map +1 -0
- package/dist/src/intl/sv.js +258 -0
- package/dist/src/intl/sw.d.ts +63 -0
- package/dist/src/intl/sw.d.ts.map +1 -0
- package/dist/src/intl/sw.js +191 -0
- package/dist/src/intl/ta.d.ts +117 -0
- package/dist/src/intl/ta.d.ts.map +1 -0
- package/dist/src/intl/ta.js +258 -0
- package/dist/src/intl/te.d.ts +117 -0
- package/dist/src/intl/te.d.ts.map +1 -0
- package/dist/src/intl/te.js +258 -0
- package/dist/src/intl/th.d.ts +117 -0
- package/dist/src/intl/th.d.ts.map +1 -0
- package/dist/src/intl/th.js +258 -0
- package/dist/src/intl/tr.d.ts +117 -0
- package/dist/src/intl/tr.d.ts.map +1 -0
- package/dist/src/intl/tr.js +255 -0
- package/dist/src/intl/uk.d.ts +117 -0
- package/dist/src/intl/uk.d.ts.map +1 -0
- package/dist/src/intl/uk.js +258 -0
- package/dist/src/intl/ur.d.ts +117 -0
- package/dist/src/intl/ur.d.ts.map +1 -0
- package/dist/src/intl/ur.js +245 -0
- package/dist/src/intl/vi.d.ts +117 -0
- package/dist/src/intl/vi.d.ts.map +1 -0
- package/dist/src/intl/vi.js +255 -0
- package/dist/src/intl/zh-CN.d.ts +117 -0
- package/dist/src/intl/zh-CN.d.ts.map +1 -0
- package/dist/src/intl/zh-CN.js +258 -0
- package/dist/src/intl/zh-TW.d.ts +117 -0
- package/dist/src/intl/zh-TW.d.ts.map +1 -0
- package/dist/src/intl/zh-TW.js +258 -0
- package/dist/src/local-first/Owner.d.ts +156 -62
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +119 -20
- package/package.json +1 -1
- package/src/Function.ts +2 -0
- package/src/Http.ts +9 -0
- package/src/Number.ts +85 -14
- package/src/Object.ts +2 -0
- package/src/RefCount.ts +2 -0
- package/src/Relation.ts +4 -0
- package/src/Resource.ts +2 -0
- package/src/Result.ts +397 -560
- package/src/Schedule.ts +1 -1
- package/src/StackTrace.ts +2 -0
- package/src/Task.ts +1145 -1225
- package/src/Time.ts +110 -62
- package/src/Type.ts +2842 -835
- package/src/Types.ts +0 -49
- package/src/intl/_en.ts +497 -0
- package/src/intl/ar.ts +417 -0
- package/src/intl/bn.ts +486 -0
- package/src/intl/ca.ts +488 -0
- package/src/intl/cs.ts +131 -32
- package/src/intl/da.ts +488 -0
- package/src/intl/de.ts +488 -0
- package/src/intl/el.ts +494 -0
- package/src/intl/es.ts +488 -0
- package/src/intl/fa.ts +487 -0
- package/src/intl/fi.ts +487 -0
- package/src/intl/fil.ts +488 -0
- package/src/intl/fr.ts +488 -0
- package/src/intl/he.ts +486 -0
- package/src/intl/hi.ts +487 -0
- package/src/intl/hr.ts +494 -0
- package/src/intl/hu.ts +387 -0
- package/src/intl/id.ts +487 -0
- package/src/intl/index.ts +42 -0
- package/src/intl/it.ts +488 -0
- package/src/intl/ja.ts +488 -0
- package/src/intl/ko.ts +487 -0
- package/src/intl/ml.ts +487 -0
- package/src/intl/mr.ts +487 -0
- package/src/intl/ms.ts +410 -0
- package/src/intl/nb.ts +364 -0
- package/src/intl/nl.ts +488 -0
- package/src/intl/pa.ts +487 -0
- package/src/intl/pl.ts +450 -0
- package/src/intl/pt-BR.ts +487 -0
- package/src/intl/pt.ts +424 -0
- package/src/intl/ro.ts +488 -0
- package/src/intl/sk.ts +412 -0
- package/src/intl/sl.ts +487 -0
- package/src/intl/sv.ts +488 -0
- package/src/intl/sw.ts +324 -0
- package/src/intl/ta.ts +487 -0
- package/src/intl/te.ts +487 -0
- package/src/intl/th.ts +484 -0
- package/src/intl/tr.ts +487 -0
- package/src/intl/uk.ts +488 -0
- package/src/intl/ur.ts +410 -0
- package/src/intl/vi.ts +435 -0
- package/src/intl/zh-CN.ts +482 -0
- package/src/intl/zh-TW.ts +482 -0
- package/src/local-first/Owner.ts +156 -62
package/src/Types.ts
CHANGED
|
@@ -381,55 +381,6 @@ export const isPromiseLike = <T>(
|
|
|
381
381
|
): value is PromiseLike<T> =>
|
|
382
382
|
typeof (value as PromiseLike<T> | null | undefined)?.then === "function";
|
|
383
383
|
|
|
384
|
-
/** Decimal digit from `"0"` to `"9"`. */
|
|
385
|
-
export type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
386
|
-
|
|
387
|
-
/** Decimal digit from `"1"` to `"9"`. */
|
|
388
|
-
export type Digit1To9 = Exclude<Digit, "0">;
|
|
389
|
-
|
|
390
|
-
/** Decimal string from `"1"` to `"6"`. */
|
|
391
|
-
export type Digit1To6 = "1" | "2" | "3" | "4" | "5" | "6";
|
|
392
|
-
|
|
393
|
-
/** Decimal string from `"1"` to `"23"`. */
|
|
394
|
-
export type Digit1To23 =
|
|
395
|
-
| Digit1To9 // 1-9
|
|
396
|
-
| `1${Digit}` // 10-19
|
|
397
|
-
| `2${"0" | "1" | "2" | "3"}`; // 20-23
|
|
398
|
-
|
|
399
|
-
/** Decimal string from `"1"` to `"51"`. */
|
|
400
|
-
export type Digit1To51 =
|
|
401
|
-
| Digit1To9 // 1-9
|
|
402
|
-
| `${"1" | "2" | "3" | "4"}${Digit}` // 10-49
|
|
403
|
-
| `5${"0" | "1"}`; // 50-51
|
|
404
|
-
|
|
405
|
-
/** Decimal string from `"1"` to `"99"`. */
|
|
406
|
-
export type Digit1To99 =
|
|
407
|
-
| Digit1To9 // 1-9
|
|
408
|
-
| `${Digit1To9}${Digit}`; // 10-99
|
|
409
|
-
|
|
410
|
-
/** Decimal string from `"1"` to `"59"`. */
|
|
411
|
-
export type Digit1To59 =
|
|
412
|
-
| Digit1To9 // 1-9
|
|
413
|
-
| `1${Digit}` // 10-19
|
|
414
|
-
| `2${Digit}` // 20-29
|
|
415
|
-
| `3${Digit}` // 30-39
|
|
416
|
-
| `4${Digit}` // 40-49
|
|
417
|
-
| `5${Digit}`; // 50-59
|
|
418
|
-
|
|
419
|
-
/** Numeric literal 1-99. */
|
|
420
|
-
export type Int1To99 = NumberFromString<Digit1To99>;
|
|
421
|
-
|
|
422
|
-
/** Numeric literal 1-100. */
|
|
423
|
-
export type Int1To100 = Int1To99 | 100;
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Parses a numeric literal type from a string literal.
|
|
427
|
-
*
|
|
428
|
-
* Used by {@link Int1To99}.
|
|
429
|
-
*/
|
|
430
|
-
export type NumberFromString<T extends string> =
|
|
431
|
-
T extends `${infer N extends number}` ? N : never;
|
|
432
|
-
|
|
433
384
|
/** Creates a readable compiler-facing error message. */
|
|
434
385
|
export type CompileTimeError<
|
|
435
386
|
Context extends string,
|
package/src/intl/_en.ts
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* English Evolu Type error formatters.
|
|
3
|
+
*
|
|
4
|
+
* This module mirrors Type's default English formatters. It is the canonical
|
|
5
|
+
* source for translating Type error messages into other languages. Update this
|
|
6
|
+
* file whenever Type adds, removes, or changes a default formatter.
|
|
7
|
+
*
|
|
8
|
+
* Every formatter is exported separately so applications bundle only messages
|
|
9
|
+
* referenced by their localized Type collections. Parameterized Type factories
|
|
10
|
+
* reuse one formatter for every parameter value; for example,
|
|
11
|
+
* {@link formatMinLengthError} formats both `MinLength1` and `MinLength100`.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { assertNonNullable } from "../Assert.ts";
|
|
17
|
+
import { safelyStringifyUnknownValue } from "../String.ts";
|
|
18
|
+
import type {
|
|
19
|
+
ArrayError,
|
|
20
|
+
Base64UrlError,
|
|
21
|
+
BetweenError,
|
|
22
|
+
CapitalizedError,
|
|
23
|
+
DateIsoError,
|
|
24
|
+
DateIsoFromDateError,
|
|
25
|
+
DecimalStringError,
|
|
26
|
+
DiscriminatedUnionError,
|
|
27
|
+
EvoluTypeError,
|
|
28
|
+
FiniteError,
|
|
29
|
+
GreaterThanError,
|
|
30
|
+
GreaterThanOrEqualToError,
|
|
31
|
+
InstanceOfError,
|
|
32
|
+
Int64Error,
|
|
33
|
+
Int64StringError,
|
|
34
|
+
IntError,
|
|
35
|
+
IdError,
|
|
36
|
+
JsonError,
|
|
37
|
+
JsonValueError,
|
|
38
|
+
LengthError,
|
|
39
|
+
LessThanError,
|
|
40
|
+
LessThanOrEqualToError,
|
|
41
|
+
LiteralError,
|
|
42
|
+
MaxLengthError,
|
|
43
|
+
MinLengthError,
|
|
44
|
+
MnemonicError,
|
|
45
|
+
MultipleOfError,
|
|
46
|
+
NegativeDecimalStringError,
|
|
47
|
+
NegativeError,
|
|
48
|
+
NameError,
|
|
49
|
+
NeverError,
|
|
50
|
+
NonNaNError,
|
|
51
|
+
NonNegativeDecimalStringError,
|
|
52
|
+
NonNegativeError,
|
|
53
|
+
NonPositiveDecimalStringError,
|
|
54
|
+
NonPositiveError,
|
|
55
|
+
ObjectError,
|
|
56
|
+
ObjectNotObjectError,
|
|
57
|
+
ObjectPropertyAccessError,
|
|
58
|
+
ObjectTagError,
|
|
59
|
+
ObjectUnexpectedPrototypeError,
|
|
60
|
+
PositiveDecimalStringError,
|
|
61
|
+
PositiveError,
|
|
62
|
+
RecordError,
|
|
63
|
+
RegexError,
|
|
64
|
+
SetError,
|
|
65
|
+
TableIdError,
|
|
66
|
+
TemplateLiteralError,
|
|
67
|
+
TrimmedError,
|
|
68
|
+
TupleElementsError,
|
|
69
|
+
TupleError,
|
|
70
|
+
TypeError,
|
|
71
|
+
TypeErrorFormatter,
|
|
72
|
+
TypeOfError,
|
|
73
|
+
UInt64Error,
|
|
74
|
+
UnionError,
|
|
75
|
+
} from "../Type.ts";
|
|
76
|
+
|
|
77
|
+
const formatTypeOfError = (
|
|
78
|
+
error: TypeOfError<
|
|
79
|
+
"String" | "Number" | "BigInt" | "Boolean" | "Symbol" | "Function"
|
|
80
|
+
>,
|
|
81
|
+
): string => {
|
|
82
|
+
const typeOf = error.expected.toLowerCase();
|
|
83
|
+
|
|
84
|
+
return `A value ${safelyStringifyUnknownValue(error.value)} is not a ${typeOf}.`;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const formatPlainObjectRootError = (
|
|
88
|
+
reason:
|
|
89
|
+
ObjectNotObjectError["reason"] | ObjectUnexpectedPrototypeError["reason"],
|
|
90
|
+
): string =>
|
|
91
|
+
reason.kind === "NotObject"
|
|
92
|
+
? `A value ${safelyStringifyUnknownValue(reason.value)} is not an object.`
|
|
93
|
+
: "The value is an object, but an Object Output must be a plain object or have a null prototype.";
|
|
94
|
+
|
|
95
|
+
/** Formats a NeverError in English. */
|
|
96
|
+
export const formatNeverError: TypeErrorFormatter<NeverError> = (error) =>
|
|
97
|
+
`A value ${safelyStringifyUnknownValue(error.value)} is not valid for type Never.`;
|
|
98
|
+
|
|
99
|
+
/** Formats a String TypeOfError in English. */
|
|
100
|
+
export const formatStringError: TypeErrorFormatter<TypeOfError<"String">> =
|
|
101
|
+
formatTypeOfError;
|
|
102
|
+
|
|
103
|
+
/** Formats a TemplateLiteralError in English. */
|
|
104
|
+
export const formatTemplateLiteralError: TypeErrorFormatter<
|
|
105
|
+
TemplateLiteralError
|
|
106
|
+
> = (error) =>
|
|
107
|
+
`The value ${safelyStringifyUnknownValue(error.value)} does not match the template literal.`;
|
|
108
|
+
|
|
109
|
+
/** Formats a Number TypeOfError in English. */
|
|
110
|
+
export const formatNumberError: TypeErrorFormatter<TypeOfError<"Number">> =
|
|
111
|
+
formatTypeOfError;
|
|
112
|
+
|
|
113
|
+
/** Formats a BigInt TypeOfError in English. */
|
|
114
|
+
export const formatBigIntError: TypeErrorFormatter<TypeOfError<"BigInt">> =
|
|
115
|
+
formatTypeOfError;
|
|
116
|
+
|
|
117
|
+
/** Formats a Boolean TypeOfError in English. */
|
|
118
|
+
export const formatBooleanError: TypeErrorFormatter<TypeOfError<"Boolean">> =
|
|
119
|
+
formatTypeOfError;
|
|
120
|
+
|
|
121
|
+
/** Formats a Symbol TypeOfError in English. */
|
|
122
|
+
export const formatSymbolError: TypeErrorFormatter<TypeOfError<"Symbol">> =
|
|
123
|
+
formatTypeOfError;
|
|
124
|
+
|
|
125
|
+
/** Formats a Function TypeOfError in English. */
|
|
126
|
+
export const formatFunctionError: TypeErrorFormatter<TypeOfError<"Function">> =
|
|
127
|
+
formatTypeOfError;
|
|
128
|
+
|
|
129
|
+
/** Formats an EvoluTypeError in English. */
|
|
130
|
+
export const formatEvoluTypeError: TypeErrorFormatter<EvoluTypeError> = (
|
|
131
|
+
error,
|
|
132
|
+
) =>
|
|
133
|
+
`A value ${safelyStringifyUnknownValue(error.value)} is not an Evolu Type.`;
|
|
134
|
+
|
|
135
|
+
/** Formats an ObjectTagError in English. */
|
|
136
|
+
export const formatObjectTagError: TypeErrorFormatter<ObjectTagError> = (
|
|
137
|
+
error,
|
|
138
|
+
) =>
|
|
139
|
+
`A value ${safelyStringifyUnknownValue(error.value)} does not have the expected object tag ${safelyStringifyUnknownValue(error.expected)}.`;
|
|
140
|
+
|
|
141
|
+
/** Formats an InstanceOfError in English. */
|
|
142
|
+
export const formatInstanceOfError: TypeErrorFormatter<InstanceOfError> = (
|
|
143
|
+
error,
|
|
144
|
+
) =>
|
|
145
|
+
`A value ${safelyStringifyUnknownValue(error.value)} is not an instance of ${error.constructorName}.`;
|
|
146
|
+
|
|
147
|
+
/** Formats a LiteralError in English. */
|
|
148
|
+
export const formatLiteralError: TypeErrorFormatter<LiteralError> = (error) =>
|
|
149
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not strictly equal to the expected literal: ${globalThis.String(error.expected)}.`;
|
|
150
|
+
|
|
151
|
+
/** Formats a UnionError in English. */
|
|
152
|
+
export const formatUnionError: TypeErrorFormatter<UnionError> = () =>
|
|
153
|
+
"A value does not match any allowed variant.";
|
|
154
|
+
|
|
155
|
+
/** Formats a DateIsoError in English. */
|
|
156
|
+
export const formatDateIsoError: TypeErrorFormatter<DateIsoError> = (error) =>
|
|
157
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a canonical ISO date-time string.`;
|
|
158
|
+
|
|
159
|
+
/** Formats a DateIsoFromDateError in English. */
|
|
160
|
+
export const formatDateIsoFromDateError: TypeErrorFormatter<
|
|
161
|
+
DateIsoFromDateError
|
|
162
|
+
> = () => "The Date cannot be represented as DateIso.";
|
|
163
|
+
|
|
164
|
+
/** Formats a DecimalStringError in English. */
|
|
165
|
+
export const formatDecimalStringError: TypeErrorFormatter<
|
|
166
|
+
DecimalStringError
|
|
167
|
+
> = (error) =>
|
|
168
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a canonical decimal string.`;
|
|
169
|
+
|
|
170
|
+
/** Formats an Int64Error in English. */
|
|
171
|
+
export const formatInt64Error: TypeErrorFormatter<Int64Error> = (error) =>
|
|
172
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid signed 64-bit integer (Int64).`;
|
|
173
|
+
|
|
174
|
+
/** Formats a UInt64Error in English. */
|
|
175
|
+
export const formatUInt64Error: TypeErrorFormatter<UInt64Error> = (error) =>
|
|
176
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid unsigned 64-bit integer (UInt64).`;
|
|
177
|
+
|
|
178
|
+
/** Formats an Int64StringError in English. */
|
|
179
|
+
export const formatInt64StringError: TypeErrorFormatter<Int64StringError> = (
|
|
180
|
+
error,
|
|
181
|
+
) =>
|
|
182
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid Int64 string.`;
|
|
183
|
+
|
|
184
|
+
/** Formats a CapitalizedError in English. */
|
|
185
|
+
export const formatCapitalizedError: TypeErrorFormatter<CapitalizedError> = (
|
|
186
|
+
error,
|
|
187
|
+
) =>
|
|
188
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be capitalized.`;
|
|
189
|
+
|
|
190
|
+
/** Formats a TrimmedError in English. */
|
|
191
|
+
export const formatTrimmedError: TypeErrorFormatter<TrimmedError> = (error) =>
|
|
192
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be trimmed.`;
|
|
193
|
+
|
|
194
|
+
/** Formats a MinLengthError in English. */
|
|
195
|
+
export const formatMinLengthError: TypeErrorFormatter<MinLengthError> = (
|
|
196
|
+
error,
|
|
197
|
+
) =>
|
|
198
|
+
`The value ${safelyStringifyUnknownValue(error.value)} does not meet the minimum length of ${error.min}.`;
|
|
199
|
+
|
|
200
|
+
/** Formats a MaxLengthError in English. */
|
|
201
|
+
export const formatMaxLengthError: TypeErrorFormatter<MaxLengthError> = (
|
|
202
|
+
error,
|
|
203
|
+
) =>
|
|
204
|
+
`The value ${safelyStringifyUnknownValue(error.value)} exceeds the maximum length of ${error.max}.`;
|
|
205
|
+
|
|
206
|
+
/** Formats a LengthError in English. */
|
|
207
|
+
export const formatLengthError: TypeErrorFormatter<LengthError> = (error) =>
|
|
208
|
+
`The value ${safelyStringifyUnknownValue(error.value)} does not have the required length of ${error.exact}.`;
|
|
209
|
+
|
|
210
|
+
/** Formats a RegexError in English. */
|
|
211
|
+
export const formatRegexError: TypeErrorFormatter<RegexError> = (error) =>
|
|
212
|
+
`The value ${safelyStringifyUnknownValue(error.value)} does not match /${error.source}/${error.flags}.`;
|
|
213
|
+
|
|
214
|
+
/** Formats a Base64UrlError in English. */
|
|
215
|
+
export const formatBase64UrlError: TypeErrorFormatter<Base64UrlError> = (
|
|
216
|
+
error,
|
|
217
|
+
) =>
|
|
218
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid Base64Url string.`;
|
|
219
|
+
|
|
220
|
+
/** Formats a NameError in English. */
|
|
221
|
+
export const formatNameError: TypeErrorFormatter<NameError> = (error) =>
|
|
222
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid Name.`;
|
|
223
|
+
|
|
224
|
+
/** Formats a MnemonicError in English. */
|
|
225
|
+
export const formatMnemonicError: TypeErrorFormatter<MnemonicError> = (error) =>
|
|
226
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid English BIP39 mnemonic.`;
|
|
227
|
+
|
|
228
|
+
/** Formats an IdError in English. */
|
|
229
|
+
export const formatIdError: TypeErrorFormatter<IdError> = (error) =>
|
|
230
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid Id.`;
|
|
231
|
+
|
|
232
|
+
/** Formats a TableIdError in English. */
|
|
233
|
+
export const formatTableIdError: TypeErrorFormatter<TableIdError> = (error) =>
|
|
234
|
+
`The value ${safelyStringifyUnknownValue(error.value)} is not a valid Id for table ${error.table}.`;
|
|
235
|
+
|
|
236
|
+
/** Formats a NonNegativeError in English. */
|
|
237
|
+
export const formatNonNegativeError: TypeErrorFormatter<NonNegativeError> = (
|
|
238
|
+
error,
|
|
239
|
+
) =>
|
|
240
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be non-negative (>= 0).`;
|
|
241
|
+
|
|
242
|
+
/** Formats a NonNegativeDecimalStringError in English. */
|
|
243
|
+
export const formatNonNegativeDecimalStringError: TypeErrorFormatter<
|
|
244
|
+
NonNegativeDecimalStringError
|
|
245
|
+
> = (error) =>
|
|
246
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a non-negative decimal string.`;
|
|
247
|
+
|
|
248
|
+
/** Formats a PositiveError in English. */
|
|
249
|
+
export const formatPositiveError: TypeErrorFormatter<PositiveError> = (error) =>
|
|
250
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be positive (> 0).`;
|
|
251
|
+
|
|
252
|
+
/** Formats a PositiveDecimalStringError in English. */
|
|
253
|
+
export const formatPositiveDecimalStringError: TypeErrorFormatter<
|
|
254
|
+
PositiveDecimalStringError
|
|
255
|
+
> = (error) =>
|
|
256
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a positive decimal string.`;
|
|
257
|
+
|
|
258
|
+
/** Formats a NonPositiveError in English. */
|
|
259
|
+
export const formatNonPositiveError: TypeErrorFormatter<NonPositiveError> = (
|
|
260
|
+
error,
|
|
261
|
+
) =>
|
|
262
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be non-positive (<= 0).`;
|
|
263
|
+
|
|
264
|
+
/** Formats a NonPositiveDecimalStringError in English. */
|
|
265
|
+
export const formatNonPositiveDecimalStringError: TypeErrorFormatter<
|
|
266
|
+
NonPositiveDecimalStringError
|
|
267
|
+
> = (error) =>
|
|
268
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a non-positive decimal string.`;
|
|
269
|
+
|
|
270
|
+
/** Formats a NegativeError in English. */
|
|
271
|
+
export const formatNegativeError: TypeErrorFormatter<NegativeError> = (error) =>
|
|
272
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be negative (< 0).`;
|
|
273
|
+
|
|
274
|
+
/** Formats a NegativeDecimalStringError in English. */
|
|
275
|
+
export const formatNegativeDecimalStringError: TypeErrorFormatter<
|
|
276
|
+
NegativeDecimalStringError
|
|
277
|
+
> = (error) =>
|
|
278
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a negative decimal string.`;
|
|
279
|
+
|
|
280
|
+
/** Formats an IntError in English. */
|
|
281
|
+
export const formatIntError: TypeErrorFormatter<IntError> = (error) =>
|
|
282
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a safe integer.`;
|
|
283
|
+
|
|
284
|
+
/** Formats a GreaterThanError in English. */
|
|
285
|
+
export const formatGreaterThanError: TypeErrorFormatter<GreaterThanError> = (
|
|
286
|
+
error,
|
|
287
|
+
) =>
|
|
288
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be greater than ${error.min}.`;
|
|
289
|
+
|
|
290
|
+
/** Formats a GreaterThanOrEqualToError in English. */
|
|
291
|
+
export const formatGreaterThanOrEqualToError: TypeErrorFormatter<
|
|
292
|
+
GreaterThanOrEqualToError
|
|
293
|
+
> = (error) =>
|
|
294
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be greater than or equal to ${error.min}.`;
|
|
295
|
+
|
|
296
|
+
/** Formats a LessThanError in English. */
|
|
297
|
+
export const formatLessThanError: TypeErrorFormatter<LessThanError> = (error) =>
|
|
298
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be less than ${error.max}.`;
|
|
299
|
+
|
|
300
|
+
/** Formats a LessThanOrEqualToError in English. */
|
|
301
|
+
export const formatLessThanOrEqualToError: TypeErrorFormatter<
|
|
302
|
+
LessThanOrEqualToError
|
|
303
|
+
> = (error) =>
|
|
304
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be less than or equal to ${error.max}.`;
|
|
305
|
+
|
|
306
|
+
/** Formats a NonNaNError in English. */
|
|
307
|
+
export const formatNonNaNError: TypeErrorFormatter<NonNaNError> = () =>
|
|
308
|
+
"The value must not be NaN.";
|
|
309
|
+
|
|
310
|
+
/** Formats a FiniteError in English. */
|
|
311
|
+
export const formatFiniteError: TypeErrorFormatter<FiniteError> = (error) =>
|
|
312
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be finite.`;
|
|
313
|
+
|
|
314
|
+
/** Formats a MultipleOfError in English. */
|
|
315
|
+
export const formatMultipleOfError: TypeErrorFormatter<MultipleOfError> = (
|
|
316
|
+
error,
|
|
317
|
+
) =>
|
|
318
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be a multiple of ${error.divisor}.`;
|
|
319
|
+
|
|
320
|
+
/** Formats a BetweenError in English. */
|
|
321
|
+
export const formatBetweenError: TypeErrorFormatter<BetweenError> = (error) =>
|
|
322
|
+
`The value ${safelyStringifyUnknownValue(error.value)} must be between ${error.min} and ${error.max}, inclusive.`;
|
|
323
|
+
|
|
324
|
+
/** Formats an ArrayError in English. */
|
|
325
|
+
export const formatArrayError: TypeErrorFormatter<ArrayError> = (error) => {
|
|
326
|
+
if (error.reason.kind === "NotArray") {
|
|
327
|
+
return `A value ${safelyStringifyUnknownValue(error.reason.value)} is not an array.`;
|
|
328
|
+
}
|
|
329
|
+
const issue = error.reason.issues[0];
|
|
330
|
+
|
|
331
|
+
switch (issue.kind) {
|
|
332
|
+
case "Hole":
|
|
333
|
+
return `An array element at index ${issue.index} is missing.`;
|
|
334
|
+
case "Accessor":
|
|
335
|
+
return `An array element at index ${issue.index} must be a data property.`;
|
|
336
|
+
case "ExcessProperty":
|
|
337
|
+
return "An excess Array property is not allowed. Remove it or use a different Type.";
|
|
338
|
+
case "Element":
|
|
339
|
+
return `An array element at index ${issue.index} is invalid.`;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
/** Formats a SetError in English. */
|
|
344
|
+
export const formatSetError: TypeErrorFormatter<SetError> = (error) => {
|
|
345
|
+
if (error.reason.kind === "NotSet") {
|
|
346
|
+
return `A value ${safelyStringifyUnknownValue(error.reason.value)} is not a Set.`;
|
|
347
|
+
}
|
|
348
|
+
if (error.reason.kind === "UnexpectedPrototype") {
|
|
349
|
+
return "The value is an instance of a Set subclass, but a Set Output must be a direct Set instance.";
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const issue = error.reason.issues[0];
|
|
353
|
+
|
|
354
|
+
switch (issue.kind) {
|
|
355
|
+
case "ExcessProperty":
|
|
356
|
+
return `An excess Set property ${safelyStringifyUnknownValue(issue.key)} is not allowed.`;
|
|
357
|
+
case "Element":
|
|
358
|
+
return `A Set element at index ${issue.index} is invalid.`;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/** Formats a TupleError in English. */
|
|
363
|
+
export const formatTupleError: TypeErrorFormatter<
|
|
364
|
+
TupleError | TupleElementsError<TypeError>
|
|
365
|
+
> = (error) => {
|
|
366
|
+
if (error.reason.kind === "NotArray") {
|
|
367
|
+
return `A value ${safelyStringifyUnknownValue(error.reason.value)} is not a tuple.`;
|
|
368
|
+
}
|
|
369
|
+
if (error.reason.kind === "InvalidLength") {
|
|
370
|
+
return `A Tuple must contain exactly ${error.reason.expected} elements, but the value contains ${error.reason.actual}.`;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const issue = error.reason.issues[0];
|
|
374
|
+
|
|
375
|
+
switch (issue.kind) {
|
|
376
|
+
case "Hole":
|
|
377
|
+
return `A Tuple element at index ${issue.index} is missing.`;
|
|
378
|
+
case "Accessor":
|
|
379
|
+
return `A Tuple element at index ${issue.index} must be a data property.`;
|
|
380
|
+
case "ExcessProperty":
|
|
381
|
+
return "An excess Tuple property is not allowed. Remove it or use a different Type.";
|
|
382
|
+
case "Element":
|
|
383
|
+
return `A Tuple element at index ${issue.index} is invalid.`;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
/** Formats a RecordError in English. */
|
|
388
|
+
export const formatRecordError: TypeErrorFormatter<RecordError> = (error) => {
|
|
389
|
+
if (error.reason.kind === "NotRecord") {
|
|
390
|
+
return `A value ${safelyStringifyUnknownValue(error.reason.value)} is not a Record.`;
|
|
391
|
+
}
|
|
392
|
+
if (error.reason.kind === "NotPlainRecord") {
|
|
393
|
+
return "The value is an object, but a Record Output must be a plain object or have a null prototype.";
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const issue = error.reason.issues[0];
|
|
397
|
+
|
|
398
|
+
switch (issue.kind) {
|
|
399
|
+
case "Key":
|
|
400
|
+
return `Property key ${safelyStringifyUnknownValue(issue.key)} is invalid.`;
|
|
401
|
+
case "Value":
|
|
402
|
+
return `The value of property ${safelyStringifyUnknownValue(issue.key)} is invalid.`;
|
|
403
|
+
case "Accessor":
|
|
404
|
+
return `A Record property ${safelyStringifyUnknownValue(issue.key)} must be a data property.`;
|
|
405
|
+
case "NonEnumerable":
|
|
406
|
+
return `A Record property ${safelyStringifyUnknownValue(issue.key)} must be enumerable.`;
|
|
407
|
+
case "Collision":
|
|
408
|
+
return `Record keys ${safelyStringifyUnknownValue(issue.previousKey)} and ${safelyStringifyUnknownValue(issue.key)} decode to the same key ${safelyStringifyUnknownValue(issue.outputKey)}.`;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/** Formats an ObjectError in English. */
|
|
413
|
+
export const formatObjectError: TypeErrorFormatter<ObjectError> = (error) => {
|
|
414
|
+
if (error.reason.kind !== "Properties") {
|
|
415
|
+
return formatPlainObjectRootError(error.reason);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const key = Reflect.ownKeys(error.reason.errors).at(0);
|
|
419
|
+
assertNonNullable(key);
|
|
420
|
+
const propertyError = error.reason.errors[key];
|
|
421
|
+
assertNonNullable(propertyError);
|
|
422
|
+
|
|
423
|
+
if (propertyError.type === "ObjectPropertyAccess") {
|
|
424
|
+
switch ((propertyError as ObjectPropertyAccessError).reason) {
|
|
425
|
+
case "Accessor":
|
|
426
|
+
return "An Object property must be a data property. Materialize accessor values into plain data before using this Type or use a different Type.";
|
|
427
|
+
case "NonEnumerable":
|
|
428
|
+
return "An Object property must be enumerable. Make it enumerable or use a different Type.";
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (propertyError.type === "ObjectMissingProperty") {
|
|
432
|
+
return `The required property ${safelyStringifyUnknownValue(key)} is missing.`;
|
|
433
|
+
}
|
|
434
|
+
if (typeof key === "symbol") {
|
|
435
|
+
return "An Object property key must be a string. Remove the symbol property or use a different Type.";
|
|
436
|
+
}
|
|
437
|
+
if (propertyError.type === "ObjectExcessProperty") {
|
|
438
|
+
return `The property ${safelyStringifyUnknownValue(key)} is not allowed. Remove it or use a different Type.`;
|
|
439
|
+
}
|
|
440
|
+
return `The property ${safelyStringifyUnknownValue(key)} is invalid.`;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
/** Formats a DiscriminatedUnionError in English. */
|
|
444
|
+
export const formatDiscriminatedUnionError: TypeErrorFormatter<
|
|
445
|
+
DiscriminatedUnionError
|
|
446
|
+
> = (error) => {
|
|
447
|
+
switch (error.reason.kind) {
|
|
448
|
+
case "Object":
|
|
449
|
+
return formatPlainObjectRootError(error.reason.error.reason);
|
|
450
|
+
case "PropertyAccess": {
|
|
451
|
+
const property = `The discriminator property ${safelyStringifyUnknownValue(error.reason.key)}`;
|
|
452
|
+
if (error.reason.reason === "Accessor") {
|
|
453
|
+
return `${property} must be a data property.`;
|
|
454
|
+
}
|
|
455
|
+
if (error.reason.reason === "Inherited") {
|
|
456
|
+
return `${property} must be an own property.`;
|
|
457
|
+
}
|
|
458
|
+
return `${property} must be enumerable.`;
|
|
459
|
+
}
|
|
460
|
+
case "Discriminator":
|
|
461
|
+
return `The discriminator property ${safelyStringifyUnknownValue(error.reason.key)} has an unexpected value ${safelyStringifyUnknownValue(error.reason.value)}.`;
|
|
462
|
+
case "Member":
|
|
463
|
+
return `The selected variant ${safelyStringifyUnknownValue(error.reason.discriminator)} is invalid.`;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
/** Formats a JsonValueError in English. */
|
|
468
|
+
export const formatJsonValueError: TypeErrorFormatter<JsonValueError> = (
|
|
469
|
+
error,
|
|
470
|
+
) => {
|
|
471
|
+
const issue = error.reason.issues[0];
|
|
472
|
+
|
|
473
|
+
switch (issue.kind) {
|
|
474
|
+
case "InvalidType":
|
|
475
|
+
return `A value ${safelyStringifyUnknownValue(issue.value)} is not a JSON value.`;
|
|
476
|
+
case "NonFiniteNumber":
|
|
477
|
+
return "A JSON number must be finite.";
|
|
478
|
+
case "UnexpectedPrototype":
|
|
479
|
+
return "The value is an object, but a JsonValue object must be a plain object or have a null prototype.";
|
|
480
|
+
case "Accessor":
|
|
481
|
+
return "A JSON property must be a data property. Materialize accessor values into plain data before using this Type or use a different Type.";
|
|
482
|
+
case "NonEnumerable":
|
|
483
|
+
return "A JSON object property must be enumerable. Remove it or use a different Type.";
|
|
484
|
+
case "SymbolProperty":
|
|
485
|
+
return "A JSON object property key must be a string. Remove the symbol property or use a different Type.";
|
|
486
|
+
case "Hole":
|
|
487
|
+
return "A JSON array element is missing.";
|
|
488
|
+
case "ExcessProperty":
|
|
489
|
+
return "An excess JSON array property is not allowed. Remove it or use a different Type.";
|
|
490
|
+
case "CircularReference":
|
|
491
|
+
return "A JsonValue must not contain circular references.";
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
/** Formats a JsonError in English. */
|
|
496
|
+
export const formatJsonError: TypeErrorFormatter<JsonError> = (error) =>
|
|
497
|
+
`The value ${safelyStringifyUnknownValue(error.value)} cannot be parsed into a JsonValue.`;
|