@evolu/common 7.3.0 → 7.4.1
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/Buffer.d.ts +2 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +1 -0
- package/dist/src/Callbacks.d.ts +1 -1
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +1 -1
- package/dist/src/Console.d.ts +1 -9
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +1 -41
- package/dist/src/Instances.d.ts.map +1 -1
- package/dist/src/Redacted.d.ts +89 -0
- package/dist/src/Redacted.d.ts.map +1 -0
- package/dist/src/Redacted.js +48 -0
- package/dist/src/Type.d.ts +5 -9
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +0 -202
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +4 -0
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Public.d.ts +6 -1
- package/dist/src/local-first/Public.d.ts.map +1 -1
- package/dist/src/local-first/Public.js +6 -1
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Sync.d.ts.map +1 -1
- package/dist/src/local-first/Sync.js +10 -13
- package/dist/src/local-first/index.d.ts +9 -1
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +9 -1
- package/package.json +3 -4
- package/src/Buffer.ts +2 -1
- package/src/Callbacks.ts +1 -1
- package/src/Console.ts +1 -10
- package/src/Instances.ts +4 -2
- package/src/Redacted.ts +118 -0
- package/src/Type.ts +229 -221
- package/src/index.ts +1 -0
- package/src/local-first/Evolu.ts +3 -2
- package/src/local-first/Owner.ts +4 -0
- package/src/local-first/Public.ts +6 -1
- package/src/local-first/Storage.ts +10 -12
- package/src/local-first/Sync.ts +10 -21
- package/src/local-first/index.ts +9 -1
package/src/Type.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
import { utf8ToBytes } from "@noble/ciphers/utils.js";
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
3
|
+
import * as bip39 from "@scure/bip39";
|
|
4
|
+
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
5
|
+
import { pack } from "msgpackr";
|
|
6
|
+
import type { Brand } from "./Brand.js";
|
|
7
|
+
import type { RandomBytesDep } from "./Crypto.js";
|
|
8
|
+
import { isPlainObject } from "./Object.js";
|
|
9
|
+
import { hasNodeBuffer } from "./Platform.js";
|
|
10
|
+
import { err, getOrNull, getOrThrow, ok, Result, trySync } from "./Result.js";
|
|
11
|
+
import { safelyStringifyUnknownValue } from "./String.js";
|
|
12
|
+
import type { TimeDep } from "./Time.js";
|
|
13
|
+
import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
|
|
14
|
+
import { IntentionalNever } from "./Types.js";
|
|
15
|
+
|
|
1
16
|
/**
|
|
2
|
-
* Runtime types
|
|
3
|
-
*
|
|
4
17
|
* Evolu {@link Type} is like a type guard that returns typed errors (via
|
|
5
18
|
* {@link Result}) instead of throwing. We either get a safely typed value or a
|
|
6
19
|
* composable typed error telling us exactly why validation failed.
|
|
@@ -197,25 +210,7 @@
|
|
|
197
210
|
* ```
|
|
198
211
|
*
|
|
199
212
|
* Note `minLength` and `maxLength` are curried because they are factories.
|
|
200
|
-
*
|
|
201
|
-
* @module
|
|
202
213
|
*/
|
|
203
|
-
|
|
204
|
-
import { utf8ToBytes } from "@noble/ciphers/utils.js";
|
|
205
|
-
import { sha256 } from "@noble/hashes/sha2.js";
|
|
206
|
-
import * as bip39 from "@scure/bip39";
|
|
207
|
-
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
208
|
-
import { pack } from "msgpackr";
|
|
209
|
-
import type { Brand } from "./Brand.js";
|
|
210
|
-
import type { RandomBytesDep } from "./Crypto.js";
|
|
211
|
-
import { isPlainObject } from "./Object.js";
|
|
212
|
-
import { hasNodeBuffer } from "./Platform.js";
|
|
213
|
-
import { err, getOrNull, getOrThrow, ok, Result, trySync } from "./Result.js";
|
|
214
|
-
import { safelyStringifyUnknownValue } from "./String.js";
|
|
215
|
-
import type { TimeDep } from "./Time.js";
|
|
216
|
-
import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
|
|
217
|
-
import { IntentionalNever } from "./Types.js";
|
|
218
|
-
|
|
219
214
|
export interface Type<
|
|
220
215
|
Name extends TypeName,
|
|
221
216
|
/** The type this Type resolves to. */
|
|
@@ -796,13 +791,14 @@ export interface InstanceOfError extends TypeError<"InstanceOf"> {
|
|
|
796
791
|
readonly ctor: string;
|
|
797
792
|
}
|
|
798
793
|
|
|
799
|
-
export interface InstanceOfType<
|
|
800
|
-
extends
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
794
|
+
export interface InstanceOfType<
|
|
795
|
+
T extends abstract new (...args: any) => any,
|
|
796
|
+
> extends Type<
|
|
797
|
+
"InstanceOf",
|
|
798
|
+
InstanceType<T>,
|
|
799
|
+
InstanceType<T>,
|
|
800
|
+
InstanceOfError
|
|
801
|
+
> {
|
|
806
802
|
ctor: T;
|
|
807
803
|
}
|
|
808
804
|
|
|
@@ -1036,13 +1032,13 @@ export interface BrandType<
|
|
|
1036
1032
|
Error extends TypeError = never,
|
|
1037
1033
|
ParentError extends TypeError = never,
|
|
1038
1034
|
> extends Type<
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1035
|
+
"Brand",
|
|
1036
|
+
InferType<ParentType> & Brand<Name>,
|
|
1037
|
+
InferInput<ParentType>,
|
|
1038
|
+
Error,
|
|
1039
|
+
InferType<ParentType>,
|
|
1040
|
+
ParentError
|
|
1041
|
+
> {
|
|
1046
1042
|
readonly brand: Name;
|
|
1047
1043
|
readonly parentType: ParentType;
|
|
1048
1044
|
}
|
|
@@ -1229,8 +1225,9 @@ export const minLength: <Min extends number>(
|
|
|
1229
1225
|
value.length >= min ? ok(value) : err({ type: "MinLength", value, min }),
|
|
1230
1226
|
);
|
|
1231
1227
|
|
|
1232
|
-
export interface MinLengthError<
|
|
1233
|
-
extends
|
|
1228
|
+
export interface MinLengthError<
|
|
1229
|
+
Min extends number = number,
|
|
1230
|
+
> extends TypeError<"MinLength"> {
|
|
1234
1231
|
readonly min: Min;
|
|
1235
1232
|
}
|
|
1236
1233
|
|
|
@@ -1260,8 +1257,9 @@ export const maxLength: <Max extends number>(
|
|
|
1260
1257
|
value.length <= max ? ok(value) : err({ type: "MaxLength", value, max }),
|
|
1261
1258
|
);
|
|
1262
1259
|
|
|
1263
|
-
export interface MaxLengthError<
|
|
1264
|
-
extends
|
|
1260
|
+
export interface MaxLengthError<
|
|
1261
|
+
Max extends number = number,
|
|
1262
|
+
> extends TypeError<"MaxLength"> {
|
|
1265
1263
|
readonly max: Max;
|
|
1266
1264
|
}
|
|
1267
1265
|
|
|
@@ -1293,8 +1291,9 @@ export const length: <Exact extends number>(
|
|
|
1293
1291
|
: err({ type: "Length", value, exact }),
|
|
1294
1292
|
);
|
|
1295
1293
|
|
|
1296
|
-
export interface LengthError<
|
|
1297
|
-
extends
|
|
1294
|
+
export interface LengthError<
|
|
1295
|
+
Exact extends number = number,
|
|
1296
|
+
> extends TypeError<"Length"> {
|
|
1298
1297
|
readonly exact: Exact;
|
|
1299
1298
|
}
|
|
1300
1299
|
|
|
@@ -1393,8 +1392,9 @@ export const regex: <Name extends TypeName>(
|
|
|
1393
1392
|
});
|
|
1394
1393
|
};
|
|
1395
1394
|
|
|
1396
|
-
export interface RegexError<
|
|
1397
|
-
extends
|
|
1395
|
+
export interface RegexError<
|
|
1396
|
+
Name extends TypeName = TypeName,
|
|
1397
|
+
> extends TypeError<"Regex"> {
|
|
1398
1398
|
readonly name: Name;
|
|
1399
1399
|
readonly pattern: RegExp;
|
|
1400
1400
|
}
|
|
@@ -1762,20 +1762,20 @@ export const id = <Table extends TypeName>(table: Table): TableId<Table> => {
|
|
|
1762
1762
|
};
|
|
1763
1763
|
};
|
|
1764
1764
|
|
|
1765
|
-
export interface TableId<Table extends TypeName>
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
> {
|
|
1765
|
+
export interface TableId<Table extends TypeName> extends Type<
|
|
1766
|
+
"Id",
|
|
1767
|
+
string & Brand<"Id"> & Brand<Table>,
|
|
1768
|
+
string,
|
|
1769
|
+
TableIdError<Table>,
|
|
1770
|
+
string,
|
|
1771
|
+
StringError
|
|
1772
|
+
> {
|
|
1774
1773
|
table: Table;
|
|
1775
1774
|
}
|
|
1776
1775
|
|
|
1777
|
-
export interface TableIdError<
|
|
1778
|
-
extends
|
|
1776
|
+
export interface TableIdError<
|
|
1777
|
+
Table extends TypeName = TypeName,
|
|
1778
|
+
> extends TypeError<"TableId"> {
|
|
1779
1779
|
readonly table: Table;
|
|
1780
1780
|
}
|
|
1781
1781
|
|
|
@@ -2020,8 +2020,9 @@ export const greaterThan: <Min extends number>(
|
|
|
2020
2020
|
value > min ? ok(value) : err({ type: "GreaterThan", value, min }),
|
|
2021
2021
|
);
|
|
2022
2022
|
|
|
2023
|
-
export interface GreaterThanError<
|
|
2024
|
-
extends
|
|
2023
|
+
export interface GreaterThanError<
|
|
2024
|
+
Min extends number = number,
|
|
2025
|
+
> extends TypeError<"GreaterThan"> {
|
|
2025
2026
|
readonly min: Min;
|
|
2026
2027
|
}
|
|
2027
2028
|
|
|
@@ -2043,8 +2044,9 @@ export const lessThan: <Max extends number>(
|
|
|
2043
2044
|
value < max ? ok(value) : err({ type: "LessThan", value, max }),
|
|
2044
2045
|
);
|
|
2045
2046
|
|
|
2046
|
-
export interface LessThanError<
|
|
2047
|
-
extends
|
|
2047
|
+
export interface LessThanError<
|
|
2048
|
+
Max extends number = number,
|
|
2049
|
+
> extends TypeError<"LessThan"> {
|
|
2048
2050
|
readonly max: Max;
|
|
2049
2051
|
}
|
|
2050
2052
|
|
|
@@ -2070,8 +2072,9 @@ export const greaterThanOrEqualTo: <Min extends number>(
|
|
|
2070
2072
|
: err({ type: "GreaterThanOrEqualTo", value, min }),
|
|
2071
2073
|
);
|
|
2072
2074
|
|
|
2073
|
-
export interface GreaterThanOrEqualToError<
|
|
2074
|
-
extends
|
|
2075
|
+
export interface GreaterThanOrEqualToError<
|
|
2076
|
+
Min extends number = number,
|
|
2077
|
+
> extends TypeError<"GreaterThanOrEqualTo"> {
|
|
2075
2078
|
readonly min: Min;
|
|
2076
2079
|
}
|
|
2077
2080
|
|
|
@@ -2096,8 +2099,9 @@ export const lessThanOrEqualTo: <Max extends number>(
|
|
|
2096
2099
|
value <= max ? ok(value) : err({ type: "LessThanOrEqualTo", value, max }),
|
|
2097
2100
|
);
|
|
2098
2101
|
|
|
2099
|
-
export interface LessThanOrEqualToError<
|
|
2100
|
-
extends
|
|
2102
|
+
export interface LessThanOrEqualToError<
|
|
2103
|
+
Max extends number = number,
|
|
2104
|
+
> extends TypeError<"LessThanOrEqualTo"> {
|
|
2101
2105
|
readonly max: Max;
|
|
2102
2106
|
}
|
|
2103
2107
|
|
|
@@ -2177,8 +2181,9 @@ export const multipleOf: <Divisor extends number>(
|
|
|
2177
2181
|
: err({ type: "MultipleOf", value, divisor }),
|
|
2178
2182
|
);
|
|
2179
2183
|
|
|
2180
|
-
export interface MultipleOfError<
|
|
2181
|
-
extends
|
|
2184
|
+
export interface MultipleOfError<
|
|
2185
|
+
Divisor extends number = number,
|
|
2186
|
+
> extends TypeError<"MultipleOf"> {
|
|
2182
2187
|
readonly divisor: Divisor;
|
|
2183
2188
|
}
|
|
2184
2189
|
|
|
@@ -2255,13 +2260,18 @@ export const literal = <T extends Literal>(expected: T): LiteralType<T> => {
|
|
|
2255
2260
|
} as LiteralType<T>;
|
|
2256
2261
|
};
|
|
2257
2262
|
|
|
2258
|
-
export interface LiteralType<T extends Literal>
|
|
2259
|
-
|
|
2263
|
+
export interface LiteralType<T extends Literal> extends Type<
|
|
2264
|
+
"Literal",
|
|
2265
|
+
T,
|
|
2266
|
+
WidenLiteral<T>,
|
|
2267
|
+
LiteralError<T>
|
|
2268
|
+
> {
|
|
2260
2269
|
expected: T;
|
|
2261
2270
|
}
|
|
2262
2271
|
|
|
2263
|
-
export interface LiteralError<
|
|
2264
|
-
extends
|
|
2272
|
+
export interface LiteralError<
|
|
2273
|
+
T extends Literal = Literal,
|
|
2274
|
+
> extends TypeError<"Literal"> {
|
|
2265
2275
|
readonly expected: T;
|
|
2266
2276
|
}
|
|
2267
2277
|
|
|
@@ -2356,28 +2366,28 @@ export const array = <ElementType extends AnyType>(
|
|
|
2356
2366
|
};
|
|
2357
2367
|
|
|
2358
2368
|
/** ArrayType extends Type with an additional `element` property for reflection. */
|
|
2359
|
-
export interface ArrayType<ElementType extends AnyType>
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
> {
|
|
2369
|
+
export interface ArrayType<ElementType extends AnyType> extends Type<
|
|
2370
|
+
"Array",
|
|
2371
|
+
ReadonlyArray<InferType<ElementType>>,
|
|
2372
|
+
ReadonlyArray<InferInput<ElementType>>,
|
|
2373
|
+
ArrayError<InferError<ElementType>>,
|
|
2374
|
+
ReadonlyArray<InferParent<ElementType>>,
|
|
2375
|
+
ArrayError<InferParentError<ElementType>>
|
|
2376
|
+
> {
|
|
2368
2377
|
readonly element: ElementType;
|
|
2369
2378
|
}
|
|
2370
2379
|
|
|
2371
|
-
export interface ArrayError<
|
|
2372
|
-
extends
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2380
|
+
export interface ArrayError<
|
|
2381
|
+
Error extends TypeError = TypeError,
|
|
2382
|
+
> extends TypeErrorWithReason<
|
|
2383
|
+
"Array",
|
|
2384
|
+
| { readonly kind: "NotArray" }
|
|
2385
|
+
| {
|
|
2386
|
+
readonly kind: "Element";
|
|
2387
|
+
readonly index: number;
|
|
2388
|
+
readonly error: Error;
|
|
2389
|
+
}
|
|
2390
|
+
> {}
|
|
2381
2391
|
|
|
2382
2392
|
export const formatArrayError = <Error extends TypeError>(
|
|
2383
2393
|
formatTypeError: TypeErrorFormatter<Error>,
|
|
@@ -2474,28 +2484,28 @@ export const set = <ElementType extends AnyType>(
|
|
|
2474
2484
|
};
|
|
2475
2485
|
|
|
2476
2486
|
/** SetType extends Type with an additional `element` property for reflection. */
|
|
2477
|
-
export interface SetType<ElementType extends AnyType>
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
> {
|
|
2487
|
+
export interface SetType<ElementType extends AnyType> extends Type<
|
|
2488
|
+
"Set",
|
|
2489
|
+
ReadonlySet<InferType<ElementType>>,
|
|
2490
|
+
ReadonlySet<InferInput<ElementType>>,
|
|
2491
|
+
SetError<InferError<ElementType>>,
|
|
2492
|
+
ReadonlySet<InferParent<ElementType>>,
|
|
2493
|
+
SetError<InferParentError<ElementType>>
|
|
2494
|
+
> {
|
|
2486
2495
|
readonly element: ElementType;
|
|
2487
2496
|
}
|
|
2488
2497
|
|
|
2489
|
-
export interface SetError<
|
|
2490
|
-
extends
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2498
|
+
export interface SetError<
|
|
2499
|
+
Error extends TypeError = TypeError,
|
|
2500
|
+
> extends TypeErrorWithReason<
|
|
2501
|
+
"Set",
|
|
2502
|
+
| { readonly kind: "NotSet" }
|
|
2503
|
+
| {
|
|
2504
|
+
readonly kind: "Element";
|
|
2505
|
+
readonly index: number;
|
|
2506
|
+
readonly error: Error;
|
|
2507
|
+
}
|
|
2508
|
+
> {}
|
|
2499
2509
|
|
|
2500
2510
|
export const formatSetError = <Error extends TypeError>(
|
|
2501
2511
|
formatTypeError: TypeErrorFormatter<Error>,
|
|
@@ -2670,13 +2680,13 @@ export interface RecordType<
|
|
|
2670
2680
|
KeyParentError extends TypeError,
|
|
2671
2681
|
Value extends AnyType = AnyType,
|
|
2672
2682
|
> extends Type<
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2683
|
+
"Record",
|
|
2684
|
+
Readonly<Record<KeyT, InferType<Value>>>,
|
|
2685
|
+
Readonly<Record<KeyInput, InferInput<Value>>>,
|
|
2686
|
+
RecordError<KeyError, InferError<Value>>,
|
|
2687
|
+
Readonly<Record<KeyParent, InferParent<Value>>>,
|
|
2688
|
+
RecordError<KeyParentError, InferParentError<Value>>
|
|
2689
|
+
> {
|
|
2680
2690
|
readonly key: Type<
|
|
2681
2691
|
KeyName,
|
|
2682
2692
|
KeyT,
|
|
@@ -2692,19 +2702,19 @@ export interface RecordError<
|
|
|
2692
2702
|
KeyError extends TypeError = TypeError,
|
|
2693
2703
|
ValueError extends TypeError = TypeError,
|
|
2694
2704
|
> extends TypeErrorWithReason<
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2705
|
+
"Record",
|
|
2706
|
+
| { readonly kind: "NotRecord" }
|
|
2707
|
+
| {
|
|
2708
|
+
readonly kind: "Key";
|
|
2709
|
+
readonly key: unknown;
|
|
2710
|
+
readonly error: KeyError;
|
|
2711
|
+
}
|
|
2712
|
+
| {
|
|
2713
|
+
readonly kind: "Value";
|
|
2714
|
+
readonly key: unknown;
|
|
2715
|
+
readonly error: ValueError;
|
|
2716
|
+
}
|
|
2717
|
+
> {}
|
|
2708
2718
|
|
|
2709
2719
|
export const formatRecordError = <Error extends TypeError>(
|
|
2710
2720
|
formatTypeError: TypeErrorFormatter<Error>,
|
|
@@ -3016,15 +3026,14 @@ export function object(
|
|
|
3016
3026
|
* ObjectType extends {@link Type} with an additional `props` property for
|
|
3017
3027
|
* reflection.
|
|
3018
3028
|
*/
|
|
3019
|
-
export interface ObjectType<Props extends Record<string, AnyType>>
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
> {
|
|
3029
|
+
export interface ObjectType<Props extends Record<string, AnyType>> extends Type<
|
|
3030
|
+
"Object",
|
|
3031
|
+
Readonly<ObjectT<Props>>,
|
|
3032
|
+
Readonly<ObjectInput<Props>>,
|
|
3033
|
+
ObjectError<{ [K in keyof Props]: InferError<Props[K]> }>,
|
|
3034
|
+
Readonly<ObjectParent<Props>>,
|
|
3035
|
+
ObjectError<{ [K in keyof Props]: InferParentError<Props[K]> }>
|
|
3036
|
+
> {
|
|
3028
3037
|
readonly props: Props;
|
|
3029
3038
|
}
|
|
3030
3039
|
|
|
@@ -3070,14 +3079,14 @@ type OptionalKeys<Props extends Record<string, AnyType>> = {
|
|
|
3070
3079
|
export interface ObjectError<
|
|
3071
3080
|
PropsErrors extends Record<string, TypeError> = Record<string, TypeError>,
|
|
3072
3081
|
> extends TypeErrorWithReason<
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3082
|
+
"Object",
|
|
3083
|
+
| { readonly kind: "NotObject" }
|
|
3084
|
+
| {
|
|
3085
|
+
readonly kind: "Props";
|
|
3086
|
+
readonly errors: Partial<PropsErrors>;
|
|
3087
|
+
}
|
|
3088
|
+
| { readonly kind: "ExtraKeys"; readonly extraKeys: ReadonlyArray<string> }
|
|
3089
|
+
> {}
|
|
3081
3090
|
|
|
3082
3091
|
/**
|
|
3083
3092
|
* Merge Error and ParentError into one ObjectError so tooltips and error
|
|
@@ -3123,23 +3132,22 @@ export interface ObjectWithRecordType<
|
|
|
3123
3132
|
KeyParentError extends TypeError,
|
|
3124
3133
|
Value extends AnyType,
|
|
3125
3134
|
> extends Type<
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
Readonly<
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
> {
|
|
3135
|
+
"ObjectWithRecord",
|
|
3136
|
+
Readonly<ObjectT<Props>> & Readonly<Record<KeyT, InferType<Value>>>,
|
|
3137
|
+
Readonly<ObjectInput<Props>> & Readonly<Record<KeyInput, InferInput<Value>>>,
|
|
3138
|
+
ObjectWithRecordError<
|
|
3139
|
+
{ [K in keyof Props]: InferError<Props[K]> },
|
|
3140
|
+
KeyError,
|
|
3141
|
+
InferError<Value>
|
|
3142
|
+
>,
|
|
3143
|
+
Readonly<ObjectParent<Props>> &
|
|
3144
|
+
Readonly<Record<KeyParent, InferParent<Value>>>,
|
|
3145
|
+
ObjectWithRecordError<
|
|
3146
|
+
{ [K in keyof Props]: InferParentError<Props[K]> },
|
|
3147
|
+
KeyParentError,
|
|
3148
|
+
InferParentError<Value>
|
|
3149
|
+
>
|
|
3150
|
+
> {
|
|
3143
3151
|
readonly props: Props;
|
|
3144
3152
|
readonly record: RecordType<
|
|
3145
3153
|
KeyName,
|
|
@@ -3157,20 +3165,20 @@ export interface ObjectWithRecordError<
|
|
|
3157
3165
|
KeyError extends TypeError = TypeError,
|
|
3158
3166
|
ValueError extends TypeError = TypeError,
|
|
3159
3167
|
> extends TypeErrorWithReason<
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3168
|
+
"ObjectWithRecord",
|
|
3169
|
+
| { readonly kind: "NotObject" }
|
|
3170
|
+
| { readonly kind: "Props"; readonly errors: Partial<PropsErrors> }
|
|
3171
|
+
| {
|
|
3172
|
+
readonly kind: "IndexKey";
|
|
3173
|
+
readonly key: unknown;
|
|
3174
|
+
readonly error: KeyError;
|
|
3175
|
+
}
|
|
3176
|
+
| {
|
|
3177
|
+
readonly kind: "IndexValue";
|
|
3178
|
+
readonly key: string;
|
|
3179
|
+
readonly error: ValueError;
|
|
3180
|
+
}
|
|
3181
|
+
> {}
|
|
3174
3182
|
|
|
3175
3183
|
export const formatObjectWithRecordError = <Error extends TypeError>(
|
|
3176
3184
|
formatTypeError: TypeErrorFormatter<Error>,
|
|
@@ -3276,20 +3284,22 @@ export function union(...args: ReadonlyArray<any>): any {
|
|
|
3276
3284
|
* UnionType extends {@link Type} with an additional `members` property for
|
|
3277
3285
|
* reflection.
|
|
3278
3286
|
*/
|
|
3279
|
-
export interface UnionType<
|
|
3280
|
-
extends
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3287
|
+
export interface UnionType<
|
|
3288
|
+
Members extends [AnyType, ...ReadonlyArray<AnyType>],
|
|
3289
|
+
> extends Type<
|
|
3290
|
+
"Union",
|
|
3291
|
+
InferType<Members[number]>,
|
|
3292
|
+
InferInput<Members[number]>,
|
|
3293
|
+
UnionError<InferErrors<Members[number]>>,
|
|
3294
|
+
InferInput<Members[number]>,
|
|
3295
|
+
never
|
|
3296
|
+
> {
|
|
3288
3297
|
readonly members: Members;
|
|
3289
3298
|
}
|
|
3290
3299
|
|
|
3291
|
-
export interface UnionError<
|
|
3292
|
-
extends TypeError
|
|
3300
|
+
export interface UnionError<
|
|
3301
|
+
E extends TypeError = TypeError,
|
|
3302
|
+
> extends TypeError<"Union"> {
|
|
3293
3303
|
readonly errors: Array<E>;
|
|
3294
3304
|
}
|
|
3295
3305
|
|
|
@@ -3379,15 +3389,14 @@ export const recursive = <ParentType extends AnyType>(
|
|
|
3379
3389
|
} as RecursiveType<ParentType>;
|
|
3380
3390
|
};
|
|
3381
3391
|
|
|
3382
|
-
export interface RecursiveType<ParentType extends AnyType>
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
> {
|
|
3392
|
+
export interface RecursiveType<ParentType extends AnyType> extends Type<
|
|
3393
|
+
"Recursive",
|
|
3394
|
+
InferType<ParentType>,
|
|
3395
|
+
InferInput<ParentType>,
|
|
3396
|
+
InferError<ParentType>,
|
|
3397
|
+
InferParent<ParentType>,
|
|
3398
|
+
InferParentError<ParentType>
|
|
3399
|
+
> {
|
|
3391
3400
|
getParentType(): ParentType;
|
|
3392
3401
|
}
|
|
3393
3402
|
|
|
@@ -3551,26 +3560,27 @@ export const tuple = <Elements extends [AnyType, ...ReadonlyArray<AnyType>]>(
|
|
|
3551
3560
|
export interface TupleType<
|
|
3552
3561
|
Elements extends readonly [AnyType, ...ReadonlyArray<AnyType>],
|
|
3553
3562
|
> extends Type<
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3563
|
+
"Tuple",
|
|
3564
|
+
readonly [...{ [K in keyof Elements]: InferType<Elements[K]> }],
|
|
3565
|
+
readonly [...{ [K in keyof Elements]: InferInput<Elements[K]> }],
|
|
3566
|
+
TupleError<{ [K in keyof Elements]: InferError<Elements[K]> }[number]>,
|
|
3567
|
+
readonly [...{ [K in keyof Elements]: InferParent<Elements[K]> }],
|
|
3568
|
+
TupleError<{ [K in keyof Elements]: InferParentError<Elements[K]> }[number]>
|
|
3569
|
+
> {
|
|
3561
3570
|
readonly elements: Elements;
|
|
3562
3571
|
}
|
|
3563
3572
|
|
|
3564
|
-
export interface TupleError<
|
|
3565
|
-
extends
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3573
|
+
export interface TupleError<
|
|
3574
|
+
ElementError extends TypeError = TypeError,
|
|
3575
|
+
> extends TypeErrorWithReason<
|
|
3576
|
+
"Tuple",
|
|
3577
|
+
| { readonly kind: "InvalidLength"; readonly expected: number }
|
|
3578
|
+
| {
|
|
3579
|
+
readonly kind: "Element";
|
|
3580
|
+
readonly index: number;
|
|
3581
|
+
readonly error: ElementError;
|
|
3582
|
+
}
|
|
3583
|
+
> {}
|
|
3574
3584
|
|
|
3575
3585
|
export const formatTupleError = <Error extends TypeError>(
|
|
3576
3586
|
formatTypeError: TypeErrorFormatter<Error>,
|
|
@@ -3874,15 +3884,14 @@ export const optional = <T extends AnyType>(type: T): OptionalType<T> => ({
|
|
|
3874
3884
|
parent: type,
|
|
3875
3885
|
});
|
|
3876
3886
|
|
|
3877
|
-
export interface OptionalType<T extends AnyType>
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
> {
|
|
3887
|
+
export interface OptionalType<T extends AnyType> extends Type<
|
|
3888
|
+
"Optional",
|
|
3889
|
+
InferType<T>,
|
|
3890
|
+
InferInput<T>,
|
|
3891
|
+
InferError<T>,
|
|
3892
|
+
InferParent<T>,
|
|
3893
|
+
InferParentError<T>
|
|
3894
|
+
> {
|
|
3886
3895
|
readonly parent: T;
|
|
3887
3896
|
}
|
|
3888
3897
|
|
|
@@ -4015,8 +4024,7 @@ export const validMutationSize = <T extends AnyType>(
|
|
|
4015
4024
|
: err<ValidMutationSizeError>({ type: "ValidMutationSize", value }),
|
|
4016
4025
|
);
|
|
4017
4026
|
|
|
4018
|
-
export interface ValidMutationSizeError
|
|
4019
|
-
extends TypeError<"ValidMutationSize"> {}
|
|
4027
|
+
export interface ValidMutationSizeError extends TypeError<"ValidMutationSize"> {}
|
|
4020
4028
|
|
|
4021
4029
|
export const formatValidMutationSizeError =
|
|
4022
4030
|
createTypeErrorFormatter<ValidMutationSizeError>(
|
package/src/index.ts
CHANGED