@byloth/core 2.0.0-rc.9 → 2.0.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/core.js +3371 -608
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +13 -10
- package/src/core/types.ts +41 -0
- package/src/helpers.ts +11 -2
- package/src/index.ts +12 -9
- package/src/models/aggregators/aggregated-async-iterator.ts +765 -21
- package/src/models/aggregators/aggregated-iterator.ts +698 -22
- package/src/models/aggregators/reduced-iterator.ts +699 -10
- package/src/models/aggregators/types.ts +153 -10
- package/src/models/callbacks/callable-object.ts +42 -6
- package/src/models/callbacks/index.ts +2 -2
- package/src/models/callbacks/publisher.ts +139 -4
- package/src/models/callbacks/switchable-callback.ts +138 -4
- package/src/models/callbacks/types.ts +16 -0
- package/src/models/exceptions/core.ts +112 -3
- package/src/models/exceptions/index.ts +340 -13
- package/src/models/index.ts +4 -8
- package/src/models/iterators/smart-async-iterator.ts +687 -22
- package/src/models/iterators/smart-iterator.ts +631 -21
- package/src/models/iterators/types.ts +268 -9
- package/src/models/json/json-storage.ts +388 -110
- package/src/models/json/types.ts +10 -1
- package/src/models/promises/deferred-promise.ts +75 -5
- package/src/models/promises/index.ts +1 -3
- package/src/models/promises/smart-promise.ts +232 -4
- package/src/models/promises/timed-promise.ts +38 -1
- package/src/models/promises/types.ts +84 -2
- package/src/models/timers/clock.ts +91 -19
- package/src/models/timers/countdown.ts +152 -22
- package/src/models/timers/game-loop.ts +243 -0
- package/src/models/timers/index.ts +2 -1
- package/src/models/types.ts +6 -5
- package/src/utils/async.ts +43 -0
- package/src/utils/curve.ts +75 -0
- package/src/utils/date.ts +204 -10
- package/src/utils/dom.ts +16 -2
- package/src/utils/index.ts +3 -2
- package/src/utils/iterator.ts +200 -17
- package/src/utils/math.ts +55 -3
- package/src/utils/random.ts +109 -2
- package/src/utils/string.ts +11 -0
- package/src/models/game-loop.ts +0 -83
- package/src/models/promises/long-running-task.ts +0 -294
- package/src/models/promises/thenable.ts +0 -97
|
@@ -1,5 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class representing an exception, subclass of the native `Error` class.
|
|
3
|
+
* It's the base class for any other further exception.
|
|
4
|
+
*
|
|
5
|
+
* It allows to chain exceptions together, tracking the initial cause of an error and
|
|
6
|
+
* storing its stack trace while providing a clear and friendly message to the user.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* try { loadGameSaves(); }
|
|
10
|
+
* catch (error)
|
|
11
|
+
* {
|
|
12
|
+
* throw new Exception("The game saves may be corrupted. Try to restart the game.", error);
|
|
13
|
+
* // Uncaught Exception: The game saves may be corrupted. Try to restart the game.
|
|
14
|
+
* // at /src/game/index.ts:37:15
|
|
15
|
+
* // at /src/main.ts:23:17
|
|
16
|
+
* //
|
|
17
|
+
* // Caused by SyntaxError: Unexpected end of JSON input
|
|
18
|
+
* // at /src/models/saves.ts:47:17
|
|
19
|
+
* // at /src/game/index.ts:12:9
|
|
20
|
+
* // at /src/main.ts:23:17
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
1
24
|
export default class Exception extends Error
|
|
2
25
|
{
|
|
26
|
+
/**
|
|
27
|
+
* A static method to convert a generic caught error, ensuring it's an instance of the {@link Exception} class.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* try { [...] }
|
|
31
|
+
* catch (error)
|
|
32
|
+
* {
|
|
33
|
+
* const exc = Exception.FromUnknown(error);
|
|
34
|
+
*
|
|
35
|
+
* [...]
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param error The caught error to convert.
|
|
40
|
+
*
|
|
41
|
+
* @returns An instance of the {@link Exception} class.
|
|
42
|
+
*/
|
|
3
43
|
public static FromUnknown(error: unknown): Exception
|
|
4
44
|
{
|
|
5
45
|
if (error instanceof Exception)
|
|
@@ -19,6 +59,17 @@ export default class Exception extends Error
|
|
|
19
59
|
return new Exception(`${error}`);
|
|
20
60
|
}
|
|
21
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Initializes a new instance of the {@link Exception} class.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* throw new Exception("An error occurred while processing the request.");
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param message The message that describes the error.
|
|
70
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
71
|
+
* @param name The name of the exception. Default is `"Exception"`.
|
|
72
|
+
*/
|
|
22
73
|
public constructor(message: string, cause?: unknown, name = "Exception")
|
|
23
74
|
{
|
|
24
75
|
super(message);
|
|
@@ -42,8 +93,38 @@ export default class Exception extends Error
|
|
|
42
93
|
public readonly [Symbol.toStringTag]: string = "Exception";
|
|
43
94
|
}
|
|
44
95
|
|
|
96
|
+
/**
|
|
97
|
+
* An utility class representing that kind of situation where the program should never reach.
|
|
98
|
+
* Also commonly used to satisfy the type-system, but not part of a real feasible scenario.
|
|
99
|
+
*
|
|
100
|
+
* It provides a clear and friendly message by default.
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* function checkCase(value: "A" | "B" | "C"): 1 | 2 | 3
|
|
104
|
+
* {
|
|
105
|
+
* switch (value)
|
|
106
|
+
* {
|
|
107
|
+
* case "A": return 1;
|
|
108
|
+
* case "B": return 2;
|
|
109
|
+
* case "C": return 3;
|
|
110
|
+
* default: throw new FatalErrorException();
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
45
115
|
export class FatalErrorException extends Exception
|
|
46
116
|
{
|
|
117
|
+
/**
|
|
118
|
+
* Initializes a new instance of the {@link FatalErrorException} class.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* throw new FatalErrorException("This error should never happen. Please, contact the support team.");
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param message The message that describes the error.
|
|
125
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
126
|
+
* @param name The name of the exception. Default is `"FatalErrorException"`.
|
|
127
|
+
*/
|
|
47
128
|
public constructor(message?: string, cause?: unknown, name = "FatalErrorException")
|
|
48
129
|
{
|
|
49
130
|
if (message === undefined)
|
|
@@ -55,19 +136,47 @@ export class FatalErrorException extends Exception
|
|
|
55
136
|
super(message, cause, name);
|
|
56
137
|
}
|
|
57
138
|
|
|
58
|
-
public readonly [Symbol.toStringTag]: string = "FatalErrorException";
|
|
139
|
+
public override readonly [Symbol.toStringTag]: string = "FatalErrorException";
|
|
59
140
|
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* An utility class representing a situation where a feature isn't implemented yet.
|
|
144
|
+
* It's commonly used as a placeholder for future implementations.
|
|
145
|
+
*
|
|
146
|
+
* It provides a clear and friendly message by default.
|
|
147
|
+
*
|
|
148
|
+
* ```ts
|
|
149
|
+
* class Database
|
|
150
|
+
* {
|
|
151
|
+
* public async connect(): Promise<void>
|
|
152
|
+
* {
|
|
153
|
+
* throw new NotImplementedException();
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
60
158
|
export class NotImplementedException extends FatalErrorException
|
|
61
159
|
{
|
|
160
|
+
/**
|
|
161
|
+
* Initializes a new instance of the {@link NotImplementedException} class.
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* throw new NotImplementedException("This method hasn't been implemented yet. Check back later.");
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @param message The message that describes the error.
|
|
168
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
169
|
+
* @param name The name of the exception. Default is `"NotImplementedException"`.
|
|
170
|
+
*/
|
|
62
171
|
public constructor(message?: string, cause?: unknown, name = "NotImplementedException")
|
|
63
172
|
{
|
|
64
173
|
if (message === undefined)
|
|
65
174
|
{
|
|
66
|
-
message = "This feature
|
|
175
|
+
message = "This feature isn't implemented yet. Please, try again later.";
|
|
67
176
|
}
|
|
68
177
|
|
|
69
178
|
super(message, cause, name);
|
|
70
179
|
}
|
|
71
180
|
|
|
72
|
-
public readonly [Symbol.toStringTag]: string = "NotImplementedException";
|
|
181
|
+
public override readonly [Symbol.toStringTag]: string = "NotImplementedException";
|
|
73
182
|
}
|
|
@@ -1,125 +1,452 @@
|
|
|
1
1
|
import Exception from "./core.js";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A class representing a generic exception that can be thrown when a file
|
|
5
|
+
* operation fails, such as reading, writing, copying, moving, deleting, etc...
|
|
6
|
+
*
|
|
7
|
+
* It can also be used to catch all file-related exceptions at once.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* try { [...] }
|
|
11
|
+
* catch (error)
|
|
12
|
+
* {
|
|
13
|
+
* if (error instanceof FileException)
|
|
14
|
+
* {
|
|
15
|
+
* // A file-related exception occurred. Handle it...
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
3
20
|
export class FileException extends Exception
|
|
4
21
|
{
|
|
22
|
+
/**
|
|
23
|
+
* Initializes a new instance of the {@link FileException} class.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* throw new FileException("An error occurred while trying to read the file.");
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param message The message that describes the error.
|
|
30
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
31
|
+
* @param name The name of the exception. Default is `"FileException"`.
|
|
32
|
+
*/
|
|
5
33
|
public constructor(message: string, cause?: unknown, name = "FileException")
|
|
6
34
|
{
|
|
7
35
|
super(message, cause, name);
|
|
8
36
|
}
|
|
9
37
|
|
|
10
|
-
public readonly [Symbol.toStringTag]: string = "FileException";
|
|
38
|
+
public override readonly [Symbol.toStringTag]: string = "FileException";
|
|
11
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A class representing an exception that can be thrown when a file already exists.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { existsSync } from "node:fs";
|
|
46
|
+
*
|
|
47
|
+
* if (existsSync("file.txt"))
|
|
48
|
+
* {
|
|
49
|
+
* throw new FileExistsException("The file named 'file.txt' already exists.");
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
12
53
|
export class FileExistsException extends FileException
|
|
13
54
|
{
|
|
55
|
+
/**
|
|
56
|
+
* Initializes a new instance of the {@link FileExistsException} class.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* throw new FileExistsException("The file named 'data.json' already exists on the server.");
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param message The message that describes the error.
|
|
63
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
64
|
+
* @param name The name of the exception. Default is `"FileExistsException"`.
|
|
65
|
+
*/
|
|
14
66
|
public constructor(message: string, cause?: unknown, name = "FileExistsException")
|
|
15
67
|
{
|
|
16
68
|
super(message, cause, name);
|
|
17
69
|
}
|
|
18
70
|
|
|
19
|
-
public readonly [Symbol.toStringTag]: string = "FileExistsException";
|
|
71
|
+
public override readonly [Symbol.toStringTag]: string = "FileExistsException";
|
|
20
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A class representing an exception that can be thrown when a file isn't found.
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { existsSync } from "node:fs";
|
|
79
|
+
*
|
|
80
|
+
* if (!existsSync("file.txt"))
|
|
81
|
+
* {
|
|
82
|
+
* throw new FileNotFoundException("The file named 'file.txt' wasn't found.");
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
21
86
|
export class FileNotFoundException extends FileException
|
|
22
87
|
{
|
|
88
|
+
/**
|
|
89
|
+
* Initializes a new instance of the {@link FileNotFoundException} class.
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* throw new FileNotFoundException("The file named 'data.json' wasn't found on the server.");
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param message The message that describes the error.
|
|
96
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
97
|
+
* @param name The name of the exception. Default is `"FileNotFoundException"`.
|
|
98
|
+
*/
|
|
23
99
|
public constructor(message: string, cause?: unknown, name = "FileNotFoundException")
|
|
24
100
|
{
|
|
25
101
|
super(message, cause, name);
|
|
26
102
|
}
|
|
27
103
|
|
|
28
|
-
public readonly [Symbol.toStringTag]: string = "FileNotFoundException";
|
|
104
|
+
public override readonly [Symbol.toStringTag]: string = "FileNotFoundException";
|
|
29
105
|
}
|
|
30
106
|
|
|
107
|
+
/**
|
|
108
|
+
* A class representing an exception that can be thrown when a key is invalid or not found.
|
|
109
|
+
* It's commonly used when working with dictionaries, maps, objects, sets, etc...
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* const map = new Map<string, number>();
|
|
113
|
+
* if (!map.has("hash"))
|
|
114
|
+
* {
|
|
115
|
+
* throw new KeyException("The key 'hash' wasn't found in the collection.");
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
31
119
|
export class KeyException extends Exception
|
|
32
120
|
{
|
|
121
|
+
/**
|
|
122
|
+
* Initializes a new instance of the {@link KeyException} class.
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* throw new KeyException("The 'id' key wasn't found in the dictionary.");
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param message The message that describes the error.
|
|
129
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
130
|
+
* @param name The name of the exception. Default is `"KeyException"`.
|
|
131
|
+
*/
|
|
33
132
|
public constructor(message: string, cause?: unknown, name = "KeyException")
|
|
34
133
|
{
|
|
35
134
|
super(message, cause, name);
|
|
36
135
|
}
|
|
37
136
|
|
|
38
|
-
public readonly [Symbol.toStringTag]: string = "KeyException";
|
|
137
|
+
public override readonly [Symbol.toStringTag]: string = "KeyException";
|
|
39
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A class representing an exception that can be thrown when a network operation fails.
|
|
142
|
+
* It's commonly used when it's unable to connect to a server or when a request times out.
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* import axios, { isAxiosError } from "axios";
|
|
146
|
+
*
|
|
147
|
+
* try { await axios.get("https://api.example.com/data"); }
|
|
148
|
+
* catch (error)
|
|
149
|
+
* {
|
|
150
|
+
* if (isAxiosError(error) && !error.response)
|
|
151
|
+
* {
|
|
152
|
+
* throw new NetworkException(
|
|
153
|
+
* "Unable to establish a connection to the server. " +
|
|
154
|
+
* "Please, check your internet connection and try again."
|
|
155
|
+
* );
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
40
160
|
export class NetworkException extends Exception
|
|
41
161
|
{
|
|
162
|
+
/**
|
|
163
|
+
* Initializes a new instance of the {@link NetworkException} class.
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* throw new NetworkException("Couldn't connect to the server. Please, try again later.");
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @param message The message that describes the error.
|
|
170
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
171
|
+
* @param name The name of the exception. Default is `"NetworkException"`.
|
|
172
|
+
*/
|
|
42
173
|
public constructor(message: string, cause?: unknown, name = "NetworkException")
|
|
43
174
|
{
|
|
44
175
|
super(message, cause, name);
|
|
45
176
|
}
|
|
46
177
|
|
|
47
|
-
public readonly [Symbol.toStringTag]: string = "NetworkException";
|
|
178
|
+
public override readonly [Symbol.toStringTag]: string = "NetworkException";
|
|
48
179
|
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A class representing an exception that can be thrown when a permission is denied.
|
|
183
|
+
* It's commonly used when a user tries to access a restricted resource or perform a forbidden action.
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* const $user = useUserStore();
|
|
187
|
+
* if (!$user.isAdmin)
|
|
188
|
+
* {
|
|
189
|
+
* throw new PermissionException("You don't have permission to perform this action.");
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
49
193
|
export class PermissionException extends Exception
|
|
50
194
|
{
|
|
195
|
+
/**
|
|
196
|
+
* Initializes a new instance of the {@link PermissionException} class.
|
|
197
|
+
*
|
|
198
|
+
* ```ts
|
|
199
|
+
* throw new PermissionException("You don't have permission to access this resource.");
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @param message The message that describes the error.
|
|
203
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
204
|
+
* @param name The name of the exception. Default is `"PermissionException"`.
|
|
205
|
+
*/
|
|
51
206
|
public constructor(message: string, cause?: unknown, name = "PermissionException")
|
|
52
207
|
{
|
|
53
208
|
super(message, cause, name);
|
|
54
209
|
}
|
|
55
210
|
|
|
56
|
-
public readonly [Symbol.toStringTag]: string = "PermissionException";
|
|
211
|
+
public override readonly [Symbol.toStringTag]: string = "PermissionException";
|
|
57
212
|
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A class representing an exception that can be thrown when a reference is invalid or not found.
|
|
216
|
+
* It's commonly used when a variable is `null`, `undefined` or when an object doesn't exist.
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* const $el = document.getElementById("app");
|
|
220
|
+
* if ($el === null)
|
|
221
|
+
* {
|
|
222
|
+
* throw new ReferenceException("The element with the ID 'app' wasn't found in the document.");
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
58
226
|
export class ReferenceException extends Exception
|
|
59
227
|
{
|
|
228
|
+
/**
|
|
229
|
+
* Initializes a new instance of the {@link ReferenceException} class.
|
|
230
|
+
*
|
|
231
|
+
* ```ts
|
|
232
|
+
* throw new ReferenceException("The 'canvas' element wasn't found in the document.");
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @param message The message that describes the error.
|
|
236
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
237
|
+
* @param name The name of the exception. Default is `"ReferenceException"`.
|
|
238
|
+
*/
|
|
60
239
|
public constructor(message: string, cause?: unknown, name = "ReferenceException")
|
|
61
240
|
{
|
|
62
241
|
super(message, cause, name);
|
|
63
242
|
}
|
|
64
243
|
|
|
65
|
-
public readonly [Symbol.toStringTag]: string = "ReferenceException";
|
|
244
|
+
public override readonly [Symbol.toStringTag]: string = "ReferenceException";
|
|
66
245
|
}
|
|
67
246
|
|
|
247
|
+
/**
|
|
248
|
+
* A class representing an exception that can be thrown when a runtime error occurs.
|
|
249
|
+
* It's commonly used when an unexpected condition is encountered during the execution of a program.
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* let status: "enabled" | "disabled" = "enabled";
|
|
253
|
+
*
|
|
254
|
+
* function enable(): void
|
|
255
|
+
* {
|
|
256
|
+
* if (status === "enabled") { throw new RuntimeException("The feature is already enabled."); }
|
|
257
|
+
* status = "enabled";
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
68
261
|
export class RuntimeException extends Exception
|
|
69
262
|
{
|
|
263
|
+
/**
|
|
264
|
+
* Initializes a new instance of the {@link RuntimeException} class.
|
|
265
|
+
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* throw new RuntimeException("The received input seems to be malformed or corrupted.");
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @param message The message that describes the error.
|
|
271
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
272
|
+
* @param name The name of the exception. Default is `"RuntimeException"`.
|
|
273
|
+
*/
|
|
70
274
|
public constructor(message: string, cause?: unknown, name = "RuntimeException")
|
|
71
275
|
{
|
|
72
276
|
super(message, cause, name);
|
|
73
277
|
}
|
|
74
278
|
|
|
75
|
-
public readonly [Symbol.toStringTag]: string = "RuntimeException";
|
|
279
|
+
public override readonly [Symbol.toStringTag]: string = "RuntimeException";
|
|
76
280
|
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* A class representing an exception that can be thrown when an environment
|
|
284
|
+
* isn't properly configured or when a required variable isn't set.
|
|
285
|
+
* It can also be used when the environment on which the program is running is unsupported.
|
|
286
|
+
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* if (!navigator.geolocation)
|
|
289
|
+
* {
|
|
290
|
+
* throw new EnvironmentException("The Geolocation API isn't supported in this environment.");
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
77
294
|
export class EnvironmentException extends RuntimeException
|
|
78
295
|
{
|
|
296
|
+
/**
|
|
297
|
+
* Initializes a new instance of the {@link EnvironmentException} class.
|
|
298
|
+
*
|
|
299
|
+
* ```ts
|
|
300
|
+
* throw new EnvironmentException("The required environment variable 'API_KEY' isn't set.");
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @param message The message that describes the error.
|
|
304
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
305
|
+
* @param name The name of the exception. Default is `"EnvironmentException"`.
|
|
306
|
+
*/
|
|
79
307
|
public constructor(message: string, cause?: unknown, name = "EnvironmentException")
|
|
80
308
|
{
|
|
81
309
|
super(message, cause, name);
|
|
82
310
|
}
|
|
83
311
|
|
|
84
|
-
public readonly [Symbol.toStringTag]: string = "EnvironmentException";
|
|
312
|
+
public override readonly [Symbol.toStringTag]: string = "EnvironmentException";
|
|
85
313
|
}
|
|
86
314
|
|
|
315
|
+
/**
|
|
316
|
+
* A class representing an exception that can be thrown when a timeout occurs.
|
|
317
|
+
* It's commonly used when a task takes too long to complete or when a request times out.
|
|
318
|
+
*
|
|
319
|
+
* ```ts
|
|
320
|
+
* const timeoutId = setTimeout(() => { throw new TimeoutException("The request timed out."); }, 5_000);
|
|
321
|
+
* const response = await fetch("https://api.example.com/data");
|
|
322
|
+
*
|
|
323
|
+
* clearTimeout(timeoutId);
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
87
326
|
export class TimeoutException extends Exception
|
|
88
327
|
{
|
|
328
|
+
/**
|
|
329
|
+
* Initializes a new instance of the {@link TimeoutException} class.
|
|
330
|
+
*
|
|
331
|
+
* ```ts
|
|
332
|
+
* throw new TimeoutException("The task took too long to complete.");
|
|
333
|
+
* ```
|
|
334
|
+
*
|
|
335
|
+
* @param message The message that describes the error.
|
|
336
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
337
|
+
* @param name The name of the exception. Default is `"TimeoutException"`.
|
|
338
|
+
*/
|
|
89
339
|
public constructor(message: string, cause?: unknown, name = "TimeoutException")
|
|
90
340
|
{
|
|
91
341
|
super(message, cause, name);
|
|
92
342
|
}
|
|
93
343
|
|
|
94
|
-
public readonly [Symbol.toStringTag]: string = "TimeoutException";
|
|
344
|
+
public override readonly [Symbol.toStringTag]: string = "TimeoutException";
|
|
95
345
|
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* A class representing an exception that can be thrown when a type is invalid or not supported.
|
|
349
|
+
* It's commonly used when a function receives an unexpected type of argument.
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* function greet(name: string): void
|
|
353
|
+
* {
|
|
354
|
+
* if (typeof name !== "string")
|
|
355
|
+
* {
|
|
356
|
+
* throw new TypeException("The 'name' argument must be a valid string.");
|
|
357
|
+
* }
|
|
358
|
+
* }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
96
361
|
export class TypeException extends Exception
|
|
97
362
|
{
|
|
363
|
+
/**
|
|
364
|
+
* Initializes a new instance of the {@link TypeException} class.
|
|
365
|
+
*
|
|
366
|
+
* ```ts
|
|
367
|
+
* throw new TypeException("The 'username' argument must be a valid string.");
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @param message The message that describes the error.
|
|
371
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
372
|
+
* @param name The name of the exception. Default is `"TypeException"`.
|
|
373
|
+
*/
|
|
98
374
|
public constructor(message: string, cause?: unknown, name = "TypeException")
|
|
99
375
|
{
|
|
100
376
|
super(message, cause, name);
|
|
101
377
|
}
|
|
102
378
|
|
|
103
|
-
public readonly [Symbol.toStringTag]: string = "TypeException";
|
|
379
|
+
public override readonly [Symbol.toStringTag]: string = "TypeException";
|
|
104
380
|
}
|
|
105
381
|
|
|
382
|
+
/**
|
|
383
|
+
* A class representing an exception that can be thrown when a value is invalid.
|
|
384
|
+
* It's commonly used when a function receives an unexpected value as an argument.
|
|
385
|
+
*
|
|
386
|
+
* ```ts
|
|
387
|
+
* function setVolume(value: number): void
|
|
388
|
+
* {
|
|
389
|
+
* if (value < 0)
|
|
390
|
+
* {
|
|
391
|
+
* throw new ValueException("The 'value' argument must be greater than or equal to 0.");
|
|
392
|
+
* }
|
|
393
|
+
* }
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
106
396
|
export class ValueException extends Exception
|
|
107
397
|
{
|
|
398
|
+
/**
|
|
399
|
+
* Initializes a new instance of the {@link ValueException} class.
|
|
400
|
+
*
|
|
401
|
+
* ```ts
|
|
402
|
+
* throw new ValueException("The 'grade' argument cannot be negative.");
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* @param message The message that describes the error.
|
|
406
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
407
|
+
* @param name The name of the exception. Default is `"ValueException"`.
|
|
408
|
+
*/
|
|
108
409
|
public constructor(message: string, cause?: unknown, name = "ValueException")
|
|
109
410
|
{
|
|
110
411
|
super(message, cause, name);
|
|
111
412
|
}
|
|
112
413
|
|
|
113
|
-
public readonly [Symbol.toStringTag]: string = "ValueException";
|
|
414
|
+
public override readonly [Symbol.toStringTag]: string = "ValueException";
|
|
114
415
|
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* A class representing an exception that can be thrown when a value is out of range.
|
|
419
|
+
* It's commonly used when a function receives an unexpected value as an argument.
|
|
420
|
+
*
|
|
421
|
+
* ```ts
|
|
422
|
+
* function setVolume(value: number): void
|
|
423
|
+
* {
|
|
424
|
+
* if ((value < 0) || (value > 100))
|
|
425
|
+
* {
|
|
426
|
+
* throw new RangeException("The 'value' argument must be between 0 and 100.");
|
|
427
|
+
* }
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
115
431
|
export class RangeException extends ValueException
|
|
116
432
|
{
|
|
433
|
+
/**
|
|
434
|
+
* Initializes a new instance of the {@link RangeException} class.
|
|
435
|
+
*
|
|
436
|
+
* ```ts
|
|
437
|
+
* throw new RangeException("The 'percentage' argument must be between 0 and 100.");
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* @param message The message that describes the error.
|
|
441
|
+
* @param cause The previous caught error that caused this one, if any.
|
|
442
|
+
* @param name The name of the exception. Default is `"RangeException"`.
|
|
443
|
+
*/
|
|
117
444
|
public constructor(message: string, cause?: unknown, name = "RangeException")
|
|
118
445
|
{
|
|
119
446
|
super(message, cause, name);
|
|
120
447
|
}
|
|
121
448
|
|
|
122
|
-
public readonly [Symbol.toStringTag]: string = "RangeException";
|
|
449
|
+
public override readonly [Symbol.toStringTag]: string = "RangeException";
|
|
123
450
|
}
|
|
124
451
|
|
|
125
452
|
export { Exception };
|
package/src/models/index.ts
CHANGED
|
@@ -5,11 +5,12 @@ export {
|
|
|
5
5
|
|
|
6
6
|
} from "./aggregators/index.js";
|
|
7
7
|
|
|
8
|
-
export { CallableObject, Publisher,
|
|
8
|
+
export { CallableObject, Publisher, SwitchableCallback } from "./callbacks/index.js";
|
|
9
9
|
export {
|
|
10
10
|
Exception,
|
|
11
11
|
FatalErrorException,
|
|
12
12
|
NotImplementedException,
|
|
13
|
+
EnvironmentException,
|
|
13
14
|
FileException,
|
|
14
15
|
FileExistsException,
|
|
15
16
|
FileNotFoundException,
|
|
@@ -25,12 +26,7 @@ export {
|
|
|
25
26
|
|
|
26
27
|
} from "./exceptions/index.js";
|
|
27
28
|
|
|
28
|
-
import GameLoop from "./game-loop.js";
|
|
29
|
-
|
|
30
29
|
export { SmartIterator, SmartAsyncIterator } from "./iterators/index.js";
|
|
31
30
|
export { JSONStorage } from "./json/index.js";
|
|
32
|
-
export { DeferredPromise,
|
|
33
|
-
|
|
34
|
-
export { Clock, Countdown } from "./timers/index.js";
|
|
35
|
-
|
|
36
|
-
export { GameLoop };
|
|
31
|
+
export { DeferredPromise, SmartPromise, TimedPromise } from "./promises/index.js";
|
|
32
|
+
export { Clock, Countdown, GameLoop } from "./timers/index.js";
|