Skip to content

Commit 5c46e4c

Browse files
author
Mat Jones
committed
Merge branch 'main' of github.com:AndcultureCode/AndcultureCode.JavaScript.Core into main
2 parents dd089f0 + 3b28f32 commit 5c46e4c

30 files changed

Lines changed: 936 additions & 445 deletions

docs/README.md

Lines changed: 435 additions & 307 deletions
Large diffs are not rendered by default.

docs/classes/do.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
[andculturecode-javascript-core](../README.md)[Do](do.md)
2+
3+
# Class: Do <**TResourceType, TReturnVal**>
4+
5+
Utility class to be able to use strong typing in a catch handler.
6+
the Do.catch method takes a callback where the parameters are:
7+
- result?: Result<TResourceType> -- if it's an error from the server, will not be null
8+
- error?: any -- if it's a Javascript error, will not be null
9+
10+
## Type parameters
11+
12+
**TResourceType**
13+
14+
**TReturnVal**
15+
16+
## Hierarchy
17+
18+
* **Do**
19+
20+
## Index
21+
22+
### Constructors
23+
24+
* [constructor](do.md#private-constructor)
25+
26+
### Properties
27+
28+
* [promise](do.md#private-readonly-promise)
29+
30+
### Methods
31+
32+
* [catch](do.md#catch)
33+
* [finally](do.md#finally)
34+
* [getAwaiter](do.md#getawaiter)
35+
* [try](do.md#static-try)
36+
37+
## Constructors
38+
39+
### `Private` constructor
40+
41+
\+ **new Do**(`workload`: [AsyncWorkload](../README.md#asyncworkload)‹TReturnVal›): *[Do](do.md)*
42+
43+
*Defined in [src/utilities/do-try.ts:20](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L20)*
44+
45+
**Parameters:**
46+
47+
Name | Type |
48+
------ | ------ |
49+
`workload` | [AsyncWorkload](../README.md#asyncworkload)‹TReturnVal› |
50+
51+
**Returns:** *[Do](do.md)*
52+
53+
## Properties
54+
55+
### `Private` `Readonly` promise
56+
57+
**promise**: *Promise‹TReturnVal›*
58+
59+
*Defined in [src/utilities/do-try.ts:20](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L20)*
60+
61+
## Methods
62+
63+
### catch
64+
65+
**catch**(`errorHandler`: [CatchHandler](../README.md#catchhandler)‹TResourceType›): *[Do](do.md)‹TResourceType, TReturnVal›*
66+
67+
*Defined in [src/utilities/do-try.ts:35](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L35)*
68+
69+
Handle errors from the workload.
70+
If errors are in the shape of a {ResultRecord},
71+
you will get a typed {ResultRecord} as the first parameter.
72+
Otherwise, if it's an unknown error or Javascript error,
73+
you'll get an {any} as the second parameter.
74+
75+
**Parameters:**
76+
77+
Name | Type | Description |
78+
------ | ------ | ------ |
79+
`errorHandler` | [CatchHandler](../README.md#catchhandler)‹TResourceType› | handle errors, either as a {ResultRecord} or {any} |
80+
81+
**Returns:** *[Do](do.md)‹TResourceType, TReturnVal›*
82+
83+
this
84+
85+
___
86+
87+
### finally
88+
89+
**finally**(`finallyHandler`: [FinallyHandler](../README.md#finallyhandler)): *[Do](do.md)‹TResourceType, TReturnVal›*
90+
91+
*Defined in [src/utilities/do-try.ts:56](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L56)*
92+
93+
Run some handler when the function completes, whether the
94+
catch() was hit or not.
95+
96+
**Parameters:**
97+
98+
Name | Type |
99+
------ | ------ |
100+
`finallyHandler` | [FinallyHandler](../README.md#finallyhandler) |
101+
102+
**Returns:** *[Do](do.md)‹TResourceType, TReturnVal›*
103+
104+
this
105+
106+
___
107+
108+
### getAwaiter
109+
110+
**getAwaiter**(): *Promise‹TReturnVal›*
111+
112+
*Defined in [src/utilities/do-try.ts:70](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L70)*
113+
114+
Awaits the internal promise being tracked by the Do instance,
115+
and returns the result. This way, you can await a Do.try
116+
chain, if you need to await for the result inside of another scope,
117+
such as tests.
118+
119+
**Returns:** *Promise‹TReturnVal›*
120+
121+
the result of the promise.
122+
123+
___
124+
125+
### `Static` try
126+
127+
**try**<**TResourceType**, **TReturnVal**>(`workload`: [AsyncWorkload](../README.md#asyncworkload)‹TReturnVal›): *[Do](do.md)‹TResourceType, TReturnVal›*
128+
129+
*Defined in [src/utilities/do-try.ts:81](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L81)*
130+
131+
Static factory method for Do class.
132+
Start a workload (sync or async) that you can then
133+
call .catch(catchHandler).finally(finallyHandler) on.
134+
135+
**Type parameters:**
136+
137+
**TResourceType**
138+
139+
**TReturnVal**
140+
141+
**Parameters:**
142+
143+
Name | Type | Description |
144+
------ | ------ | ------ |
145+
`workload` | [AsyncWorkload](../README.md#asyncworkload)‹TReturnVal› | a sync or async method to wrap |
146+
147+
**Returns:** *[Do](do.md)‹TResourceType, TReturnVal›*
148+
149+
a new instance of Do

docs/classes/dosync.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
[andculturecode-javascript-core](../README.md)[DoSync](dosync.md)
2+
3+
# Class: DoSync <**TResourceType, TReturnVal**>
4+
5+
## Type parameters
6+
7+
**TResourceType**
8+
9+
**TReturnVal**
10+
11+
## Hierarchy
12+
13+
* **DoSync**
14+
15+
## Index
16+
17+
### Constructors
18+
19+
* [constructor](dosync.md#private-constructor)
20+
21+
### Properties
22+
23+
* [catchHandler](dosync.md#private-optional-catchhandler)
24+
* [finallyHandler](dosync.md#private-optional-finallyhandler)
25+
* [workload](dosync.md#private-readonly-workload)
26+
27+
### Methods
28+
29+
* [catch](dosync.md#catch)
30+
* [execute](dosync.md#execute)
31+
* [finally](dosync.md#finally)
32+
* [try](dosync.md#static-try)
33+
34+
## Constructors
35+
36+
### `Private` constructor
37+
38+
\+ **new DoSync**(`workload`: [SyncWorkload](../README.md#syncworkload)‹TReturnVal›): *[DoSync](dosync.md)*
39+
40+
*Defined in [src/utilities/do-try.ts:97](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L97)*
41+
42+
**Parameters:**
43+
44+
Name | Type |
45+
------ | ------ |
46+
`workload` | [SyncWorkload](../README.md#syncworkload)‹TReturnVal› |
47+
48+
**Returns:** *[DoSync](dosync.md)*
49+
50+
## Properties
51+
52+
### `Private` `Optional` catchHandler
53+
54+
**catchHandler**? : *undefined | function*
55+
56+
*Defined in [src/utilities/do-try.ts:96](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L96)*
57+
58+
___
59+
60+
### `Private` `Optional` finallyHandler
61+
62+
**finallyHandler**? : *[FinallyHandler](../README.md#finallyhandler)*
63+
64+
*Defined in [src/utilities/do-try.ts:97](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L97)*
65+
66+
___
67+
68+
### `Private` `Readonly` workload
69+
70+
**workload**: *[SyncWorkload](../README.md#syncworkload)‹TReturnVal›*
71+
72+
*Defined in [src/utilities/do-try.ts:95](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L95)*
73+
74+
## Methods
75+
76+
### catch
77+
78+
**catch**(`errorHandler`: [CatchHandler](../README.md#catchhandler)‹TResourceType›): *[DoSync](dosync.md)‹TResourceType, TReturnVal›*
79+
80+
*Defined in [src/utilities/do-try.ts:111](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L111)*
81+
82+
Add a catch handler to the DoSync call chain.
83+
If errors are in the shape of a {ResultRecord},
84+
you will get a typed {ResultRecord} as the first parameter.
85+
Otherwise, if it's an unknown error or Javascript error,
86+
you'll get an {any} as the second parameter.
87+
88+
**Parameters:**
89+
90+
Name | Type | Description |
91+
------ | ------ | ------ |
92+
`errorHandler` | [CatchHandler](../README.md#catchhandler)‹TResourceType› | handle errors, either as a {ResultRecord} or {any} |
93+
94+
**Returns:** *[DoSync](dosync.md)‹TResourceType, TReturnVal›*
95+
96+
___
97+
98+
### execute
99+
100+
**execute**(): *TReturnVal | undefined*
101+
102+
*Defined in [src/utilities/do-try.ts:131](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L131)*
103+
104+
Execute the entire DoSync call chain. For the synchronous version, i.e. DoSync,
105+
you must manually call .execute() for the call chain to be executed.
106+
107+
**Returns:** *TReturnVal | undefined*
108+
109+
TReturnVal the value returned from the workload, or undefined if an error occurred.
110+
111+
___
112+
113+
### finally
114+
115+
**finally**(`finallyHandler`: [FinallyHandler](../README.md#finallyhandler)): *[DoSync](dosync.md)‹TResourceType, TReturnVal›*
116+
117+
*Defined in [src/utilities/do-try.ts:147](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L147)*
118+
119+
Run some handler when the function completes, whether the
120+
catch() was hit or not.
121+
122+
**Parameters:**
123+
124+
Name | Type |
125+
------ | ------ |
126+
`finallyHandler` | [FinallyHandler](../README.md#finallyhandler) |
127+
128+
**Returns:** *[DoSync](dosync.md)‹TResourceType, TReturnVal›*
129+
130+
this
131+
132+
___
133+
134+
### `Static` try
135+
136+
**try**<**TResourceType**, **TReturnVal**>(`workload`: [SyncWorkload](../README.md#syncworkload)‹TReturnVal›): *[DoSync](dosync.md)‹TResourceType, TReturnVal›*
137+
138+
*Defined in [src/utilities/do-try.ts:159](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/utilities/do-try.ts#L159)*
139+
140+
Static factory method for DoSync. Creates a new DoSync
141+
with the given workload.
142+
143+
**Type parameters:**
144+
145+
**TResourceType**
146+
147+
**TReturnVal**
148+
149+
**Parameters:**
150+
151+
Name | Type | Description |
152+
------ | ------ | ------ |
153+
`workload` | [SyncWorkload](../README.md#syncworkload)‹TReturnVal› | |
154+
155+
**Returns:** *[DoSync](dosync.md)‹TResourceType, TReturnVal›*

docs/classes/resulterrorrecord.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ The name provided to `Record(values, name)` can be accessed with
157157

158158
\+ **new ResultErrorRecord**(`params?`: [ResultError](../interfaces/resulterror.md)): *[ResultErrorRecord](resulterrorrecord.md)*
159159

160-
*Defined in [src/view-models/result-error-record.ts:11](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/bc87312/src/view-models/result-error-record.ts#L11)*
160+
*Defined in [src/view-models/result-error-record.ts:11](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/view-models/result-error-record.ts#L11)*
161161

162162
**Parameters:**
163163

@@ -293,7 +293,7 @@ ___
293293

294294
**fullError**(): *string*
295295

296-
*Defined in [src/view-models/result-error-record.ts:40](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/bc87312/src/view-models/result-error-record.ts#L40)*
296+
*Defined in [src/view-models/result-error-record.ts:40](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/view-models/result-error-record.ts#L40)*
297297

298298
Display error key and message
299299

@@ -759,7 +759,7 @@ ___
759759

760760
**with**(`values`: Partial‹[ResultError](../interfaces/resulterror.md)›): *[ResultErrorRecord](resulterrorrecord.md)*
761761

762-
*Defined in [src/view-models/result-error-record.ts:51](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/bc87312/src/view-models/result-error-record.ts#L51)*
762+
*Defined in [src/view-models/result-error-record.ts:51](https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core/blob/ba68f27/src/view-models/result-error-record.ts#L51)*
763763

764764
Merges new values into the record and returns a new instance.
765765

0 commit comments

Comments
 (0)