@reactionary/core 0.1.13 → 0.2.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/cache/memory-cache.js +1 -1
- package/decorators/reactionary.decorator.js +50 -16
- package/package.json +1 -1
- package/providers/base.provider.js +0 -15
- package/providers/cart.provider.js +0 -39
- package/providers/inventory.provider.js +1 -8
- package/providers/order.provider.js +0 -1
- package/providers/price.provider.js +0 -7
- package/providers/product.provider.js +0 -7
- package/schemas/errors/generic.error.js +8 -0
- package/schemas/errors/index.js +4 -0
- package/schemas/errors/invalid-input.error.js +8 -0
- package/schemas/errors/invalid-output.error.js +8 -0
- package/schemas/errors/not-found.error.js +8 -0
- package/schemas/index.js +2 -0
- package/schemas/models/base.model.js +1 -14
- package/schemas/mutations/cart.mutation.js +1 -1
- package/schemas/mutations/checkout.mutation.js +4 -4
- package/schemas/result.js +51 -0
- package/src/cache/memory-cache.d.ts +2 -1
- package/src/decorators/reactionary.decorator.d.ts +3 -2
- package/src/providers/base.provider.d.ts +0 -3
- package/src/providers/cart.provider.d.ts +11 -10
- package/src/providers/category.provider.d.ts +6 -6
- package/src/providers/checkout.provider.d.ts +11 -9
- package/src/providers/identity.provider.d.ts +5 -4
- package/src/providers/inventory.provider.d.ts +3 -1
- package/src/providers/order.provider.d.ts +3 -1
- package/src/providers/price.provider.d.ts +3 -3
- package/src/providers/product-search.provider.d.ts +3 -3
- package/src/providers/product.provider.d.ts +5 -3
- package/src/providers/profile.provider.d.ts +3 -2
- package/src/providers/store.provider.d.ts +2 -1
- package/src/schemas/errors/generic.error.d.ts +7 -0
- package/src/schemas/errors/index.d.ts +4 -0
- package/src/schemas/errors/invalid-input.error.d.ts +7 -0
- package/src/schemas/errors/invalid-output.error.d.ts +7 -0
- package/src/schemas/errors/not-found.error.d.ts +7 -0
- package/src/schemas/index.d.ts +2 -0
- package/src/schemas/models/analytics.model.d.ts +1 -9
- package/src/schemas/models/base.model.d.ts +1 -29
- package/src/schemas/models/cart.model.d.ts +0 -7
- package/src/schemas/models/category.model.d.ts +0 -21
- package/src/schemas/models/checkout.model.d.ts +0 -35
- package/src/schemas/models/identity.model.d.ts +0 -42
- package/src/schemas/models/inventory.model.d.ts +0 -7
- package/src/schemas/models/order.model.d.ts +0 -28
- package/src/schemas/models/payment.model.d.ts +0 -14
- package/src/schemas/models/price.model.d.ts +0 -7
- package/src/schemas/models/product-search.model.d.ts +0 -21
- package/src/schemas/models/product.model.d.ts +0 -7
- package/src/schemas/models/profile.model.d.ts +0 -35
- package/src/schemas/models/shipping-method.model.d.ts +0 -14
- package/src/schemas/models/store.model.d.ts +0 -7
- package/src/schemas/mutations/cart.mutation.d.ts +2 -16
- package/src/schemas/mutations/checkout.mutation.d.ts +1 -8
- package/src/schemas/queries/product-search.query.d.ts +0 -7
- package/src/schemas/result.d.ts +55 -0
|
@@ -14,13 +14,6 @@ export declare const PaymentProtocolDataSchema: z.ZodObject<{
|
|
|
14
14
|
value: z.ZodString;
|
|
15
15
|
}, z.core.$loose>;
|
|
16
16
|
export declare const PaymentMethodSchema: z.ZodObject<{
|
|
17
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
18
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
19
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
-
key: z.ZodDefault<z.ZodString>;
|
|
21
|
-
}, z.core.$loose>>;
|
|
22
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
23
|
-
}, z.core.$loose>>;
|
|
24
17
|
identifier: z.ZodObject<{
|
|
25
18
|
method: z.ZodString;
|
|
26
19
|
name: z.ZodString;
|
|
@@ -36,13 +29,6 @@ export declare const PaymentMethodSchema: z.ZodObject<{
|
|
|
36
29
|
isPunchOut: z.ZodBoolean;
|
|
37
30
|
}, z.core.$loose>;
|
|
38
31
|
export declare const PaymentInstructionSchema: z.ZodObject<{
|
|
39
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
40
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
41
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
42
|
-
key: z.ZodDefault<z.ZodString>;
|
|
43
|
-
}, z.core.$loose>>;
|
|
44
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
45
|
-
}, z.core.$loose>>;
|
|
46
32
|
identifier: z.ZodObject<{
|
|
47
33
|
key: z.ZodString;
|
|
48
34
|
}, z.core.$loose>;
|
|
@@ -376,13 +376,6 @@ export declare const TieredPriceSchema: z.ZodObject<{
|
|
|
376
376
|
}, z.core.$loose>;
|
|
377
377
|
}, z.core.$loose>;
|
|
378
378
|
export declare const PriceSchema: z.ZodObject<{
|
|
379
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
380
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
381
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
382
|
-
key: z.ZodDefault<z.ZodString>;
|
|
383
|
-
}, z.core.$loose>>;
|
|
384
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
385
|
-
}, z.core.$loose>>;
|
|
386
379
|
identifier: z.ZodObject<{
|
|
387
380
|
variant: z.ZodObject<{
|
|
388
381
|
sku: z.ZodString;
|
|
@@ -27,13 +27,6 @@ export declare const ProductSearchResultItemVariantSchema: z.ZodObject<{
|
|
|
27
27
|
}, z.core.$loose>>;
|
|
28
28
|
}, z.core.$loose>;
|
|
29
29
|
export declare const ProductSearchResultItemSchema: z.ZodObject<{
|
|
30
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
31
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
32
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
33
|
-
key: z.ZodDefault<z.ZodString>;
|
|
34
|
-
}, z.core.$loose>>;
|
|
35
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
36
|
-
}, z.core.$loose>>;
|
|
37
30
|
identifier: z.ZodObject<{
|
|
38
31
|
key: z.ZodString;
|
|
39
32
|
}, z.core.$loose>;
|
|
@@ -95,25 +88,11 @@ export declare const ProductSearchResultFacetSchema: z.ZodObject<{
|
|
|
95
88
|
}, z.core.$loose>>;
|
|
96
89
|
}, z.core.$loose>;
|
|
97
90
|
export declare const ProductSearchResultSchema: z.ZodObject<{
|
|
98
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
99
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
100
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
101
|
-
key: z.ZodDefault<z.ZodString>;
|
|
102
|
-
}, z.core.$loose>>;
|
|
103
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
104
|
-
}, z.core.$loose>>;
|
|
105
91
|
pageNumber: z.ZodNumber;
|
|
106
92
|
pageSize: z.ZodNumber;
|
|
107
93
|
totalCount: z.ZodNumber;
|
|
108
94
|
totalPages: z.ZodNumber;
|
|
109
95
|
items: z.ZodArray<z.ZodObject<{
|
|
110
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
111
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
112
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
113
|
-
key: z.ZodDefault<z.ZodString>;
|
|
114
|
-
}, z.core.$loose>>;
|
|
115
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
116
|
-
}, z.core.$loose>>;
|
|
117
96
|
identifier: z.ZodObject<{
|
|
118
97
|
key: z.ZodString;
|
|
119
98
|
}, z.core.$loose>;
|
|
@@ -92,13 +92,6 @@ export declare const ProductAttributeSchema: z.ZodObject<{
|
|
|
92
92
|
}, z.core.$loose>>;
|
|
93
93
|
}, z.core.$loose>;
|
|
94
94
|
export declare const ProductSchema: z.ZodObject<{
|
|
95
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
96
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
97
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
98
|
-
key: z.ZodDefault<z.ZodString>;
|
|
99
|
-
}, z.core.$loose>>;
|
|
100
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
101
|
-
}, z.core.$loose>>;
|
|
102
95
|
identifier: z.ZodObject<{
|
|
103
96
|
key: z.ZodString;
|
|
104
97
|
}, z.core.$loose>;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { InferType } from '../../zod-utils.js';
|
|
3
3
|
export declare const AddressSchema: z.ZodObject<{
|
|
4
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
5
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
6
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
-
key: z.ZodDefault<z.ZodString>;
|
|
8
|
-
}, z.core.$loose>>;
|
|
9
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
-
}, z.core.$loose>>;
|
|
11
4
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
12
5
|
nickName: z.ZodString;
|
|
13
6
|
}, z.core.$loose>>;
|
|
@@ -21,13 +14,6 @@ export declare const AddressSchema: z.ZodObject<{
|
|
|
21
14
|
countryCode: z.ZodString;
|
|
22
15
|
}, z.core.$loose>;
|
|
23
16
|
export declare const ProfileSchema: z.ZodObject<{
|
|
24
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
25
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
26
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
27
|
-
key: z.ZodDefault<z.ZodString>;
|
|
28
|
-
}, z.core.$loose>>;
|
|
29
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
30
|
-
}, z.core.$loose>>;
|
|
31
17
|
identifier: z.ZodObject<{
|
|
32
18
|
userId: z.ZodString;
|
|
33
19
|
}, z.core.$loose>;
|
|
@@ -38,13 +24,6 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
38
24
|
createdAt: z.ZodString;
|
|
39
25
|
updatedAt: z.ZodString;
|
|
40
26
|
shippingAddress: z.ZodOptional<z.ZodObject<{
|
|
41
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
42
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
43
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
44
|
-
key: z.ZodDefault<z.ZodString>;
|
|
45
|
-
}, z.core.$loose>>;
|
|
46
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
47
|
-
}, z.core.$loose>>;
|
|
48
27
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
49
28
|
nickName: z.ZodString;
|
|
50
29
|
}, z.core.$loose>>;
|
|
@@ -58,13 +37,6 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
58
37
|
countryCode: z.ZodString;
|
|
59
38
|
}, z.core.$loose>>;
|
|
60
39
|
billingAddress: z.ZodOptional<z.ZodObject<{
|
|
61
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
62
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
63
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
64
|
-
key: z.ZodDefault<z.ZodString>;
|
|
65
|
-
}, z.core.$loose>>;
|
|
66
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
67
|
-
}, z.core.$loose>>;
|
|
68
40
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
69
41
|
nickName: z.ZodString;
|
|
70
42
|
}, z.core.$loose>>;
|
|
@@ -78,13 +50,6 @@ export declare const ProfileSchema: z.ZodObject<{
|
|
|
78
50
|
countryCode: z.ZodString;
|
|
79
51
|
}, z.core.$loose>>;
|
|
80
52
|
alternateShippingAddresses: z.ZodArray<z.ZodObject<{
|
|
81
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
82
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
83
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
84
|
-
key: z.ZodDefault<z.ZodString>;
|
|
85
|
-
}, z.core.$loose>>;
|
|
86
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
87
|
-
}, z.core.$loose>>;
|
|
88
53
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
89
54
|
nickName: z.ZodString;
|
|
90
55
|
}, z.core.$loose>>;
|
|
@@ -7,13 +7,6 @@ export declare const PickupPointSchema: z.ZodObject<{
|
|
|
7
7
|
name: z.ZodString;
|
|
8
8
|
description: z.ZodString;
|
|
9
9
|
address: z.ZodObject<{
|
|
10
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
11
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
12
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
-
key: z.ZodDefault<z.ZodString>;
|
|
14
|
-
}, z.core.$loose>>;
|
|
15
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
16
|
-
}, z.core.$loose>>;
|
|
17
10
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
18
11
|
nickName: z.ZodString;
|
|
19
12
|
}, z.core.$loose>>;
|
|
@@ -233,13 +226,6 @@ export declare const ShippingMethodSchema: z.ZodObject<{
|
|
|
233
226
|
carrier: z.ZodOptional<z.ZodString>;
|
|
234
227
|
}, z.core.$loose>;
|
|
235
228
|
export declare const ShippingInstructionSchema: z.ZodObject<{
|
|
236
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
237
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
238
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
239
|
-
key: z.ZodDefault<z.ZodString>;
|
|
240
|
-
}, z.core.$loose>>;
|
|
241
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
242
|
-
}, z.core.$loose>>;
|
|
243
229
|
shippingMethod: z.ZodObject<{
|
|
244
230
|
key: z.ZodString;
|
|
245
231
|
}, z.core.$loose>;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { InferType } from '../../zod-utils.js';
|
|
3
3
|
export declare const StoreSchema: z.ZodObject<{
|
|
4
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
5
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
6
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
-
key: z.ZodDefault<z.ZodString>;
|
|
8
|
-
}, z.core.$loose>>;
|
|
9
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
-
}, z.core.$loose>>;
|
|
11
4
|
identifier: z.ZodObject<{
|
|
12
5
|
key: z.ZodString;
|
|
13
6
|
}, z.core.$loose>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { InferType } from '../../zod-utils.js';
|
|
3
3
|
export declare const CartMutationItemAddSchema: z.ZodObject<{
|
|
4
|
-
cart: z.ZodObject<{
|
|
4
|
+
cart: z.ZodOptional<z.ZodObject<{
|
|
5
5
|
key: z.ZodString;
|
|
6
|
-
}, z.core.$loose
|
|
6
|
+
}, z.core.$loose>>;
|
|
7
7
|
variant: z.ZodObject<{
|
|
8
8
|
sku: z.ZodString;
|
|
9
9
|
}, z.core.$loose>;
|
|
@@ -39,13 +39,6 @@ export declare const CartMutationSetShippingInfoSchema: z.ZodObject<{
|
|
|
39
39
|
key: z.ZodString;
|
|
40
40
|
}, z.core.$loose>>;
|
|
41
41
|
shippingAddress: z.ZodOptional<z.ZodObject<{
|
|
42
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
43
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
44
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
45
|
-
key: z.ZodDefault<z.ZodString>;
|
|
46
|
-
}, z.core.$loose>>;
|
|
47
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
-
}, z.core.$loose>>;
|
|
49
42
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
50
43
|
nickName: z.ZodString;
|
|
51
44
|
}, z.core.$loose>>;
|
|
@@ -64,13 +57,6 @@ export declare const CartMutationSetBillingAddressSchema: z.ZodObject<{
|
|
|
64
57
|
key: z.ZodString;
|
|
65
58
|
}, z.core.$loose>;
|
|
66
59
|
billingAddress: z.ZodObject<{
|
|
67
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
68
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
69
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
70
|
-
key: z.ZodDefault<z.ZodString>;
|
|
71
|
-
}, z.core.$loose>>;
|
|
72
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
73
|
-
}, z.core.$loose>>;
|
|
74
60
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
75
61
|
nickName: z.ZodString;
|
|
76
62
|
}, z.core.$loose>>;
|
|
@@ -2,13 +2,6 @@ import { z } from "zod";
|
|
|
2
2
|
import type { InferType } from '../../zod-utils.js';
|
|
3
3
|
export declare const CheckoutMutationInitiateCheckoutSchema: z.ZodObject<{
|
|
4
4
|
cart: z.ZodObject<{
|
|
5
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
6
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
7
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
-
key: z.ZodDefault<z.ZodString>;
|
|
9
|
-
}, z.core.$loose>>;
|
|
10
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
-
}, z.core.$loose>>;
|
|
12
5
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
13
6
|
key: z.ZodString;
|
|
14
7
|
}, z.core.$loose>>;
|
|
@@ -2139,11 +2132,11 @@ export declare const CheckoutMutationRemovePaymentInstructionSchema: z.ZodObject
|
|
|
2139
2132
|
}, z.core.$loose>;
|
|
2140
2133
|
export declare const CheckoutMutationSetShippingInstructionSchema: z.ZodObject<{
|
|
2141
2134
|
shippingInstruction: z.ZodObject<{
|
|
2142
|
-
instructions: z.ZodString;
|
|
2143
2135
|
shippingMethod: z.ZodObject<{
|
|
2144
2136
|
key: z.ZodString;
|
|
2145
2137
|
}, z.core.$loose>;
|
|
2146
2138
|
pickupPoint: z.ZodString;
|
|
2139
|
+
instructions: z.ZodString;
|
|
2147
2140
|
consentForUnattendedDelivery: z.ZodBoolean;
|
|
2148
2141
|
}, z.core.$loose>;
|
|
2149
2142
|
checkout: z.ZodObject<{
|
|
@@ -24,13 +24,6 @@ export declare const ProductSearchQueryByTermSchema: z.ZodObject<{
|
|
|
24
24
|
}, z.core.$loose>;
|
|
25
25
|
export declare const ProductSearchQueryCreateNavigationFilterSchema: z.ZodObject<{
|
|
26
26
|
categoryPath: z.ZodArray<z.ZodObject<{
|
|
27
|
-
meta: z.ZodDefault<z.ZodObject<{
|
|
28
|
-
cache: z.ZodDefault<z.ZodObject<{
|
|
29
|
-
hit: z.ZodDefault<z.ZodBoolean>;
|
|
30
|
-
key: z.ZodDefault<z.ZodString>;
|
|
31
|
-
}, z.core.$loose>>;
|
|
32
|
-
placeholder: z.ZodDefault<z.ZodBoolean>;
|
|
33
|
-
}, z.core.$loose>>;
|
|
34
27
|
identifier: z.ZodDefault<z.ZodObject<{
|
|
35
28
|
key: z.ZodString;
|
|
36
29
|
}, z.core.$loose>>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { GenericError } from "./errors/generic.error.js";
|
|
2
|
+
import type { InvalidInputError } from "./errors/invalid-input.error.js";
|
|
3
|
+
import type { InvalidOutputError } from "./errors/invalid-output.error.js";
|
|
4
|
+
export type Ok<T> = {
|
|
5
|
+
success: true;
|
|
6
|
+
value: T;
|
|
7
|
+
meta: {
|
|
8
|
+
trace: string;
|
|
9
|
+
cache: {
|
|
10
|
+
hit: boolean;
|
|
11
|
+
key: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type Fail<E> = {
|
|
16
|
+
success: false;
|
|
17
|
+
error: E | GenericError | InvalidInputError | InvalidOutputError;
|
|
18
|
+
meta: {
|
|
19
|
+
trace: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type Result<T, E = Error> = Ok<T> | Fail<E>;
|
|
23
|
+
/**
|
|
24
|
+
* Utility function for asserting and unwrapping the value of a success.
|
|
25
|
+
* It is an assert, so treat it as such (similar to any unwrap, assert or similar function).
|
|
26
|
+
* You are guaranteeing that this will ALWAYS succeed, and can expect a runtime error if
|
|
27
|
+
* that assertion ever fails.
|
|
28
|
+
*
|
|
29
|
+
* This is primarily useful for cases where you KNOW that it shouldn't fail, or where failure
|
|
30
|
+
* has no known mechanism of recovery besides simply crashing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function assertSuccess<T, E = Error>(result: Result<T, E>): asserts result is Ok<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Utility function for asserting an error. This is primarily useful for testing scenarios
|
|
35
|
+
* that trigger errors as part of their validation.
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertError<T, E = Error>(result: Result<T, E>): asserts result is Fail<E>;
|
|
38
|
+
/**
|
|
39
|
+
* Utility function for unwrapping a value from a result. Internally this
|
|
40
|
+
* WILL assert success, so the caller needs to guarantee that this will
|
|
41
|
+
* always be a valid operation, or expect a thrown exception.
|
|
42
|
+
*/
|
|
43
|
+
export declare function unwrapValue<T, E = Error>(result: Result<T, E>): T;
|
|
44
|
+
/**
|
|
45
|
+
* Utility function for unwrapping an error. Primarily useful for testing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function unwrapError<T, E>(result: Result<T, E>): Fail<E>['error'];
|
|
48
|
+
/**
|
|
49
|
+
* Helper function for wrapping a success as an Ok<T> type
|
|
50
|
+
*/
|
|
51
|
+
export declare function success<T>(value: T): Ok<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Helper function for wrapping an error as a Fail<E> type
|
|
54
|
+
*/
|
|
55
|
+
export declare function error<E>(error: E): Fail<E>;
|