@seedcord/services 0.6.0 → 0.7.0-next.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/README.md +1 -1
- package/dist/SeedcordError-BuWVIe6m.d.mts +302 -0
- package/dist/SeedcordError-wt7_KePP.cjs +376 -0
- package/dist/SeedcordError-wt7_KePP.cjs.map +1 -0
- package/dist/SeedcordError-xd-Ib_-z.mjs +313 -0
- package/dist/SeedcordError-xd-Ib_-z.mjs.map +1 -0
- package/dist/index.cjs +1485 -1103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -656
- package/dist/index.d.mts +2930 -0
- package/dist/index.mjs +1474 -1090
- package/dist/index.mjs.map +1 -1
- package/dist/internal.index.cjs +6 -0
- package/dist/internal.index.d.cts +1 -0
- package/dist/internal.index.d.mts +2 -0
- package/dist/internal.index.mjs +3 -0
- package/package.json +44 -25
- package/dist/index.d.ts +0 -656
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2930 @@
|
|
|
1
|
+
import { o as isSeedcordError, r as SeedcordErrorTypeString, s as SeedcordErrorCode, t as BaseSeedcordError } from "./SeedcordError-BuWVIe6m.mjs";
|
|
2
|
+
import { Logform, Logger as Logger$1 } from "winston";
|
|
3
|
+
import TransportStream from "winston-transport";
|
|
4
|
+
import { EventEmitter } from "node:events";
|
|
5
|
+
import { HealthCheckConfig, ILogger, TypedExclude } from "@seedcord/types";
|
|
6
|
+
import { Writable } from "node:stream";
|
|
7
|
+
|
|
8
|
+
//#region src/CooldownManager.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for CooldownManager.
|
|
11
|
+
*/
|
|
12
|
+
interface CooldownOptions {
|
|
13
|
+
/** Cooldown window in milliseconds (default 1000) */
|
|
14
|
+
cooldown?: number;
|
|
15
|
+
/** Custom error class to throw when a key is still cooling down; receives the remaining ms. */
|
|
16
|
+
err?: new (msg: string, remaining: number) => Error;
|
|
17
|
+
/** Message passed to the error constructor (default "Cooldown active") */
|
|
18
|
+
message?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Lightweight utility for per-key cooldowns.
|
|
22
|
+
*
|
|
23
|
+
* Manages time-based restrictions on operations by key,
|
|
24
|
+
* useful for rate limiting, command cooldowns, and spam prevention.
|
|
25
|
+
*/
|
|
26
|
+
declare class CooldownManager {
|
|
27
|
+
private readonly window;
|
|
28
|
+
private readonly Err;
|
|
29
|
+
private readonly msg;
|
|
30
|
+
private readonly map;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new CooldownManager instance.
|
|
33
|
+
*
|
|
34
|
+
* @param opts - Configuration options for the cooldown behavior
|
|
35
|
+
*/
|
|
36
|
+
constructor(opts?: CooldownOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Records usage timestamp for a key without any cooldown checks.
|
|
39
|
+
*
|
|
40
|
+
* @param key - The unique identifier for the cooldown entry
|
|
41
|
+
*/
|
|
42
|
+
set(key: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Verifies cooldown status for a key and updates timestamp if not active.
|
|
45
|
+
*
|
|
46
|
+
* If the cooldown is still active, throws the configured error.
|
|
47
|
+
* If not active, updates the timestamp and returns successfully.
|
|
48
|
+
*
|
|
49
|
+
* @param key - The unique identifier to check cooldown for
|
|
50
|
+
* @throws An {@link Err} When the cooldown is still active for the given key
|
|
51
|
+
*/
|
|
52
|
+
check(key: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a key is currently cooling down without updating timestamp.
|
|
55
|
+
*
|
|
56
|
+
* @param key - The unique identifier to check
|
|
57
|
+
* @returns True if the key is still cooling down, false otherwise
|
|
58
|
+
*/
|
|
59
|
+
isActive(key: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Removes a key from the cooldown map.
|
|
62
|
+
*
|
|
63
|
+
* @param key - The unique identifier to remove (useful for manual resets)
|
|
64
|
+
*/
|
|
65
|
+
clear(key: string): void;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/Logger/Types.d.ts
|
|
69
|
+
/** Log level defining severity of a message */
|
|
70
|
+
type LoggerLevel = keyof ILogger;
|
|
71
|
+
/** Format mode for log output */
|
|
72
|
+
type LoggerFormatMode = 'pretty' | 'json' | 'minimal';
|
|
73
|
+
/**
|
|
74
|
+
* Base configuration shared by all transport types.
|
|
75
|
+
*/
|
|
76
|
+
interface BaseTransportConfig {
|
|
77
|
+
/** Minimum log level for this transport */
|
|
78
|
+
level?: LoggerLevel;
|
|
79
|
+
/** Output format mode */
|
|
80
|
+
format?: LoggerFormatMode;
|
|
81
|
+
/** Whether to strip ANSI color codes from output */
|
|
82
|
+
stripAnsi?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Console transport configuration.
|
|
86
|
+
*
|
|
87
|
+
* Logs to stdout/stderr for terminal output.
|
|
88
|
+
*/
|
|
89
|
+
interface ConsoleTransportConfig extends BaseTransportConfig {
|
|
90
|
+
/** Transport type */
|
|
91
|
+
type: 'console';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* File transport configuration.
|
|
95
|
+
*
|
|
96
|
+
* Logs to rotating files with automatic directory creation.
|
|
97
|
+
*/
|
|
98
|
+
interface FileTransportConfig extends BaseTransportConfig {
|
|
99
|
+
/** Transport type */
|
|
100
|
+
type: 'file';
|
|
101
|
+
/** File path (supports `{channel}`, `{date}`, `{timestamp}` placeholders) */
|
|
102
|
+
filename?: string;
|
|
103
|
+
/** Maximum file size in bytes before rotation */
|
|
104
|
+
maxSize?: number;
|
|
105
|
+
/** Maximum number of rotated log files to keep */
|
|
106
|
+
maxFiles?: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Stream transport configuration.
|
|
110
|
+
*
|
|
111
|
+
* Logs to any writable stream for custom destinations.
|
|
112
|
+
* Use this for logging to databases, network sockets, or custom handlers.
|
|
113
|
+
*/
|
|
114
|
+
interface StreamTransportConfig extends BaseTransportConfig {
|
|
115
|
+
/** Transport type */
|
|
116
|
+
type: 'stream';
|
|
117
|
+
/** Writable stream to log to */
|
|
118
|
+
stream: Writable;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Configuration for a logger transport.
|
|
122
|
+
*
|
|
123
|
+
* Discriminated union ensuring type-safe transport configuration.
|
|
124
|
+
*/
|
|
125
|
+
type TransportConfig = ConsoleTransportConfig | FileTransportConfig | StreamTransportConfig;
|
|
126
|
+
/**
|
|
127
|
+
* Configuration for a named logger channel.
|
|
128
|
+
*/
|
|
129
|
+
interface ChannelConfig {
|
|
130
|
+
/** Channel identifier */
|
|
131
|
+
name: string;
|
|
132
|
+
/** Default log level for the channel */
|
|
133
|
+
level?: LoggerLevel;
|
|
134
|
+
/** List of transports for this channel */
|
|
135
|
+
transports?: TransportConfig[];
|
|
136
|
+
/** Default format for the channel */
|
|
137
|
+
format?: LoggerFormatMode;
|
|
138
|
+
/** Whether to strip ANSI codes by default */
|
|
139
|
+
stripAnsi?: boolean;
|
|
140
|
+
}
|
|
141
|
+
interface LoggerFilePatternsConfig {
|
|
142
|
+
/** Filename pattern for development logs */
|
|
143
|
+
dev: string;
|
|
144
|
+
/** Filename pattern for staging logs */
|
|
145
|
+
staging: string;
|
|
146
|
+
/** Filename pattern for production logs */
|
|
147
|
+
prod: string;
|
|
148
|
+
}
|
|
149
|
+
interface LoggerFileConfig {
|
|
150
|
+
/** Maximum file size in MB for log rotation */
|
|
151
|
+
maxSizeMB: number;
|
|
152
|
+
/** Maximum number of log files to retain */
|
|
153
|
+
maxFiles: number;
|
|
154
|
+
/** Filename patterns for different environments */
|
|
155
|
+
patterns: LoggerFilePatternsConfig;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Global logger configuration.
|
|
159
|
+
*/
|
|
160
|
+
interface LoggerConfiguration {
|
|
161
|
+
/** Name of the default channel to use when none is specified */
|
|
162
|
+
defaultChannel: string;
|
|
163
|
+
files: LoggerFileConfig;
|
|
164
|
+
/** Channel configurations keyed by channel name */
|
|
165
|
+
channels: Record<string, ChannelConfig>;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Options for creating a Logger instance.
|
|
169
|
+
*/
|
|
170
|
+
interface LoggerOptions {
|
|
171
|
+
/** Channel to log to (defaults to configured default channel) */
|
|
172
|
+
channel?: string;
|
|
173
|
+
/** Format mode for output */
|
|
174
|
+
format?: LoggerFormatMode;
|
|
175
|
+
/** Whether to strip ANSI color codes */
|
|
176
|
+
stripAnsi?: boolean;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Winston logger instance type re-export.
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
type WinstonInstance = Logger$1;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/Logger/LoggerUtilities.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Provides access to common logging utilities.
|
|
187
|
+
*/
|
|
188
|
+
declare class LoggerUtilities {
|
|
189
|
+
private readonly logger;
|
|
190
|
+
constructor(logger: ILogger);
|
|
191
|
+
private arrow;
|
|
192
|
+
/**
|
|
193
|
+
* Logs a single item with an arrow prefix.
|
|
194
|
+
* @param text - The text to log
|
|
195
|
+
*/
|
|
196
|
+
item(text: string, level?: LoggerLevel): void;
|
|
197
|
+
/**
|
|
198
|
+
* Logs a list of items with optional heading.
|
|
199
|
+
*
|
|
200
|
+
* @param items - Array of items to log as a list
|
|
201
|
+
* @param heading - Optional heading to display above the list
|
|
202
|
+
*/
|
|
203
|
+
list(items: string[], heading?: string, level?: LoggerLevel): void;
|
|
204
|
+
/**
|
|
205
|
+
* Logs a summary with title and key-value pairs.
|
|
206
|
+
* Example: "Loaded: 5 handlers, 3 commands"
|
|
207
|
+
*
|
|
208
|
+
* @param title - The title of the summary
|
|
209
|
+
* @param items - Object with counts/values to display
|
|
210
|
+
*/
|
|
211
|
+
summary(title: string, items: Record<string, number | string>, level?: LoggerLevel): void;
|
|
212
|
+
/**
|
|
213
|
+
* Logs a component registration message.
|
|
214
|
+
*
|
|
215
|
+
* @param name - Name of the component being registered
|
|
216
|
+
* @param from - File path the component is from
|
|
217
|
+
* @param type - Optional type label (e.g., 'middleware', 'handler')
|
|
218
|
+
*/
|
|
219
|
+
registration(name: string, from: string, type?: string, level?: LoggerLevel): void;
|
|
220
|
+
/**
|
|
221
|
+
* Logs component initialization start/end.
|
|
222
|
+
*
|
|
223
|
+
* @param component - Name of the component
|
|
224
|
+
* @param action - 'start' or 'end' to indicate initialization phase
|
|
225
|
+
*/
|
|
226
|
+
initialization(component: string, action: 'start' | 'end', level?: LoggerLevel): void;
|
|
227
|
+
/**
|
|
228
|
+
* Logs progress as "[current/total]" with optional item label.
|
|
229
|
+
*
|
|
230
|
+
* @param current - Current progress count
|
|
231
|
+
* @param total - Total count
|
|
232
|
+
* @param item - Optional item label to append
|
|
233
|
+
*/
|
|
234
|
+
progress(current: number, total: number, item?: string, level?: LoggerLevel): void;
|
|
235
|
+
/**
|
|
236
|
+
* Logs content in a decorative box.
|
|
237
|
+
*
|
|
238
|
+
* @param title - Title to display in the box
|
|
239
|
+
* @param content - Lines of content to display in the box
|
|
240
|
+
*/
|
|
241
|
+
box(title: string, content: string[], level?: LoggerLevel): void;
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/Logger/Logger.d.ts
|
|
245
|
+
/**
|
|
246
|
+
* Public logging service with channel-aware transports and per-run file output.
|
|
247
|
+
*
|
|
248
|
+
* - Channel separation (e.g., bot, cli, hmr)
|
|
249
|
+
* - Production-safe JSON logs with ANSI stripping
|
|
250
|
+
* - Unique log files per run via filename templates
|
|
251
|
+
*/
|
|
252
|
+
declare class Logger implements ILogger {
|
|
253
|
+
private logger;
|
|
254
|
+
private readonly label;
|
|
255
|
+
private channel;
|
|
256
|
+
private readonly registry;
|
|
257
|
+
readonly utils: LoggerUtilities;
|
|
258
|
+
private static readonly instances;
|
|
259
|
+
private static instance;
|
|
260
|
+
/**
|
|
261
|
+
* Configures global logger settings.
|
|
262
|
+
*
|
|
263
|
+
* Applies configuration to all channels and clears instance cache.
|
|
264
|
+
*
|
|
265
|
+
* @param config - Partial configuration to merge with defaults
|
|
266
|
+
*/
|
|
267
|
+
static configure(config: Partial<LoggerConfiguration>): void;
|
|
268
|
+
/**
|
|
269
|
+
* Creates a new Logger instance.
|
|
270
|
+
*
|
|
271
|
+
* @param label - Prefix/label for all log entries from this logger
|
|
272
|
+
* @param options - Optional configuration for channel, format, and ANSI handling
|
|
273
|
+
*/
|
|
274
|
+
constructor(label: string, options?: LoggerOptions);
|
|
275
|
+
/**
|
|
276
|
+
* Switches this logger to a different channel.
|
|
277
|
+
*
|
|
278
|
+
* @param channel - Channel name to switch to
|
|
279
|
+
*/
|
|
280
|
+
setChannel(channel: string): void;
|
|
281
|
+
/**
|
|
282
|
+
* Returns a new Logger instance configured for the specified channel. Loggers are cached per (label, channel) pair.
|
|
283
|
+
*
|
|
284
|
+
* @param channel - Channel name to use
|
|
285
|
+
*/
|
|
286
|
+
inChannel(channel: string): Logger;
|
|
287
|
+
/**
|
|
288
|
+
* Logs an error message with optional additional data.
|
|
289
|
+
*
|
|
290
|
+
* @param msg - The error message to log
|
|
291
|
+
* @param args - Additional data to include in the log entry
|
|
292
|
+
*/
|
|
293
|
+
error(msg: string, ...args: unknown[]): void;
|
|
294
|
+
/**
|
|
295
|
+
* Logs a warning message with optional additional data.
|
|
296
|
+
*
|
|
297
|
+
* @param msg - The warning message to log
|
|
298
|
+
* @param args - Additional data to include in the log entry
|
|
299
|
+
*/
|
|
300
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
301
|
+
/**
|
|
302
|
+
* Logs an informational message with optional additional data.
|
|
303
|
+
*
|
|
304
|
+
* @param msg - The informational message to log
|
|
305
|
+
* @param args - Additional data to include in the log entry
|
|
306
|
+
*/
|
|
307
|
+
info(msg: string, ...args: unknown[]): void;
|
|
308
|
+
/**
|
|
309
|
+
* Logs an HTTP-related message with optional additional data.
|
|
310
|
+
*
|
|
311
|
+
* @param msg - The HTTP message to log
|
|
312
|
+
* @param args - Additional data to include in the log entry
|
|
313
|
+
*/
|
|
314
|
+
http(msg: string, ...args: unknown[]): void;
|
|
315
|
+
/**
|
|
316
|
+
* Logs a verbose message with optional additional data.
|
|
317
|
+
*
|
|
318
|
+
* @param msg - The verbose message to log
|
|
319
|
+
* @param args - Additional data to include in the log entry
|
|
320
|
+
*/
|
|
321
|
+
verbose(msg: string, ...args: unknown[]): void;
|
|
322
|
+
/**
|
|
323
|
+
* Logs a debug message with optional additional data.
|
|
324
|
+
*
|
|
325
|
+
* @param msg - The debug message to log
|
|
326
|
+
* @param args - Additional data to include in the log entry
|
|
327
|
+
*/
|
|
328
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
329
|
+
/**
|
|
330
|
+
* Logs a silly/trace level message with optional additional data.
|
|
331
|
+
*
|
|
332
|
+
* @param msg - The silly message to log
|
|
333
|
+
* @param args - Additional data to include in the log entry
|
|
334
|
+
*/
|
|
335
|
+
silly(msg: string, ...args: unknown[]): void;
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/Logger/Transports/SinkTransport.d.ts
|
|
339
|
+
/**
|
|
340
|
+
* A log entry passed to custom sinks.
|
|
341
|
+
*/
|
|
342
|
+
interface LoggerSinkLogEntry {
|
|
343
|
+
/** Channel the log originated from */
|
|
344
|
+
readonly channel: string;
|
|
345
|
+
/** Pre-formatted log message ready for display */
|
|
346
|
+
readonly rendered: string;
|
|
347
|
+
/** Raw Winston log info object */
|
|
348
|
+
readonly info: Logform.TransformableInfo;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Custom sink interface for capturing logger output.
|
|
352
|
+
*
|
|
353
|
+
* Implement this to route logs to custom destinations.
|
|
354
|
+
*/
|
|
355
|
+
interface ILoggerSink {
|
|
356
|
+
/**
|
|
357
|
+
* Called when a log entry is emitted.
|
|
358
|
+
*
|
|
359
|
+
* @param entry - The log entry with channel, rendered message, and raw info
|
|
360
|
+
*/
|
|
361
|
+
onLog(entry: LoggerSinkLogEntry): void;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Handle for managing a sink's lifecycle.
|
|
365
|
+
*/
|
|
366
|
+
interface ILoggerSinkHandle {
|
|
367
|
+
/**
|
|
368
|
+
* Removes the sink and restores console output if muted.
|
|
369
|
+
*/
|
|
370
|
+
dispose(): void;
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/Logger/LoggerChannelRegistry.d.ts
|
|
374
|
+
/**
|
|
375
|
+
* Manages Winston logger instances per channel with caching.
|
|
376
|
+
*
|
|
377
|
+
* Stores channel configuration and creates transports for each channel
|
|
378
|
+
* with environment-aware defaults.
|
|
379
|
+
*/
|
|
380
|
+
declare class LoggerChannelRegistry {
|
|
381
|
+
private static _instance;
|
|
382
|
+
private nextSinkId;
|
|
383
|
+
private readonly sinks;
|
|
384
|
+
private readonly DEFAULT_LEVEL;
|
|
385
|
+
private config;
|
|
386
|
+
private readonly FORMAT;
|
|
387
|
+
private readonly cache;
|
|
388
|
+
private readonly transportFactory;
|
|
389
|
+
private constructor();
|
|
390
|
+
/**
|
|
391
|
+
* Gets the singleton instance of the registry.
|
|
392
|
+
*/
|
|
393
|
+
static get instance(): LoggerChannelRegistry;
|
|
394
|
+
private getDefaultChannelConfig;
|
|
395
|
+
private mergeChannelConfig;
|
|
396
|
+
/**
|
|
397
|
+
* Updates global logger configuration and clears cache.
|
|
398
|
+
*
|
|
399
|
+
* @param config - Partial configuration to merge with existing settings
|
|
400
|
+
*/
|
|
401
|
+
configure(config: Partial<LoggerConfiguration>): void;
|
|
402
|
+
private disposeCachedLoggers;
|
|
403
|
+
/**
|
|
404
|
+
* Returns the name of the default channel.
|
|
405
|
+
*/
|
|
406
|
+
getDefaultChannel(): string;
|
|
407
|
+
/**
|
|
408
|
+
* Returns a list of all known channels (configured or cached).
|
|
409
|
+
*/
|
|
410
|
+
getChannels(): string[];
|
|
411
|
+
/**
|
|
412
|
+
* Gets the log file path for a specific channel, if one exists.
|
|
413
|
+
*
|
|
414
|
+
* @param channel - Channel name to get log file path for
|
|
415
|
+
* @returns The log file path, or null if no file transport exists
|
|
416
|
+
*/
|
|
417
|
+
getLogFilePath(channel: string): string | null;
|
|
418
|
+
/**
|
|
419
|
+
* Gets or creates a Winston logger instance for the given channel.
|
|
420
|
+
*
|
|
421
|
+
* @param channel - Channel name to get logger for
|
|
422
|
+
* @returns Configured Winston logger instance
|
|
423
|
+
*/
|
|
424
|
+
get(channel: string): WinstonInstance;
|
|
425
|
+
private isConsoleMuted;
|
|
426
|
+
/**
|
|
427
|
+
* Installs a custom sink to capture log output across all channels.
|
|
428
|
+
*
|
|
429
|
+
* Useful for routing logs to custom destinations like TUIs or remote services.
|
|
430
|
+
*
|
|
431
|
+
* @param sink - Custom sink implementation to receive log entries
|
|
432
|
+
* @param options - Optional configuration for console muting behavior
|
|
433
|
+
* @returns Handle to dispose the sink when no longer needed
|
|
434
|
+
*/
|
|
435
|
+
installSink(sink: ILoggerSink, options?: {
|
|
436
|
+
muteConsole?: boolean;
|
|
437
|
+
}): ILoggerSinkHandle;
|
|
438
|
+
private uninstallSink;
|
|
439
|
+
private applySinkToCachedLogger;
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/StrictEventEmitter.d.ts
|
|
443
|
+
/** Tuple type used for all event payloads. */
|
|
444
|
+
type SEArgsTuple = readonly unknown[];
|
|
445
|
+
/** Convenience map for emitters that intentionally expose no events. */
|
|
446
|
+
type SENoEvents = Record<never, SEArgsTuple>;
|
|
447
|
+
/**
|
|
448
|
+
* Accepts any object type and constrains every value to be a tuple.
|
|
449
|
+
*
|
|
450
|
+
* @typeParam TEvents - Map of event names to readonly tuple payloads
|
|
451
|
+
*/
|
|
452
|
+
type SEEventMapLike<TEvents extends object> = { [K in keyof TEvents]: SEArgsTuple };
|
|
453
|
+
/**
|
|
454
|
+
* Narrows a provided event map to the keys that can be emitted or listened for.
|
|
455
|
+
*
|
|
456
|
+
* @typeParam TEvents - Map of event names to readonly tuple payloads
|
|
457
|
+
* @internal
|
|
458
|
+
*/
|
|
459
|
+
type SEEventKey<TEvents extends object> = Extract<keyof TEvents, string | symbol>;
|
|
460
|
+
/**
|
|
461
|
+
* Typed wrapper around Node.js {@link EventEmitter} enforcing tuple payloads per event name.
|
|
462
|
+
*
|
|
463
|
+
* @typeParam TEvents - Map of event names to readonly tuple payloads
|
|
464
|
+
*/
|
|
465
|
+
declare class StrictEventEmitter<TEvents extends SEEventMapLike<TEvents>> extends EventEmitter {
|
|
466
|
+
/**
|
|
467
|
+
* Registers a persistent listener with tuple-safe arguments for the given event.
|
|
468
|
+
*
|
|
469
|
+
* @param event - The event name to attach to
|
|
470
|
+
* @param listener - Callback operating on the typed argument tuple for the event
|
|
471
|
+
* @returns This emitter instance for chaining
|
|
472
|
+
*/
|
|
473
|
+
on<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, listener: (...args: TEvents[TEventKey]) => void): this;
|
|
474
|
+
/**
|
|
475
|
+
* Registers a one time listener that is removed after the first invocation.
|
|
476
|
+
*
|
|
477
|
+
* @param event - The event name to attach to
|
|
478
|
+
* @param listener - Callback operating on the typed argument tuple for the event
|
|
479
|
+
* @returns This emitter instance for chaining
|
|
480
|
+
*/
|
|
481
|
+
once<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, listener: (...args: TEvents[TEventKey]) => void): this;
|
|
482
|
+
/**
|
|
483
|
+
* Removes a previously registered listener for the given event.
|
|
484
|
+
*
|
|
485
|
+
* @param event - The event name whose listener should be removed
|
|
486
|
+
* @param listener - Callback originally registered for the event
|
|
487
|
+
* @returns This emitter instance for chaining
|
|
488
|
+
*/
|
|
489
|
+
off<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, listener: (...args: TEvents[TEventKey]) => void): this;
|
|
490
|
+
/**
|
|
491
|
+
* Alias of {@link StrictEventEmitter.on} for compatibility with Node.js EventEmitter APIs.
|
|
492
|
+
*
|
|
493
|
+
* @param event - The event name to attach to
|
|
494
|
+
* @param listener - Callback operating on the typed argument tuple for the event
|
|
495
|
+
* @returns This emitter instance for chaining
|
|
496
|
+
*/
|
|
497
|
+
addListener<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, listener: (...args: TEvents[TEventKey]) => void): this;
|
|
498
|
+
/**
|
|
499
|
+
* Alias of {@link StrictEventEmitter.off} for compatibility with Node.js EventEmitter APIs.
|
|
500
|
+
*
|
|
501
|
+
* @param event - The event name whose listener should be removed
|
|
502
|
+
* @param listener - Callback originally registered for the event
|
|
503
|
+
* @returns This emitter instance for chaining
|
|
504
|
+
*/
|
|
505
|
+
removeListener<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, listener: (...args: TEvents[TEventKey]) => void): this;
|
|
506
|
+
/**
|
|
507
|
+
* Emits an event with the strictly typed argument tuple for the event name.
|
|
508
|
+
*
|
|
509
|
+
* @param event - The event name to emit
|
|
510
|
+
* @param args - Tuple payload for the event
|
|
511
|
+
* @returns True when the event had listeners, false otherwise
|
|
512
|
+
*/
|
|
513
|
+
emit<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, ...args: TEvents[TEventKey]): boolean;
|
|
514
|
+
/**
|
|
515
|
+
* Retrieves the listener list for a given event with the correct tuple signature.
|
|
516
|
+
*
|
|
517
|
+
* @param event - The event name to inspect
|
|
518
|
+
* @returns Array of listeners registered for the event
|
|
519
|
+
*/
|
|
520
|
+
listeners<TEventKey extends SEEventKey<TEvents>>(event: TEventKey): ((...args: TEvents[TEventKey]) => void)[];
|
|
521
|
+
/**
|
|
522
|
+
* Counts listeners for an event without widening the return type of {@link EventEmitter.listenerCount}.
|
|
523
|
+
*
|
|
524
|
+
* @param event - The event name to inspect
|
|
525
|
+
* @returns The total number of listeners registered for the event
|
|
526
|
+
*/
|
|
527
|
+
listenerCountTyped<TEventKey extends SEEventKey<TEvents>>(event: TEventKey): number;
|
|
528
|
+
/**
|
|
529
|
+
* Returns the list of event names known to the emitter with the mapped key type.
|
|
530
|
+
*
|
|
531
|
+
* @returns Array of event keys supported by the emitter
|
|
532
|
+
*/
|
|
533
|
+
eventNamesTyped(): SEEventKey<TEvents>[];
|
|
534
|
+
/**
|
|
535
|
+
* Waits for an event to be emitted, resolving with the listener arguments tuple once triggered.
|
|
536
|
+
* Supports optional abort signals and timeouts for cancellation semantics.
|
|
537
|
+
*
|
|
538
|
+
* @param event - The event name to wait for
|
|
539
|
+
* @param opts - Optional abort signal or timeout in milliseconds
|
|
540
|
+
* @returns Promise resolving with the emitted argument tuple; rejects when aborted or timed out
|
|
541
|
+
*/
|
|
542
|
+
waitFor<TEventKey extends SEEventKey<TEvents>>(event: TEventKey, opts?: {
|
|
543
|
+
signal?: AbortSignal;
|
|
544
|
+
timeoutMs?: number;
|
|
545
|
+
}): Promise<TEvents[TEventKey]>;
|
|
546
|
+
}
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
549
|
+
/**
|
|
550
|
+
Convert a union type to an intersection type.
|
|
551
|
+
|
|
552
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
553
|
+
|
|
554
|
+
@example
|
|
555
|
+
```
|
|
556
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
557
|
+
|
|
558
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
559
|
+
|
|
560
|
+
type Intersection = UnionToIntersection<Union>;
|
|
561
|
+
//=> {the(): void} & {great(arg: string): void} & {escape: boolean}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
@category Type
|
|
565
|
+
*/
|
|
566
|
+
type UnionToIntersection<Union> = (// `extends unknown` is always going to be the case and is used to convert the
|
|
567
|
+
// `Union` into a [distributive conditional
|
|
568
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
569
|
+
Union extends unknown // The union type is used as the only argument to a function since the union
|
|
570
|
+
// of function arguments is an intersection.
|
|
571
|
+
? (distributedUnion: Union) => void // This won't happen.
|
|
572
|
+
: never // Infer the `Intersection` type since TypeScript represents the positional
|
|
573
|
+
// arguments of unions of functions as an intersection of the union.
|
|
574
|
+
) extends ((mergedIntersection: infer Intersection) => void) // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
575
|
+
? Intersection & Union : never;
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-any.d.ts
|
|
578
|
+
/**
|
|
579
|
+
Returns a boolean for whether the given type is `any`.
|
|
580
|
+
|
|
581
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
582
|
+
|
|
583
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
584
|
+
|
|
585
|
+
@example
|
|
586
|
+
```
|
|
587
|
+
import type {IsAny} from 'type-fest';
|
|
588
|
+
|
|
589
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
590
|
+
const anyObject: any = {a: 1, b: 2};
|
|
591
|
+
|
|
592
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
593
|
+
return object[key];
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const typedA = get(typedObject, 'a');
|
|
597
|
+
//=> 1
|
|
598
|
+
|
|
599
|
+
const anyA = get(anyObject, 'a');
|
|
600
|
+
//=> any
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
@category Type Guard
|
|
604
|
+
@category Utilities
|
|
605
|
+
*/
|
|
606
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
609
|
+
/**
|
|
610
|
+
Returns a boolean for whether the given key is an optional key of type.
|
|
611
|
+
|
|
612
|
+
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
613
|
+
|
|
614
|
+
@example
|
|
615
|
+
```
|
|
616
|
+
import type {IsOptionalKeyOf} from 'type-fest';
|
|
617
|
+
|
|
618
|
+
type User = {
|
|
619
|
+
name: string;
|
|
620
|
+
surname: string;
|
|
621
|
+
|
|
622
|
+
luckyNumber?: number;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
type Admin = {
|
|
626
|
+
name: string;
|
|
627
|
+
surname?: string;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
631
|
+
//=> true
|
|
632
|
+
|
|
633
|
+
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
634
|
+
//=> false
|
|
635
|
+
|
|
636
|
+
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
637
|
+
//=> boolean
|
|
638
|
+
|
|
639
|
+
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
640
|
+
//=> false
|
|
641
|
+
|
|
642
|
+
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
643
|
+
//=> boolean
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
@category Type Guard
|
|
647
|
+
@category Utilities
|
|
648
|
+
*/
|
|
649
|
+
type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
652
|
+
/**
|
|
653
|
+
Extract all optional keys from the given type.
|
|
654
|
+
|
|
655
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
656
|
+
|
|
657
|
+
@example
|
|
658
|
+
```
|
|
659
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
660
|
+
|
|
661
|
+
type User = {
|
|
662
|
+
name: string;
|
|
663
|
+
surname: string;
|
|
664
|
+
|
|
665
|
+
luckyNumber?: number;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
669
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
670
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
const update1: UpdateOperation<User> = {
|
|
674
|
+
name: 'Alice',
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
const update2: UpdateOperation<User> = {
|
|
678
|
+
name: 'Bob',
|
|
679
|
+
luckyNumber: REMOVE_FIELD,
|
|
680
|
+
};
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
@category Utilities
|
|
684
|
+
*/
|
|
685
|
+
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
686
|
+
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
687
|
+
: never;
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
690
|
+
/**
|
|
691
|
+
Extract all required keys from the given type.
|
|
692
|
+
|
|
693
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
694
|
+
|
|
695
|
+
@example
|
|
696
|
+
```
|
|
697
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
698
|
+
|
|
699
|
+
declare function createValidation<
|
|
700
|
+
Entity extends object,
|
|
701
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
702
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
703
|
+
|
|
704
|
+
type User = {
|
|
705
|
+
name: string;
|
|
706
|
+
surname: string;
|
|
707
|
+
luckyNumber?: number;
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
711
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
712
|
+
|
|
713
|
+
// @ts-expect-error
|
|
714
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
715
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
@category Utilities
|
|
719
|
+
*/
|
|
720
|
+
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
721
|
+
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
722
|
+
//#endregion
|
|
723
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-never.d.ts
|
|
724
|
+
/**
|
|
725
|
+
Returns a boolean for whether the given type is `never`.
|
|
726
|
+
|
|
727
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
728
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
729
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
730
|
+
|
|
731
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
732
|
+
|
|
733
|
+
@example
|
|
734
|
+
```
|
|
735
|
+
import type {IsNever, And} from 'type-fest';
|
|
736
|
+
|
|
737
|
+
type A = IsNever<never>;
|
|
738
|
+
//=> true
|
|
739
|
+
|
|
740
|
+
type B = IsNever<any>;
|
|
741
|
+
//=> false
|
|
742
|
+
|
|
743
|
+
type C = IsNever<unknown>;
|
|
744
|
+
//=> false
|
|
745
|
+
|
|
746
|
+
type D = IsNever<never[]>;
|
|
747
|
+
//=> false
|
|
748
|
+
|
|
749
|
+
type E = IsNever<object>;
|
|
750
|
+
//=> false
|
|
751
|
+
|
|
752
|
+
type F = IsNever<string>;
|
|
753
|
+
//=> false
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
@example
|
|
757
|
+
```
|
|
758
|
+
import type {IsNever} from 'type-fest';
|
|
759
|
+
|
|
760
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
761
|
+
|
|
762
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
763
|
+
type A = IsTrue<never>;
|
|
764
|
+
//=> never
|
|
765
|
+
|
|
766
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
767
|
+
type IsTrueFixed<T> =
|
|
768
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
769
|
+
|
|
770
|
+
type B = IsTrueFixed<never>;
|
|
771
|
+
//=> false
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
@category Type Guard
|
|
775
|
+
@category Utilities
|
|
776
|
+
*/
|
|
777
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
778
|
+
//#endregion
|
|
779
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/if.d.ts
|
|
780
|
+
/**
|
|
781
|
+
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
782
|
+
|
|
783
|
+
Use-cases:
|
|
784
|
+
- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
|
|
785
|
+
|
|
786
|
+
Note:
|
|
787
|
+
- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
|
|
788
|
+
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
789
|
+
|
|
790
|
+
@example
|
|
791
|
+
```
|
|
792
|
+
import type {If} from 'type-fest';
|
|
793
|
+
|
|
794
|
+
type A = If<true, 'yes', 'no'>;
|
|
795
|
+
//=> 'yes'
|
|
796
|
+
|
|
797
|
+
type B = If<false, 'yes', 'no'>;
|
|
798
|
+
//=> 'no'
|
|
799
|
+
|
|
800
|
+
type C = If<boolean, 'yes', 'no'>;
|
|
801
|
+
//=> 'yes' | 'no'
|
|
802
|
+
|
|
803
|
+
type D = If<any, 'yes', 'no'>;
|
|
804
|
+
//=> 'yes' | 'no'
|
|
805
|
+
|
|
806
|
+
type E = If<never, 'yes', 'no'>;
|
|
807
|
+
//=> 'no'
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
@example
|
|
811
|
+
```
|
|
812
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
813
|
+
|
|
814
|
+
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
815
|
+
//=> 'not any'
|
|
816
|
+
|
|
817
|
+
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
818
|
+
//=> 'is never'
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
@example
|
|
822
|
+
```
|
|
823
|
+
import type {If, IsEqual} from 'type-fest';
|
|
824
|
+
|
|
825
|
+
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
826
|
+
|
|
827
|
+
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
828
|
+
//=> 'equal'
|
|
829
|
+
|
|
830
|
+
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
831
|
+
//=> 'not equal'
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
|
|
835
|
+
|
|
836
|
+
@example
|
|
837
|
+
```
|
|
838
|
+
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
839
|
+
|
|
840
|
+
type HundredZeroes = StringRepeat<'0', 100>;
|
|
841
|
+
|
|
842
|
+
// The following implementation is not tail recursive
|
|
843
|
+
type Includes<S extends string, Char extends string> =
|
|
844
|
+
S extends `${infer First}${infer Rest}`
|
|
845
|
+
? If<IsEqual<First, Char>,
|
|
846
|
+
'found',
|
|
847
|
+
Includes<Rest, Char>>
|
|
848
|
+
: 'not found';
|
|
849
|
+
|
|
850
|
+
// Hence, instantiations with long strings will fail
|
|
851
|
+
// @ts-expect-error
|
|
852
|
+
type Fails = Includes<HundredZeroes, '1'>;
|
|
853
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
854
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
855
|
+
|
|
856
|
+
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
857
|
+
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
858
|
+
S extends `${infer First}${infer Rest}`
|
|
859
|
+
? IsEqual<First, Char> extends true
|
|
860
|
+
? 'found'
|
|
861
|
+
: IncludesWithoutIf<Rest, Char>
|
|
862
|
+
: 'not found';
|
|
863
|
+
|
|
864
|
+
// Now, instantiations with long strings will work
|
|
865
|
+
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
866
|
+
//=> 'not found'
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
@category Type Guard
|
|
870
|
+
@category Utilities
|
|
871
|
+
*/
|
|
872
|
+
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/unknown-array.d.ts
|
|
875
|
+
/**
|
|
876
|
+
Represents an array with `unknown` value.
|
|
877
|
+
|
|
878
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
879
|
+
|
|
880
|
+
@example
|
|
881
|
+
```
|
|
882
|
+
import type {UnknownArray} from 'type-fest';
|
|
883
|
+
|
|
884
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
885
|
+
|
|
886
|
+
type A = IsArray<['foo']>;
|
|
887
|
+
//=> true
|
|
888
|
+
|
|
889
|
+
type B = IsArray<readonly number[]>;
|
|
890
|
+
//=> true
|
|
891
|
+
|
|
892
|
+
type C = IsArray<string>;
|
|
893
|
+
//=> false
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
@category Type
|
|
897
|
+
@category Array
|
|
898
|
+
*/
|
|
899
|
+
type UnknownArray = readonly unknown[];
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/type.d.ts
|
|
902
|
+
/**
|
|
903
|
+
Returns a boolean for whether A is false.
|
|
904
|
+
|
|
905
|
+
@example
|
|
906
|
+
```
|
|
907
|
+
type A = Not<true>;
|
|
908
|
+
//=> false
|
|
909
|
+
|
|
910
|
+
type B = Not<false>;
|
|
911
|
+
//=> true
|
|
912
|
+
```
|
|
913
|
+
*/
|
|
914
|
+
type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
915
|
+
/**
|
|
916
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
917
|
+
|
|
918
|
+
@example
|
|
919
|
+
```
|
|
920
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
921
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
922
|
+
//=> 'VALID'
|
|
923
|
+
|
|
924
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
925
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
926
|
+
//=> 'IS_ANY'
|
|
927
|
+
|
|
928
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
929
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
930
|
+
//=> 'IS_NEVER'
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
Note: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:
|
|
934
|
+
|
|
935
|
+
@example
|
|
936
|
+
```ts
|
|
937
|
+
import type {StringRepeat} from 'type-fest';
|
|
938
|
+
|
|
939
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
940
|
+
|
|
941
|
+
// The following implementation is not tail recursive
|
|
942
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
943
|
+
|
|
944
|
+
// Hence, instantiations with long strings will fail
|
|
945
|
+
// @ts-expect-error
|
|
946
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
947
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
948
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
949
|
+
|
|
950
|
+
// To fix this, move the recursion into a helper type
|
|
951
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
952
|
+
|
|
953
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
954
|
+
|
|
955
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
956
|
+
//=> ''
|
|
957
|
+
```
|
|
958
|
+
*/
|
|
959
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever>>;
|
|
960
|
+
/**
|
|
961
|
+
Indicates the value of `exactOptionalPropertyTypes` compiler option.
|
|
962
|
+
*/
|
|
963
|
+
type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] ? false : true;
|
|
964
|
+
//#endregion
|
|
965
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/array.d.ts
|
|
966
|
+
/**
|
|
967
|
+
Transforms a tuple type by replacing it's rest element with a single element that has the same type as the rest element, while keeping all the non-rest elements intact.
|
|
968
|
+
|
|
969
|
+
@example
|
|
970
|
+
```
|
|
971
|
+
type A = CollapseRestElement<[string, string, ...number[]]>;
|
|
972
|
+
//=> [string, string, number]
|
|
973
|
+
|
|
974
|
+
type B = CollapseRestElement<[...string[], number, number]>;
|
|
975
|
+
//=> [string, number, number]
|
|
976
|
+
|
|
977
|
+
type C = CollapseRestElement<[string, string, ...Array<number | bigint>]>;
|
|
978
|
+
//=> [string, string, number | bigint]
|
|
979
|
+
|
|
980
|
+
type D = CollapseRestElement<[string, number]>;
|
|
981
|
+
//=> [string, number]
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
Note: Optional modifiers (`?`) are removed from elements unless the `exactOptionalPropertyTypes` compiler option is disabled. When disabled, there's an additional `| undefined` for optional elements.
|
|
985
|
+
|
|
986
|
+
@example
|
|
987
|
+
```
|
|
988
|
+
// `exactOptionalPropertyTypes` enabled
|
|
989
|
+
type A = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
990
|
+
//=> [string, string, number]
|
|
991
|
+
|
|
992
|
+
// `exactOptionalPropertyTypes` disabled
|
|
993
|
+
type B = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
994
|
+
//=> [string | undefined, string | undefined, number]
|
|
995
|
+
```
|
|
996
|
+
*/
|
|
997
|
+
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, _CollapseRestElement<TArray>>;
|
|
998
|
+
type _CollapseRestElement<TArray extends UnknownArray, ForwardAccumulator extends UnknownArray = [], BackwardAccumulator extends UnknownArray = []> = TArray extends UnknownArray // For distributing `TArray`
|
|
999
|
+
? keyof TArray & `${number}` extends never // Enters this branch, if `TArray` is empty (e.g., []),
|
|
1000
|
+
// or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
1001
|
+
? TArray extends readonly [...infer Rest, infer Last] ? _CollapseRestElement<Rest, ForwardAccumulator, [Last, ...BackwardAccumulator]> // Accumulate elements that are present after the rest element.
|
|
1002
|
+
: TArray extends readonly [] ? [...ForwardAccumulator, ...BackwardAccumulator] : [...ForwardAccumulator, TArray[number], ...BackwardAccumulator] // Add the rest element between the accumulated elements.
|
|
1003
|
+
: TArray extends readonly [(infer First)?, ...infer Rest] ? _CollapseRestElement<Rest, [...ForwardAccumulator, '0' extends OptionalKeysOf<TArray> ? If<IsExactOptionalPropertyTypesEnabled, First, First | undefined> // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
|
|
1004
|
+
: First], BackwardAccumulator> : never // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
|
|
1005
|
+
: never; // Should never happen
|
|
1006
|
+
//#endregion
|
|
1007
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/numeric.d.ts
|
|
1008
|
+
type _Numeric = number | bigint;
|
|
1009
|
+
type Zero = 0 | 0n;
|
|
1010
|
+
/**
|
|
1011
|
+
Matches the hidden `Infinity` type.
|
|
1012
|
+
|
|
1013
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
1014
|
+
|
|
1015
|
+
@see {@link NegativeInfinity}
|
|
1016
|
+
|
|
1017
|
+
@category Numeric
|
|
1018
|
+
*/
|
|
1019
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
1020
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
1021
|
+
type PositiveInfinity = 1e999;
|
|
1022
|
+
/**
|
|
1023
|
+
Matches the hidden `-Infinity` type.
|
|
1024
|
+
|
|
1025
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
1026
|
+
|
|
1027
|
+
@see {@link PositiveInfinity}
|
|
1028
|
+
|
|
1029
|
+
@category Numeric
|
|
1030
|
+
*/
|
|
1031
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
1032
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
1033
|
+
type NegativeInfinity = -1e999;
|
|
1034
|
+
/**
|
|
1035
|
+
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
1036
|
+
|
|
1037
|
+
Use-case: Validating and documenting parameters.
|
|
1038
|
+
|
|
1039
|
+
@see {@link NegativeInteger}
|
|
1040
|
+
@see {@link NonNegative}
|
|
1041
|
+
|
|
1042
|
+
@category Numeric
|
|
1043
|
+
*/
|
|
1044
|
+
type Negative<T extends _Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
1045
|
+
/**
|
|
1046
|
+
Returns a boolean for whether the given number is a negative number.
|
|
1047
|
+
|
|
1048
|
+
@see {@link Negative}
|
|
1049
|
+
|
|
1050
|
+
@example
|
|
1051
|
+
```
|
|
1052
|
+
import type {IsNegative} from 'type-fest';
|
|
1053
|
+
|
|
1054
|
+
type ShouldBeFalse = IsNegative<1>;
|
|
1055
|
+
type ShouldBeTrue = IsNegative<-1>;
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
@category Numeric
|
|
1059
|
+
*/
|
|
1060
|
+
type IsNegative<T extends _Numeric> = T extends Negative<T> ? true : false;
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/tuple-of.d.ts
|
|
1063
|
+
/**
|
|
1064
|
+
Create a tuple type of the specified length with elements of the specified type.
|
|
1065
|
+
|
|
1066
|
+
@example
|
|
1067
|
+
```
|
|
1068
|
+
import type {TupleOf} from 'type-fest';
|
|
1069
|
+
|
|
1070
|
+
type RGB = TupleOf<3, number>;
|
|
1071
|
+
//=> [number, number, number]
|
|
1072
|
+
|
|
1073
|
+
type Line = TupleOf<2, {x: number; y: number}>;
|
|
1074
|
+
//=> [{x: number; y: number}, {x: number; y: number}]
|
|
1075
|
+
|
|
1076
|
+
type TicTacToeBoard = TupleOf<3, TupleOf<3, 'X' | 'O' | null>>;
|
|
1077
|
+
//=> [['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null]]
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
@example
|
|
1081
|
+
```
|
|
1082
|
+
import type {TupleOf} from 'type-fest';
|
|
1083
|
+
|
|
1084
|
+
type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
|
|
1085
|
+
|
|
1086
|
+
type ZeroToFour = Range<0, 5>;
|
|
1087
|
+
//=> '0' | '1' | '2' | '3' | '4'
|
|
1088
|
+
|
|
1089
|
+
type ThreeToEight = Range<3, 9>;
|
|
1090
|
+
//=> '5' | '3' | '4' | '6' | '7' | '8'
|
|
1091
|
+
```
|
|
1092
|
+
|
|
1093
|
+
Note: If the specified length is the non-literal `number` type, the result will not be a tuple but a regular array.
|
|
1094
|
+
|
|
1095
|
+
@example
|
|
1096
|
+
```
|
|
1097
|
+
import type {TupleOf} from 'type-fest';
|
|
1098
|
+
|
|
1099
|
+
type StringArray = TupleOf<number, string>;
|
|
1100
|
+
//=> string[]
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
Note: If the type for elements is not specified, it will default to `unknown`.
|
|
1104
|
+
|
|
1105
|
+
@example
|
|
1106
|
+
```
|
|
1107
|
+
import type {TupleOf} from 'type-fest';
|
|
1108
|
+
|
|
1109
|
+
type UnknownTriplet = TupleOf<3>;
|
|
1110
|
+
//=> [unknown, unknown, unknown]
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
Note: If the specified length is negative, the result will be an empty tuple.
|
|
1114
|
+
|
|
1115
|
+
@example
|
|
1116
|
+
```
|
|
1117
|
+
import type {TupleOf} from 'type-fest';
|
|
1118
|
+
|
|
1119
|
+
type EmptyTuple = TupleOf<-3, string>;
|
|
1120
|
+
//=> []
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
Note: If you need a readonly tuple, simply wrap this type with `Readonly`, for example, to create `readonly [number, number, number]` use `Readonly<TupleOf<3, number>>`.
|
|
1124
|
+
|
|
1125
|
+
@category Array
|
|
1126
|
+
*/
|
|
1127
|
+
type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length, _TupleOf<If<IsNegative<Length>, 0, Length>, Fill, []>, Fill[], []>;
|
|
1128
|
+
type _TupleOf<L extends number, Fill, Accumulator extends UnknownArray> = number extends L ? Fill[] : L extends Accumulator['length'] ? Accumulator : _TupleOf<L, Fill, [...Accumulator, Fill]>;
|
|
1129
|
+
//#endregion
|
|
1130
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/string.d.ts
|
|
1131
|
+
/**
|
|
1132
|
+
Converts a numeric string to a number.
|
|
1133
|
+
|
|
1134
|
+
@example
|
|
1135
|
+
```
|
|
1136
|
+
type PositiveInt = StringToNumber<'1234'>;
|
|
1137
|
+
//=> 1234
|
|
1138
|
+
|
|
1139
|
+
type NegativeInt = StringToNumber<'-1234'>;
|
|
1140
|
+
//=> -1234
|
|
1141
|
+
|
|
1142
|
+
type PositiveFloat = StringToNumber<'1234.56'>;
|
|
1143
|
+
//=> 1234.56
|
|
1144
|
+
|
|
1145
|
+
type NegativeFloat = StringToNumber<'-1234.56'>;
|
|
1146
|
+
//=> -1234.56
|
|
1147
|
+
|
|
1148
|
+
type PositiveInfinity = StringToNumber<'Infinity'>;
|
|
1149
|
+
//=> Infinity
|
|
1150
|
+
|
|
1151
|
+
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
1152
|
+
//=> -Infinity
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
@category String
|
|
1156
|
+
@category Numeric
|
|
1157
|
+
@category Template literal
|
|
1158
|
+
*/
|
|
1159
|
+
type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends 'Infinity' ? PositiveInfinity : S extends '-Infinity' ? NegativeInfinity : never;
|
|
1160
|
+
/**
|
|
1161
|
+
Returns an array of the characters of the string.
|
|
1162
|
+
|
|
1163
|
+
@example
|
|
1164
|
+
```
|
|
1165
|
+
type A = StringToArray<'abcde'>;
|
|
1166
|
+
//=> ['a', 'b', 'c', 'd', 'e']
|
|
1167
|
+
|
|
1168
|
+
type B = StringToArray<string>;
|
|
1169
|
+
//=> never
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
@category String
|
|
1173
|
+
*/
|
|
1174
|
+
type StringToArray<S extends string, Result extends string[] = []> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [...Result, F]> : Result;
|
|
1175
|
+
/**
|
|
1176
|
+
Returns the length of the given string.
|
|
1177
|
+
|
|
1178
|
+
@example
|
|
1179
|
+
```
|
|
1180
|
+
type A = StringLength<'abcde'>;
|
|
1181
|
+
//=> 5
|
|
1182
|
+
|
|
1183
|
+
type B = StringLength<string>;
|
|
1184
|
+
//=> never
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
@category String
|
|
1188
|
+
@category Template literal
|
|
1189
|
+
*/
|
|
1190
|
+
type StringLength<S extends string> = string extends S ? never : StringToArray<S>['length'];
|
|
1191
|
+
/**
|
|
1192
|
+
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
|
|
1193
|
+
|
|
1194
|
+
@example
|
|
1195
|
+
```
|
|
1196
|
+
type A = SameLengthPositiveNumericStringGt<'50', '10'>;
|
|
1197
|
+
//=> true
|
|
1198
|
+
|
|
1199
|
+
type B = SameLengthPositiveNumericStringGt<'10', '10'>;
|
|
1200
|
+
//=> false
|
|
1201
|
+
```
|
|
1202
|
+
*/
|
|
1203
|
+
type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}` ? B extends `${infer FirstB}${infer RestB}` ? FirstA extends FirstB ? SameLengthPositiveNumericStringGt<RestA, RestB> : PositiveNumericCharacterGt<FirstA, FirstB> : never : false;
|
|
1204
|
+
type NumericString = '0123456789';
|
|
1205
|
+
/**
|
|
1206
|
+
Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
|
|
1207
|
+
|
|
1208
|
+
@example
|
|
1209
|
+
```
|
|
1210
|
+
type A = PositiveNumericStringGt<'500', '1'>;
|
|
1211
|
+
//=> true
|
|
1212
|
+
|
|
1213
|
+
type B = PositiveNumericStringGt<'1', '1'>;
|
|
1214
|
+
//=> false
|
|
1215
|
+
|
|
1216
|
+
type C = PositiveNumericStringGt<'1', '500'>;
|
|
1217
|
+
//=> false
|
|
1218
|
+
```
|
|
1219
|
+
*/
|
|
1220
|
+
type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [TupleOf<StringLength<A>, 0>, TupleOf<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]] ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]] ? 0 extends Remain['length'] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
|
|
1221
|
+
/**
|
|
1222
|
+
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
|
|
1223
|
+
|
|
1224
|
+
@example
|
|
1225
|
+
```
|
|
1226
|
+
type A = PositiveNumericCharacterGt<'5', '1'>;
|
|
1227
|
+
//=> true
|
|
1228
|
+
|
|
1229
|
+
type B = PositiveNumericCharacterGt<'1', '1'>;
|
|
1230
|
+
//=> false
|
|
1231
|
+
```
|
|
1232
|
+
*/
|
|
1233
|
+
type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}` ? NumericString extends `${infer HeadB}${B}${infer TailB}` ? HeadA extends `${HeadB}${infer _}${infer __}` ? true : false : never : never;
|
|
1234
|
+
//#endregion
|
|
1235
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/numeric.d.ts
|
|
1236
|
+
/**
|
|
1237
|
+
Returns the number with reversed sign.
|
|
1238
|
+
|
|
1239
|
+
@example
|
|
1240
|
+
```
|
|
1241
|
+
type A = ReverseSign<-1>;
|
|
1242
|
+
//=> 1
|
|
1243
|
+
|
|
1244
|
+
type B = ReverseSign<1>;
|
|
1245
|
+
//=> -1
|
|
1246
|
+
|
|
1247
|
+
type C = ReverseSign<NegativeInfinity>;
|
|
1248
|
+
//=> PositiveInfinity
|
|
1249
|
+
|
|
1250
|
+
type D = ReverseSign<PositiveInfinity>;
|
|
1251
|
+
//=> NegativeInfinity
|
|
1252
|
+
```
|
|
1253
|
+
*/
|
|
1254
|
+
type ReverseSign<N extends number> = // Handle edge cases
|
|
1255
|
+
N extends 0 ? 0 : N extends PositiveInfinity ? NegativeInfinity : N extends NegativeInfinity ? PositiveInfinity // Handle negative numbers
|
|
1256
|
+
: `${N}` extends `-${infer P extends number}` ? P // Handle positive numbers
|
|
1257
|
+
: `-${N}` extends `${infer R extends number}` ? R : never;
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/simplify.d.ts
|
|
1260
|
+
/**
|
|
1261
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
1262
|
+
|
|
1263
|
+
@example
|
|
1264
|
+
```
|
|
1265
|
+
import type {Simplify} from 'type-fest';
|
|
1266
|
+
|
|
1267
|
+
type PositionProps = {
|
|
1268
|
+
top: number;
|
|
1269
|
+
left: number;
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
type SizeProps = {
|
|
1273
|
+
width: number;
|
|
1274
|
+
height: number;
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
1278
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
1279
|
+
```
|
|
1280
|
+
|
|
1281
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
1282
|
+
|
|
1283
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
1284
|
+
|
|
1285
|
+
@example
|
|
1286
|
+
```
|
|
1287
|
+
import type {Simplify} from 'type-fest';
|
|
1288
|
+
|
|
1289
|
+
interface SomeInterface {
|
|
1290
|
+
foo: number;
|
|
1291
|
+
bar?: string;
|
|
1292
|
+
baz: number | undefined;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
type SomeType = {
|
|
1296
|
+
foo: number;
|
|
1297
|
+
bar?: string;
|
|
1298
|
+
baz: number | undefined;
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
1302
|
+
const someType: SomeType = literal;
|
|
1303
|
+
const someInterface: SomeInterface = literal;
|
|
1304
|
+
|
|
1305
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
1306
|
+
|
|
1307
|
+
fn(literal); // Good: literal object type is sealed
|
|
1308
|
+
fn(someType); // Good: type is sealed
|
|
1309
|
+
// @ts-expect-error
|
|
1310
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
1311
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
1312
|
+
```
|
|
1313
|
+
|
|
1314
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
1315
|
+
@see {@link SimplifyDeep}
|
|
1316
|
+
@category Object
|
|
1317
|
+
*/
|
|
1318
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
1319
|
+
//#endregion
|
|
1320
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-equal.d.ts
|
|
1321
|
+
/**
|
|
1322
|
+
Returns a boolean for whether the two given types are equal.
|
|
1323
|
+
|
|
1324
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
1325
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
1326
|
+
|
|
1327
|
+
Use-cases:
|
|
1328
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
1329
|
+
|
|
1330
|
+
@example
|
|
1331
|
+
```
|
|
1332
|
+
import type {IsEqual} from 'type-fest';
|
|
1333
|
+
|
|
1334
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
1335
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
1336
|
+
type Includes<Value extends readonly any[], Item> =
|
|
1337
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
1338
|
+
? IsEqual<Value[0], Item> extends true
|
|
1339
|
+
? true
|
|
1340
|
+
: Includes<rest, Item>
|
|
1341
|
+
: false;
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
@category Type Guard
|
|
1345
|
+
@category Utilities
|
|
1346
|
+
*/
|
|
1347
|
+
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
1348
|
+
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
1349
|
+
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
1350
|
+
//#endregion
|
|
1351
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
1352
|
+
/**
|
|
1353
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
1354
|
+
|
|
1355
|
+
This is the counterpart of `PickIndexSignature`.
|
|
1356
|
+
|
|
1357
|
+
Use-cases:
|
|
1358
|
+
- Remove overly permissive signatures from third-party types.
|
|
1359
|
+
|
|
1360
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
1361
|
+
|
|
1362
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
1363
|
+
|
|
1364
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
1365
|
+
|
|
1366
|
+
```
|
|
1367
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
1368
|
+
|
|
1369
|
+
// @ts-expect-error
|
|
1370
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
1371
|
+
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
1375
|
+
|
|
1376
|
+
```
|
|
1377
|
+
type Indexed = {} extends Record<string, unknown>
|
|
1378
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1379
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
1380
|
+
|
|
1381
|
+
type IndexedResult = Indexed;
|
|
1382
|
+
//=> '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1383
|
+
|
|
1384
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
1385
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
1386
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
1387
|
+
|
|
1388
|
+
type KeyedResult = Keyed;
|
|
1389
|
+
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
1390
|
+
```
|
|
1391
|
+
|
|
1392
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
1393
|
+
|
|
1394
|
+
```
|
|
1395
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1396
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
1397
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
1398
|
+
};
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
1402
|
+
|
|
1403
|
+
```
|
|
1404
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1405
|
+
[KeyType in keyof ObjectType
|
|
1406
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
1407
|
+
as {} extends Record<KeyType, unknown>
|
|
1408
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
1409
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
1410
|
+
]: ObjectType[KeyType];
|
|
1411
|
+
};
|
|
1412
|
+
```
|
|
1413
|
+
|
|
1414
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
1415
|
+
|
|
1416
|
+
@example
|
|
1417
|
+
```
|
|
1418
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
1419
|
+
|
|
1420
|
+
type Example = {
|
|
1421
|
+
// These index signatures will be removed.
|
|
1422
|
+
[x: string]: any;
|
|
1423
|
+
[x: number]: any;
|
|
1424
|
+
[x: symbol]: any;
|
|
1425
|
+
[x: `head-${string}`]: string;
|
|
1426
|
+
[x: `${string}-tail`]: string;
|
|
1427
|
+
[x: `head-${string}-tail`]: string;
|
|
1428
|
+
[x: `${bigint}`]: string;
|
|
1429
|
+
[x: `embedded-${number}`]: string;
|
|
1430
|
+
|
|
1431
|
+
// These explicitly defined keys will remain.
|
|
1432
|
+
foo: 'bar';
|
|
1433
|
+
qux?: 'baz';
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
1437
|
+
//=> {foo: 'bar'; qux?: 'baz'}
|
|
1438
|
+
```
|
|
1439
|
+
|
|
1440
|
+
@see {@link PickIndexSignature}
|
|
1441
|
+
@category Object
|
|
1442
|
+
*/
|
|
1443
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
1444
|
+
//#endregion
|
|
1445
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
1446
|
+
/**
|
|
1447
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
1448
|
+
|
|
1449
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
1450
|
+
|
|
1451
|
+
@example
|
|
1452
|
+
```
|
|
1453
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
1454
|
+
|
|
1455
|
+
declare const symbolKey: unique symbol;
|
|
1456
|
+
|
|
1457
|
+
type Example = {
|
|
1458
|
+
// These index signatures will remain.
|
|
1459
|
+
[x: string]: unknown;
|
|
1460
|
+
[x: number]: unknown;
|
|
1461
|
+
[x: symbol]: unknown;
|
|
1462
|
+
[x: `head-${string}`]: string;
|
|
1463
|
+
[x: `${string}-tail`]: string;
|
|
1464
|
+
[x: `head-${string}-tail`]: string;
|
|
1465
|
+
[x: `${bigint}`]: string;
|
|
1466
|
+
[x: `embedded-${number}`]: string;
|
|
1467
|
+
|
|
1468
|
+
// These explicitly defined keys will be removed.
|
|
1469
|
+
['kebab-case-key']: string;
|
|
1470
|
+
[symbolKey]: string;
|
|
1471
|
+
foo: 'bar';
|
|
1472
|
+
qux?: 'baz';
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1475
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
1476
|
+
// {
|
|
1477
|
+
// [x: string]: unknown;
|
|
1478
|
+
// [x: number]: unknown;
|
|
1479
|
+
// [x: symbol]: unknown;
|
|
1480
|
+
// [x: `head-${string}`]: string;
|
|
1481
|
+
// [x: `${string}-tail`]: string;
|
|
1482
|
+
// [x: `head-${string}-tail`]: string;
|
|
1483
|
+
// [x: `${bigint}`]: string;
|
|
1484
|
+
// [x: `embedded-${number}`]: string;
|
|
1485
|
+
// }
|
|
1486
|
+
```
|
|
1487
|
+
|
|
1488
|
+
@see {@link OmitIndexSignature}
|
|
1489
|
+
@category Object
|
|
1490
|
+
*/
|
|
1491
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
1492
|
+
//#endregion
|
|
1493
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/merge.d.ts
|
|
1494
|
+
// Merges two objects without worrying about index signatures.
|
|
1495
|
+
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
|
|
1496
|
+
/**
|
|
1497
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
1498
|
+
|
|
1499
|
+
This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
|
|
1500
|
+
|
|
1501
|
+
@example
|
|
1502
|
+
```
|
|
1503
|
+
import type {Merge} from 'type-fest';
|
|
1504
|
+
|
|
1505
|
+
type Foo = {
|
|
1506
|
+
a: string;
|
|
1507
|
+
b: number;
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
type Bar = {
|
|
1511
|
+
a: number; // Conflicts with Foo['a']
|
|
1512
|
+
c: boolean;
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
// With `&`, `a` becomes `string & number` which is `never`. Not what you want.
|
|
1516
|
+
type WithIntersection = (Foo & Bar)['a'];
|
|
1517
|
+
//=> never
|
|
1518
|
+
|
|
1519
|
+
// With `Merge`, `a` is cleanly overridden to `number`.
|
|
1520
|
+
type WithMerge = Merge<Foo, Bar>['a'];
|
|
1521
|
+
//=> number
|
|
1522
|
+
```
|
|
1523
|
+
|
|
1524
|
+
@example
|
|
1525
|
+
```
|
|
1526
|
+
import type {Merge} from 'type-fest';
|
|
1527
|
+
|
|
1528
|
+
type Foo = {
|
|
1529
|
+
[x: string]: unknown;
|
|
1530
|
+
[x: number]: unknown;
|
|
1531
|
+
foo: string;
|
|
1532
|
+
bar: symbol;
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
type Bar = {
|
|
1536
|
+
[x: number]: number;
|
|
1537
|
+
[x: symbol]: unknown;
|
|
1538
|
+
bar: Date;
|
|
1539
|
+
baz: boolean;
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
1543
|
+
//=> {
|
|
1544
|
+
// [x: string]: unknown;
|
|
1545
|
+
// [x: number]: number;
|
|
1546
|
+
// [x: symbol]: unknown;
|
|
1547
|
+
// foo: string;
|
|
1548
|
+
// bar: Date;
|
|
1549
|
+
// baz: boolean;
|
|
1550
|
+
// }
|
|
1551
|
+
```
|
|
1552
|
+
|
|
1553
|
+
Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
|
|
1554
|
+
|
|
1555
|
+
@see {@link ObjectMerge}
|
|
1556
|
+
@category Object
|
|
1557
|
+
*/
|
|
1558
|
+
type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
|
|
1559
|
+
? Source extends unknown // For distributing `Source`
|
|
1560
|
+
? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
|
|
1561
|
+
: never;
|
|
1562
|
+
// Should never happen
|
|
1563
|
+
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
1564
|
+
//#endregion
|
|
1565
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/object.d.ts
|
|
1566
|
+
/**
|
|
1567
|
+
Merges user specified options with default options.
|
|
1568
|
+
|
|
1569
|
+
@example
|
|
1570
|
+
```
|
|
1571
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1572
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1573
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
1574
|
+
|
|
1575
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1576
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
@example
|
|
1580
|
+
```
|
|
1581
|
+
// Complains if default values are not provided for optional options
|
|
1582
|
+
|
|
1583
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1584
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
1585
|
+
type SpecifiedOptions = {};
|
|
1586
|
+
|
|
1587
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1588
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1589
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
1590
|
+
```
|
|
1591
|
+
|
|
1592
|
+
@example
|
|
1593
|
+
```
|
|
1594
|
+
// Complains if an option's default type does not conform to the expected type
|
|
1595
|
+
|
|
1596
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1597
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
1598
|
+
type SpecifiedOptions = {};
|
|
1599
|
+
|
|
1600
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1601
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1602
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1603
|
+
```
|
|
1604
|
+
|
|
1605
|
+
@example
|
|
1606
|
+
```
|
|
1607
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
1608
|
+
|
|
1609
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1610
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1611
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1612
|
+
|
|
1613
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1614
|
+
// ~~~~~~~~~~~~~~~~
|
|
1615
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1616
|
+
```
|
|
1617
|
+
*/
|
|
1618
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
1619
|
+
//#endregion
|
|
1620
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/some-extend.d.ts
|
|
1621
|
+
/**
|
|
1622
|
+
@see {@link SomeExtend}
|
|
1623
|
+
*/
|
|
1624
|
+
type SomeExtendOptions = {
|
|
1625
|
+
/**
|
|
1626
|
+
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1627
|
+
- When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
|
|
1628
|
+
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1629
|
+
@default true
|
|
1630
|
+
@example
|
|
1631
|
+
```
|
|
1632
|
+
import type {SomeExtend} from 'type-fest';
|
|
1633
|
+
type A = SomeExtend<[1, 2, never], string, {strictNever: true}>;
|
|
1634
|
+
//=> false
|
|
1635
|
+
type B = SomeExtend<[1, 2, never], string, {strictNever: false}>;
|
|
1636
|
+
//=> true
|
|
1637
|
+
type C = SomeExtend<[1, never], never, {strictNever: true}>;
|
|
1638
|
+
//=> true
|
|
1639
|
+
type D = SomeExtend<[1, never], never, {strictNever: false}>;
|
|
1640
|
+
//=> true
|
|
1641
|
+
type E = SomeExtend<[never], any, {strictNever: true}>;
|
|
1642
|
+
//=> true
|
|
1643
|
+
type F = SomeExtend<[never], any, {strictNever: false}>;
|
|
1644
|
+
//=> true
|
|
1645
|
+
```
|
|
1646
|
+
*/
|
|
1647
|
+
strictNever?: boolean;
|
|
1648
|
+
};
|
|
1649
|
+
type DefaultSomeExtendOptions = {
|
|
1650
|
+
strictNever: true;
|
|
1651
|
+
};
|
|
1652
|
+
/**
|
|
1653
|
+
Returns a boolean for whether some element in an array type extends another type.
|
|
1654
|
+
|
|
1655
|
+
@example
|
|
1656
|
+
```
|
|
1657
|
+
import type {SomeExtend} from 'type-fest';
|
|
1658
|
+
|
|
1659
|
+
type A = SomeExtend<['1', '2', 3], number>;
|
|
1660
|
+
//=> true
|
|
1661
|
+
|
|
1662
|
+
type B = SomeExtend<[1, 2, 3], string>;
|
|
1663
|
+
//=> false
|
|
1664
|
+
|
|
1665
|
+
type C = SomeExtend<[string, number | string], number>;
|
|
1666
|
+
//=> boolean
|
|
1667
|
+
|
|
1668
|
+
type D = SomeExtend<[true, boolean, true], false>;
|
|
1669
|
+
//=> boolean
|
|
1670
|
+
```
|
|
1671
|
+
|
|
1672
|
+
Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
|
|
1673
|
+
|
|
1674
|
+
```
|
|
1675
|
+
// @exactOptionalPropertyTypes: true
|
|
1676
|
+
import type {SomeExtend} from 'type-fest';
|
|
1677
|
+
|
|
1678
|
+
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1679
|
+
//=> true
|
|
1680
|
+
```
|
|
1681
|
+
|
|
1682
|
+
```
|
|
1683
|
+
// @exactOptionalPropertyTypes: false
|
|
1684
|
+
import type {SomeExtend} from 'type-fest';
|
|
1685
|
+
|
|
1686
|
+
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1687
|
+
//=> boolean
|
|
1688
|
+
|
|
1689
|
+
type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
|
|
1690
|
+
//=> true
|
|
1691
|
+
```
|
|
1692
|
+
|
|
1693
|
+
@see {@link SomeExtendOptions}
|
|
1694
|
+
|
|
1695
|
+
@category Utilities
|
|
1696
|
+
@category Array
|
|
1697
|
+
*/
|
|
1698
|
+
type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> = _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
|
|
1699
|
+
type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
|
|
1700
|
+
? true : _SomeExtend<Rest, Type, Options> : First extends Type ? true : _SomeExtend<Rest, Type, Options> : false, false, false>;
|
|
1701
|
+
//#endregion
|
|
1702
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/or-all.d.ts
|
|
1703
|
+
/**
|
|
1704
|
+
Returns a boolean for whether any of the given elements is `true`.
|
|
1705
|
+
|
|
1706
|
+
Use-cases:
|
|
1707
|
+
- Check if at least one condition in a list of booleans is met.
|
|
1708
|
+
|
|
1709
|
+
@example
|
|
1710
|
+
```
|
|
1711
|
+
import type {OrAll} from 'type-fest';
|
|
1712
|
+
|
|
1713
|
+
type FFT = OrAll<[false, false, true]>;
|
|
1714
|
+
//=> true
|
|
1715
|
+
|
|
1716
|
+
type FFF = OrAll<[false, false, false]>;
|
|
1717
|
+
//=> false
|
|
1718
|
+
```
|
|
1719
|
+
|
|
1720
|
+
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1721
|
+
For example, `OrAll<[false, boolean]>` expands to `OrAll<[false, true]> | OrAll<[false, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1722
|
+
|
|
1723
|
+
@example
|
|
1724
|
+
```
|
|
1725
|
+
import type {OrAll} from 'type-fest';
|
|
1726
|
+
|
|
1727
|
+
type A = OrAll<[false, boolean]>;
|
|
1728
|
+
//=> boolean
|
|
1729
|
+
|
|
1730
|
+
type B = OrAll<[true, boolean]>;
|
|
1731
|
+
//=> true
|
|
1732
|
+
```
|
|
1733
|
+
|
|
1734
|
+
Note: If `never` is passed as an element, it is treated as `false` and the result is computed accordingly.
|
|
1735
|
+
|
|
1736
|
+
@example
|
|
1737
|
+
```
|
|
1738
|
+
import type {OrAll} from 'type-fest';
|
|
1739
|
+
|
|
1740
|
+
type A = OrAll<[never, never, true]>;
|
|
1741
|
+
//=> true
|
|
1742
|
+
|
|
1743
|
+
type B = OrAll<[never, never, false]>;
|
|
1744
|
+
//=> false
|
|
1745
|
+
|
|
1746
|
+
type C = OrAll<[never, never, never]>;
|
|
1747
|
+
//=> false
|
|
1748
|
+
|
|
1749
|
+
type D = OrAll<[never, never, boolean]>;
|
|
1750
|
+
//=> boolean
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
1754
|
+
|
|
1755
|
+
@example
|
|
1756
|
+
```
|
|
1757
|
+
import type {OrAll} from 'type-fest';
|
|
1758
|
+
|
|
1759
|
+
type A = OrAll<[false, any]>;
|
|
1760
|
+
//=> boolean
|
|
1761
|
+
|
|
1762
|
+
type B = OrAll<[true, any]>;
|
|
1763
|
+
//=> true
|
|
1764
|
+
```
|
|
1765
|
+
|
|
1766
|
+
Note: `OrAll<[]>` evaluates to `false` because there are no `true` elements in an empty tuple. See [Wikipedia: Clause (logic) > Empty clauses](https://en.wikipedia.org/wiki/Clause_(logic)#Empty_clauses:~:text=The%20truth%20evaluation%20of%20an%20empty%20disjunctive%20clause%20is%20always%20false.).
|
|
1767
|
+
|
|
1768
|
+
@see {@link Or}
|
|
1769
|
+
@see {@link AndAll}
|
|
1770
|
+
*/
|
|
1771
|
+
type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
|
|
1772
|
+
//#endregion
|
|
1773
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/or.d.ts
|
|
1774
|
+
/**
|
|
1775
|
+
Returns a boolean for whether either of two given types is `true`.
|
|
1776
|
+
|
|
1777
|
+
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
|
|
1778
|
+
|
|
1779
|
+
@example
|
|
1780
|
+
```
|
|
1781
|
+
import type {Or} from 'type-fest';
|
|
1782
|
+
|
|
1783
|
+
type TT = Or<true, true>;
|
|
1784
|
+
//=> true
|
|
1785
|
+
|
|
1786
|
+
type TF = Or<true, false>;
|
|
1787
|
+
//=> true
|
|
1788
|
+
|
|
1789
|
+
type FT = Or<false, true>;
|
|
1790
|
+
//=> true
|
|
1791
|
+
|
|
1792
|
+
type FF = Or<false, false>;
|
|
1793
|
+
//=> false
|
|
1794
|
+
```
|
|
1795
|
+
|
|
1796
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1797
|
+
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1798
|
+
|
|
1799
|
+
@example
|
|
1800
|
+
```
|
|
1801
|
+
import type {Or} from 'type-fest';
|
|
1802
|
+
|
|
1803
|
+
type A = Or<false, boolean>;
|
|
1804
|
+
//=> boolean
|
|
1805
|
+
|
|
1806
|
+
type B = Or<boolean, false>;
|
|
1807
|
+
//=> boolean
|
|
1808
|
+
|
|
1809
|
+
type C = Or<true, boolean>;
|
|
1810
|
+
//=> true
|
|
1811
|
+
|
|
1812
|
+
type D = Or<boolean, true>;
|
|
1813
|
+
//=> true
|
|
1814
|
+
|
|
1815
|
+
type E = Or<boolean, boolean>;
|
|
1816
|
+
//=> boolean
|
|
1817
|
+
```
|
|
1818
|
+
|
|
1819
|
+
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
1820
|
+
|
|
1821
|
+
@example
|
|
1822
|
+
```
|
|
1823
|
+
import type {Or} from 'type-fest';
|
|
1824
|
+
|
|
1825
|
+
type A = Or<true, never>;
|
|
1826
|
+
//=> true
|
|
1827
|
+
|
|
1828
|
+
type B = Or<never, true>;
|
|
1829
|
+
//=> true
|
|
1830
|
+
|
|
1831
|
+
type C = Or<false, never>;
|
|
1832
|
+
//=> false
|
|
1833
|
+
|
|
1834
|
+
type D = Or<never, false>;
|
|
1835
|
+
//=> false
|
|
1836
|
+
|
|
1837
|
+
type E = Or<boolean, never>;
|
|
1838
|
+
//=> boolean
|
|
1839
|
+
|
|
1840
|
+
type F = Or<never, boolean>;
|
|
1841
|
+
//=> boolean
|
|
1842
|
+
|
|
1843
|
+
type G = Or<never, never>;
|
|
1844
|
+
//=> false
|
|
1845
|
+
```
|
|
1846
|
+
|
|
1847
|
+
@see {@link OrAll}
|
|
1848
|
+
@see {@link And}
|
|
1849
|
+
@see {@link Xor}
|
|
1850
|
+
*/
|
|
1851
|
+
type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
|
|
1852
|
+
//#endregion
|
|
1853
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/all-extend.d.ts
|
|
1854
|
+
/**
|
|
1855
|
+
@see {@link AllExtend}
|
|
1856
|
+
*/
|
|
1857
|
+
type AllExtendOptions = {
|
|
1858
|
+
/**
|
|
1859
|
+
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1860
|
+
- When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
|
|
1861
|
+
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1862
|
+
@default true
|
|
1863
|
+
@example
|
|
1864
|
+
```
|
|
1865
|
+
import type {AllExtend} from 'type-fest';
|
|
1866
|
+
type A = AllExtend<[1, 2, never], number, {strictNever: true}>;
|
|
1867
|
+
//=> false
|
|
1868
|
+
type B = AllExtend<[1, 2, never], number, {strictNever: false}>;
|
|
1869
|
+
//=> true
|
|
1870
|
+
type C = AllExtend<[never, never], never, {strictNever: true}>;
|
|
1871
|
+
//=> true
|
|
1872
|
+
type D = AllExtend<[never, never], never, {strictNever: false}>;
|
|
1873
|
+
//=> true
|
|
1874
|
+
type E = AllExtend<['a', 'b', never], any, {strictNever: true}>;
|
|
1875
|
+
//=> true
|
|
1876
|
+
type F = AllExtend<['a', 'b', never], any, {strictNever: false}>;
|
|
1877
|
+
//=> true
|
|
1878
|
+
type G = AllExtend<[never, 1], never, {strictNever: true}>;
|
|
1879
|
+
//=> false
|
|
1880
|
+
type H = AllExtend<[never, 1], never, {strictNever: false}>;
|
|
1881
|
+
//=> false
|
|
1882
|
+
```
|
|
1883
|
+
*/
|
|
1884
|
+
strictNever?: boolean;
|
|
1885
|
+
};
|
|
1886
|
+
type DefaultAllExtendOptions = {
|
|
1887
|
+
strictNever: true;
|
|
1888
|
+
};
|
|
1889
|
+
/**
|
|
1890
|
+
Returns a boolean for whether every element in an array type extends another type.
|
|
1891
|
+
|
|
1892
|
+
@example
|
|
1893
|
+
```
|
|
1894
|
+
import type {AllExtend} from 'type-fest';
|
|
1895
|
+
|
|
1896
|
+
type A = AllExtend<[1, 2, 3], number>;
|
|
1897
|
+
//=> true
|
|
1898
|
+
|
|
1899
|
+
type B = AllExtend<[1, 2, '3'], number>;
|
|
1900
|
+
//=> false
|
|
1901
|
+
|
|
1902
|
+
type C = AllExtend<[number, number | string], number>;
|
|
1903
|
+
//=> boolean
|
|
1904
|
+
|
|
1905
|
+
type D = AllExtend<[true, boolean, true], true>;
|
|
1906
|
+
//=> boolean
|
|
1907
|
+
```
|
|
1908
|
+
|
|
1909
|
+
Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
|
|
1910
|
+
|
|
1911
|
+
```
|
|
1912
|
+
// @exactOptionalPropertyTypes: true
|
|
1913
|
+
import type {AllExtend} from 'type-fest';
|
|
1914
|
+
|
|
1915
|
+
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
1916
|
+
//=> true
|
|
1917
|
+
```
|
|
1918
|
+
|
|
1919
|
+
```
|
|
1920
|
+
// @exactOptionalPropertyTypes: false
|
|
1921
|
+
import type {AllExtend} from 'type-fest';
|
|
1922
|
+
|
|
1923
|
+
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
1924
|
+
//=> boolean
|
|
1925
|
+
|
|
1926
|
+
type B = AllExtend<[1?, 2?, 3?], number | undefined>;
|
|
1927
|
+
//=> true
|
|
1928
|
+
```
|
|
1929
|
+
|
|
1930
|
+
@see {@link AllExtendOptions}
|
|
1931
|
+
|
|
1932
|
+
@category Utilities
|
|
1933
|
+
@category Array
|
|
1934
|
+
*/
|
|
1935
|
+
type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> = _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
|
|
1936
|
+
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
|
|
1937
|
+
? _AllExtend<Rest, Type, Options> : false : First extends Type ? _AllExtend<Rest, Type, Options> : false : true, false, false>;
|
|
1938
|
+
//#endregion
|
|
1939
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/and-all.d.ts
|
|
1940
|
+
/**
|
|
1941
|
+
Returns a boolean for whether all of the given elements are `true`.
|
|
1942
|
+
|
|
1943
|
+
Use-cases:
|
|
1944
|
+
- Check if all conditions in a list of booleans are met.
|
|
1945
|
+
|
|
1946
|
+
@example
|
|
1947
|
+
```
|
|
1948
|
+
import type {AndAll} from 'type-fest';
|
|
1949
|
+
|
|
1950
|
+
type TTT = AndAll<[true, true, true]>;
|
|
1951
|
+
//=> true
|
|
1952
|
+
|
|
1953
|
+
type TTF = AndAll<[true, true, false]>;
|
|
1954
|
+
//=> false
|
|
1955
|
+
|
|
1956
|
+
type TFT = AndAll<[true, false, true]>;
|
|
1957
|
+
//=> false
|
|
1958
|
+
```
|
|
1959
|
+
|
|
1960
|
+
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1961
|
+
For example, `AndAll<[true, boolean]>` expands to `AndAll<[true, true]> | AndAll<[true, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1962
|
+
|
|
1963
|
+
@example
|
|
1964
|
+
```
|
|
1965
|
+
import type {AndAll} from 'type-fest';
|
|
1966
|
+
|
|
1967
|
+
type A = AndAll<[true, boolean]>;
|
|
1968
|
+
//=> boolean
|
|
1969
|
+
|
|
1970
|
+
type B = AndAll<[false, boolean]>;
|
|
1971
|
+
//=> false
|
|
1972
|
+
```
|
|
1973
|
+
|
|
1974
|
+
Note: If any of the elements is `never`, the result becomes `false`.
|
|
1975
|
+
|
|
1976
|
+
@example
|
|
1977
|
+
```
|
|
1978
|
+
import type {AndAll} from 'type-fest';
|
|
1979
|
+
|
|
1980
|
+
type A = AndAll<[true, true, never]>;
|
|
1981
|
+
//=> false
|
|
1982
|
+
|
|
1983
|
+
type B = AndAll<[false, never, never]>;
|
|
1984
|
+
//=> false
|
|
1985
|
+
|
|
1986
|
+
type C = AndAll<[never, never, never]>;
|
|
1987
|
+
//=> false
|
|
1988
|
+
|
|
1989
|
+
type D = AndAll<[boolean, true, never]>;
|
|
1990
|
+
//=> false
|
|
1991
|
+
```
|
|
1992
|
+
|
|
1993
|
+
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
1994
|
+
|
|
1995
|
+
@example
|
|
1996
|
+
```
|
|
1997
|
+
import type {AndAll} from 'type-fest';
|
|
1998
|
+
|
|
1999
|
+
type A = AndAll<[false, any]>;
|
|
2000
|
+
//=> false
|
|
2001
|
+
|
|
2002
|
+
type B = AndAll<[true, any]>;
|
|
2003
|
+
//=> boolean
|
|
2004
|
+
```
|
|
2005
|
+
|
|
2006
|
+
Note: `AndAll<[]>` evaluates to `true` due to the concept of [vacuous truth](https://en.wikipedia.org/wiki/Logical_conjunction#:~:text=In%20keeping%20with%20the%20concept%20of%20vacuous%20truth%2C%20when%20conjunction%20is%20defined%20as%20an%20operator%20or%20function%20of%20arbitrary%20arity%2C%20the%20empty%20conjunction%20(AND%2Ding%20over%20an%20empty%20set%20of%20operands)%20is%20often%20defined%20as%20having%20the%20result%20true.), i.e., there are no `false` elements in an empty tuple.
|
|
2007
|
+
|
|
2008
|
+
@see {@link And}
|
|
2009
|
+
@see {@link OrAll}
|
|
2010
|
+
*/
|
|
2011
|
+
type AndAll<T extends readonly boolean[]> = AllExtend<T, true>;
|
|
2012
|
+
//#endregion
|
|
2013
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/and.d.ts
|
|
2014
|
+
/**
|
|
2015
|
+
Returns a boolean for whether two given types are both `true`.
|
|
2016
|
+
|
|
2017
|
+
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
|
2018
|
+
|
|
2019
|
+
@example
|
|
2020
|
+
```
|
|
2021
|
+
import type {And} from 'type-fest';
|
|
2022
|
+
|
|
2023
|
+
type TT = And<true, true>;
|
|
2024
|
+
//=> true
|
|
2025
|
+
|
|
2026
|
+
type TF = And<true, false>;
|
|
2027
|
+
//=> false
|
|
2028
|
+
|
|
2029
|
+
type FT = And<false, true>;
|
|
2030
|
+
//=> false
|
|
2031
|
+
|
|
2032
|
+
type FF = And<false, false>;
|
|
2033
|
+
//=> false
|
|
2034
|
+
```
|
|
2035
|
+
|
|
2036
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
2037
|
+
For example, `And<true, boolean>` expands to `And<true, true> | And<true, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
2038
|
+
|
|
2039
|
+
@example
|
|
2040
|
+
```
|
|
2041
|
+
import type {And} from 'type-fest';
|
|
2042
|
+
|
|
2043
|
+
type A = And<true, boolean>;
|
|
2044
|
+
//=> boolean
|
|
2045
|
+
|
|
2046
|
+
type B = And<boolean, true>;
|
|
2047
|
+
//=> boolean
|
|
2048
|
+
|
|
2049
|
+
type C = And<false, boolean>;
|
|
2050
|
+
//=> false
|
|
2051
|
+
|
|
2052
|
+
type D = And<boolean, false>;
|
|
2053
|
+
//=> false
|
|
2054
|
+
|
|
2055
|
+
type E = And<boolean, boolean>;
|
|
2056
|
+
//=> boolean
|
|
2057
|
+
```
|
|
2058
|
+
|
|
2059
|
+
Note: If either of the types is `never`, the result becomes `false`.
|
|
2060
|
+
|
|
2061
|
+
@example
|
|
2062
|
+
```
|
|
2063
|
+
import type {And} from 'type-fest';
|
|
2064
|
+
|
|
2065
|
+
type A = And<true, never>;
|
|
2066
|
+
//=> false
|
|
2067
|
+
|
|
2068
|
+
type B = And<never, true>;
|
|
2069
|
+
//=> false
|
|
2070
|
+
|
|
2071
|
+
type C = And<false, never>;
|
|
2072
|
+
//=> false
|
|
2073
|
+
|
|
2074
|
+
type D = And<never, false>;
|
|
2075
|
+
//=> false
|
|
2076
|
+
|
|
2077
|
+
type E = And<boolean, never>;
|
|
2078
|
+
//=> false
|
|
2079
|
+
|
|
2080
|
+
type F = And<never, boolean>;
|
|
2081
|
+
//=> false
|
|
2082
|
+
|
|
2083
|
+
type G = And<never, never>;
|
|
2084
|
+
//=> false
|
|
2085
|
+
```
|
|
2086
|
+
|
|
2087
|
+
@see {@link AndAll}
|
|
2088
|
+
@see {@link Or}
|
|
2089
|
+
@see {@link Xor}
|
|
2090
|
+
*/
|
|
2091
|
+
type And<A extends boolean, B extends boolean> = AndAll<[A, B]>;
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/absolute.d.ts
|
|
2094
|
+
/**
|
|
2095
|
+
Returns the absolute value of the specified number or bigint.
|
|
2096
|
+
|
|
2097
|
+
@example
|
|
2098
|
+
```
|
|
2099
|
+
import type {Absolute} from 'type-fest';
|
|
2100
|
+
|
|
2101
|
+
type A = Absolute<-1>;
|
|
2102
|
+
//=> 1
|
|
2103
|
+
|
|
2104
|
+
type B = Absolute<1>;
|
|
2105
|
+
//=> 1
|
|
2106
|
+
|
|
2107
|
+
type C = Absolute<0>;
|
|
2108
|
+
//=> 0
|
|
2109
|
+
|
|
2110
|
+
type D = Absolute<-1.025>;
|
|
2111
|
+
//=> 1.025
|
|
2112
|
+
|
|
2113
|
+
type E = Absolute<-9999n>;
|
|
2114
|
+
//=> 9999n
|
|
2115
|
+
```
|
|
2116
|
+
|
|
2117
|
+
Returns back the same type if the input is not a literal type.
|
|
2118
|
+
|
|
2119
|
+
@example
|
|
2120
|
+
```
|
|
2121
|
+
import type {Absolute} from 'type-fest';
|
|
2122
|
+
|
|
2123
|
+
type A = Absolute<number>;
|
|
2124
|
+
//=> number
|
|
2125
|
+
|
|
2126
|
+
type B = Absolute<bigint>;
|
|
2127
|
+
//=> bigint
|
|
2128
|
+
|
|
2129
|
+
type C = Absolute<number | bigint>;
|
|
2130
|
+
//=> number | bigint
|
|
2131
|
+
```
|
|
2132
|
+
|
|
2133
|
+
@category Numeric
|
|
2134
|
+
*/
|
|
2135
|
+
type Absolute<N extends number | bigint> = N extends bigint // Also, distributes `N`
|
|
2136
|
+
? `${N}` extends `-${infer Magnitude extends bigint}` ? Magnitude : N : `${N}` extends `-${infer Magnitude}` // This doesn't use the `extends number` constraint approach because that fails with the `-Infinity` case
|
|
2137
|
+
? StringToNumber<Magnitude> : N;
|
|
2138
|
+
//#endregion
|
|
2139
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/greater-than.d.ts
|
|
2140
|
+
/**
|
|
2141
|
+
Returns a boolean for whether a given number is greater than another number.
|
|
2142
|
+
|
|
2143
|
+
@example
|
|
2144
|
+
```
|
|
2145
|
+
import type {GreaterThan} from 'type-fest';
|
|
2146
|
+
|
|
2147
|
+
type A = GreaterThan<1, -5>;
|
|
2148
|
+
//=> true
|
|
2149
|
+
|
|
2150
|
+
type B = GreaterThan<1, 1>;
|
|
2151
|
+
//=> false
|
|
2152
|
+
|
|
2153
|
+
type C = GreaterThan<1, 5>;
|
|
2154
|
+
//=> false
|
|
2155
|
+
```
|
|
2156
|
+
|
|
2157
|
+
Note: If either argument is the non-literal `number` type, the result is `boolean`.
|
|
2158
|
+
|
|
2159
|
+
@example
|
|
2160
|
+
```
|
|
2161
|
+
import type {GreaterThan} from 'type-fest';
|
|
2162
|
+
|
|
2163
|
+
type A = GreaterThan<number, 1>;
|
|
2164
|
+
//=> boolean
|
|
2165
|
+
|
|
2166
|
+
type B = GreaterThan<1, number>;
|
|
2167
|
+
//=> boolean
|
|
2168
|
+
|
|
2169
|
+
type C = GreaterThan<number, number>;
|
|
2170
|
+
//=> boolean
|
|
2171
|
+
```
|
|
2172
|
+
|
|
2173
|
+
@example
|
|
2174
|
+
```
|
|
2175
|
+
import type {GreaterThan} from 'type-fest';
|
|
2176
|
+
|
|
2177
|
+
// Use `GreaterThan` to constrain a function parameter to positive numbers.
|
|
2178
|
+
declare function setPositive<N extends number>(value: GreaterThan<N, 0> extends true ? N : never): void;
|
|
2179
|
+
|
|
2180
|
+
setPositive(1); // ✅ Allowed
|
|
2181
|
+
setPositive(2); // ✅ Allowed
|
|
2182
|
+
|
|
2183
|
+
// @ts-expect-error
|
|
2184
|
+
setPositive(0);
|
|
2185
|
+
|
|
2186
|
+
// @ts-expect-error
|
|
2187
|
+
setPositive(-1);
|
|
2188
|
+
```
|
|
2189
|
+
*/
|
|
2190
|
+
type GreaterThan<A extends number, B extends number> = A extends number // For distributing `A`
|
|
2191
|
+
? B extends number // For distributing `B`
|
|
2192
|
+
? number extends A | B ? boolean : [IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>, IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>] extends infer R extends [boolean, boolean, boolean, boolean] ? Or<And<IsEqual<R[0], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[1], false>>> extends true ? true : Or<And<IsEqual<R[1], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[0], false>>> extends true ? false : true extends R[number] ? false : [IsNegative<A>, IsNegative<B>] extends infer R extends [boolean, boolean] ? [true, false] extends R ? false : [false, true] extends R ? true : [false, false] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${Absolute<B>}`, `${Absolute<A>}`> : never : never : never // Should never happen
|
|
2193
|
+
: never;
|
|
2194
|
+
//#endregion
|
|
2195
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/greater-than-or-equal.d.ts
|
|
2196
|
+
/**
|
|
2197
|
+
Returns a boolean for whether a given number is greater than or equal to another number.
|
|
2198
|
+
|
|
2199
|
+
@example
|
|
2200
|
+
```
|
|
2201
|
+
import type {GreaterThanOrEqual} from 'type-fest';
|
|
2202
|
+
|
|
2203
|
+
type A = GreaterThanOrEqual<1, -5>;
|
|
2204
|
+
//=> true
|
|
2205
|
+
|
|
2206
|
+
type B = GreaterThanOrEqual<1, 1>;
|
|
2207
|
+
//=> true
|
|
2208
|
+
|
|
2209
|
+
type C = GreaterThanOrEqual<1, 5>;
|
|
2210
|
+
//=> false
|
|
2211
|
+
```
|
|
2212
|
+
|
|
2213
|
+
Note: If either argument is the non-literal `number` type, the result is `boolean`.
|
|
2214
|
+
|
|
2215
|
+
@example
|
|
2216
|
+
```
|
|
2217
|
+
import type {GreaterThanOrEqual} from 'type-fest';
|
|
2218
|
+
|
|
2219
|
+
type A = GreaterThanOrEqual<number, 1>;
|
|
2220
|
+
//=> boolean
|
|
2221
|
+
|
|
2222
|
+
type B = GreaterThanOrEqual<1, number>;
|
|
2223
|
+
//=> boolean
|
|
2224
|
+
|
|
2225
|
+
type C = GreaterThanOrEqual<number, number>;
|
|
2226
|
+
//=> boolean
|
|
2227
|
+
```
|
|
2228
|
+
|
|
2229
|
+
@example
|
|
2230
|
+
```
|
|
2231
|
+
import type {GreaterThanOrEqual} from 'type-fest';
|
|
2232
|
+
|
|
2233
|
+
// Use `GreaterThanOrEqual` to constrain a function parameter to non-negative numbers.
|
|
2234
|
+
declare function setNonNegative<N extends number>(value: GreaterThanOrEqual<N, 0> extends true ? N : never): void;
|
|
2235
|
+
|
|
2236
|
+
setNonNegative(0); // ✅ Allowed
|
|
2237
|
+
setNonNegative(1); // ✅ Allowed
|
|
2238
|
+
|
|
2239
|
+
// @ts-expect-error
|
|
2240
|
+
setNonNegative(-1);
|
|
2241
|
+
|
|
2242
|
+
// @ts-expect-error
|
|
2243
|
+
setNonNegative(-2);
|
|
2244
|
+
```
|
|
2245
|
+
*/
|
|
2246
|
+
type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? boolean : A extends number // For distributing `A`
|
|
2247
|
+
? B extends number // For distributing `B`
|
|
2248
|
+
? A extends B ? true : GreaterThan<A, B> : never // Should never happen
|
|
2249
|
+
: never;
|
|
2250
|
+
//#endregion
|
|
2251
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/less-than.d.ts
|
|
2252
|
+
/**
|
|
2253
|
+
Returns a boolean for whether a given number is less than another number.
|
|
2254
|
+
|
|
2255
|
+
@example
|
|
2256
|
+
```
|
|
2257
|
+
import type {LessThan} from 'type-fest';
|
|
2258
|
+
|
|
2259
|
+
type A = LessThan<1, -5>;
|
|
2260
|
+
//=> false
|
|
2261
|
+
|
|
2262
|
+
type B = LessThan<1, 1>;
|
|
2263
|
+
//=> false
|
|
2264
|
+
|
|
2265
|
+
type C = LessThan<1, 5>;
|
|
2266
|
+
//=> true
|
|
2267
|
+
```
|
|
2268
|
+
|
|
2269
|
+
Note: If either argument is the non-literal `number` type, the result is `boolean`.
|
|
2270
|
+
|
|
2271
|
+
@example
|
|
2272
|
+
```
|
|
2273
|
+
import type {LessThan} from 'type-fest';
|
|
2274
|
+
|
|
2275
|
+
type A = LessThan<number, 1>;
|
|
2276
|
+
//=> boolean
|
|
2277
|
+
|
|
2278
|
+
type B = LessThan<1, number>;
|
|
2279
|
+
//=> boolean
|
|
2280
|
+
|
|
2281
|
+
type C = LessThan<number, number>;
|
|
2282
|
+
//=> boolean
|
|
2283
|
+
```
|
|
2284
|
+
|
|
2285
|
+
@example
|
|
2286
|
+
```
|
|
2287
|
+
import type {LessThan} from 'type-fest';
|
|
2288
|
+
|
|
2289
|
+
// Use `LessThan` to constrain a function parameter to negative numbers.
|
|
2290
|
+
declare function setNegative<N extends number>(value: LessThan<N, 0> extends true ? N : never): void;
|
|
2291
|
+
|
|
2292
|
+
setNegative(-1); // ✅ Allowed
|
|
2293
|
+
setNegative(-2); // ✅ Allowed
|
|
2294
|
+
|
|
2295
|
+
// @ts-expect-error
|
|
2296
|
+
setNegative(0);
|
|
2297
|
+
|
|
2298
|
+
// @ts-expect-error
|
|
2299
|
+
setNegative(1);
|
|
2300
|
+
```
|
|
2301
|
+
*/
|
|
2302
|
+
type LessThan<A extends number, B extends number> = GreaterThanOrEqual<A, B> extends infer Result ? Result extends true ? false : true : never;
|
|
2303
|
+
//#endregion
|
|
2304
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/tuple.d.ts
|
|
2305
|
+
// Should never happen
|
|
2306
|
+
/**
|
|
2307
|
+
Returns the maximum value from a tuple of integers.
|
|
2308
|
+
|
|
2309
|
+
Note:
|
|
2310
|
+
- Float numbers are not supported.
|
|
2311
|
+
|
|
2312
|
+
@example
|
|
2313
|
+
```
|
|
2314
|
+
type A = TupleMax<[1, 2, 5, 3]>;
|
|
2315
|
+
//=> 5
|
|
2316
|
+
|
|
2317
|
+
type B = TupleMax<[1, 2, 5, 3, 99, -1]>;
|
|
2318
|
+
//=> 99
|
|
2319
|
+
```
|
|
2320
|
+
*/
|
|
2321
|
+
type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [infer F extends number, ...infer R extends number[]] ? GreaterThan<F, Result> extends true ? TupleMax<R, F> : TupleMax<R, Result> : Result;
|
|
2322
|
+
//#endregion
|
|
2323
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/subtract.d.ts
|
|
2324
|
+
/**
|
|
2325
|
+
Returns the difference between two numbers.
|
|
2326
|
+
|
|
2327
|
+
Note:
|
|
2328
|
+
- A or B can only support `-999` ~ `999`.
|
|
2329
|
+
|
|
2330
|
+
@example
|
|
2331
|
+
```
|
|
2332
|
+
import type {Subtract, PositiveInfinity} from 'type-fest';
|
|
2333
|
+
|
|
2334
|
+
type A = Subtract<333, 222>;
|
|
2335
|
+
//=> 111
|
|
2336
|
+
|
|
2337
|
+
type B = Subtract<111, -222>;
|
|
2338
|
+
//=> 333
|
|
2339
|
+
|
|
2340
|
+
type C = Subtract<-111, 222>;
|
|
2341
|
+
//=> -333
|
|
2342
|
+
|
|
2343
|
+
type D = Subtract<18, 96>;
|
|
2344
|
+
//=> -78
|
|
2345
|
+
|
|
2346
|
+
type E = Subtract<PositiveInfinity, 9999>;
|
|
2347
|
+
//=> Infinity
|
|
2348
|
+
|
|
2349
|
+
type F = Subtract<PositiveInfinity, PositiveInfinity>;
|
|
2350
|
+
//=> number
|
|
2351
|
+
```
|
|
2352
|
+
|
|
2353
|
+
@category Numeric
|
|
2354
|
+
*/
|
|
2355
|
+
// TODO: Support big integer.
|
|
2356
|
+
type Subtract<A extends number, B extends number> = // Handle cases when A or B is the actual "number" type
|
|
2357
|
+
number extends A | B ? number // Handle cases when A and B are both +/- infinity
|
|
2358
|
+
: A extends B & (PositiveInfinity | NegativeInfinity) ? number // Handle cases when A is - infinity or B is + infinity
|
|
2359
|
+
: A extends NegativeInfinity ? NegativeInfinity : B extends PositiveInfinity ? NegativeInfinity // Handle cases when A is + infinity or B is - infinity
|
|
2360
|
+
: A extends PositiveInfinity ? PositiveInfinity : B extends NegativeInfinity ? PositiveInfinity // Handle case when numbers are equal to each other
|
|
2361
|
+
: A extends B ? 0 // Handle cases when A or B is 0
|
|
2362
|
+
: A extends 0 ? ReverseSign<B> : B extends 0 ? A // Handle remaining regular cases
|
|
2363
|
+
: SubtractPostChecks<A, B>;
|
|
2364
|
+
/**
|
|
2365
|
+
Subtracts two numbers A and B, such that they are not equal and neither of them are 0, +/- infinity or the `number` type
|
|
2366
|
+
*/
|
|
2367
|
+
type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNegative<A>, IsNegative<B>]> = AreNegative extends [false, false] ? SubtractPositives<A, B> : AreNegative extends [true, true] // When both numbers are negative we subtract the absolute values and then reverse the sign
|
|
2368
|
+
? ReverseSign<SubtractPositives<Absolute<A>, Absolute<B>>> // When the signs are different we can add the absolute values and then reverse the sign if A < B
|
|
2369
|
+
: [...TupleOf<Absolute<A>>, ...TupleOf<Absolute<B>>] extends infer R extends unknown[] ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length'] : never;
|
|
2370
|
+
/**
|
|
2371
|
+
Subtracts two positive numbers.
|
|
2372
|
+
*/
|
|
2373
|
+
type SubtractPositives<A extends number, B extends number> = LessThan<A, B> extends true // When A < B we can reverse the result of B - A
|
|
2374
|
+
? ReverseSign<SubtractIfAGreaterThanB<B, A>> : SubtractIfAGreaterThanB<A, B>;
|
|
2375
|
+
/**
|
|
2376
|
+
Subtracts two positive numbers A and B such that A > B.
|
|
2377
|
+
*/
|
|
2378
|
+
type SubtractIfAGreaterThanB<A extends number, B extends number> = // This is where we always want to end up and do the actual subtraction
|
|
2379
|
+
TupleOf<A> extends [...TupleOf<B>, ...infer R] ? R['length'] : never;
|
|
2380
|
+
//#endregion
|
|
2381
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/sum.d.ts
|
|
2382
|
+
/**
|
|
2383
|
+
Returns the sum of two numbers.
|
|
2384
|
+
|
|
2385
|
+
Note:
|
|
2386
|
+
- A or B can only support `-999` ~ `999`.
|
|
2387
|
+
|
|
2388
|
+
@example
|
|
2389
|
+
```
|
|
2390
|
+
import type {Sum, PositiveInfinity, NegativeInfinity} from 'type-fest';
|
|
2391
|
+
|
|
2392
|
+
type A = Sum<111, 222>;
|
|
2393
|
+
//=> 333
|
|
2394
|
+
|
|
2395
|
+
type B = Sum<-111, 222>;
|
|
2396
|
+
//=> 111
|
|
2397
|
+
|
|
2398
|
+
type C = Sum<111, -222>;
|
|
2399
|
+
//=> -111
|
|
2400
|
+
|
|
2401
|
+
type D = Sum<PositiveInfinity, -9999>;
|
|
2402
|
+
//=> Infinity
|
|
2403
|
+
|
|
2404
|
+
type E = Sum<PositiveInfinity, NegativeInfinity>;
|
|
2405
|
+
//=> number
|
|
2406
|
+
```
|
|
2407
|
+
|
|
2408
|
+
@category Numeric
|
|
2409
|
+
*/
|
|
2410
|
+
// TODO: Support big integer.
|
|
2411
|
+
type Sum<A extends number, B extends number> = // Handle cases when A or B is the actual "number" type
|
|
2412
|
+
number extends A | B ? number // Handle cases when A and B are both +/- infinity
|
|
2413
|
+
: A extends B & (PositiveInfinity | NegativeInfinity) ? A // A or B could be used here as they are equal
|
|
2414
|
+
// Handle cases when A and B are opposite infinities
|
|
2415
|
+
: A | B extends PositiveInfinity | NegativeInfinity ? number // Handle cases when A is +/- infinity
|
|
2416
|
+
: A extends PositiveInfinity | NegativeInfinity ? A // Handle cases when B is +/- infinity
|
|
2417
|
+
: B extends PositiveInfinity | NegativeInfinity ? B // Handle cases when A or B is 0 or it's the same number with different signs
|
|
2418
|
+
: A extends 0 ? B : B extends 0 ? A : A extends ReverseSign<B> ? 0 // Handle remaining regular cases
|
|
2419
|
+
: SumPostChecks<A, B>;
|
|
2420
|
+
/**
|
|
2421
|
+
Adds two numbers A and B, such that they are not equal with different signs and neither of them are 0, +/- infinity or the `number` type
|
|
2422
|
+
*/
|
|
2423
|
+
type SumPostChecks<A extends number, B extends number, AreNegative = [IsNegative<A>, IsNegative<B>]> = AreNegative extends [false, false] // When both numbers are positive we can add them together
|
|
2424
|
+
? SumPositives<A, B> : AreNegative extends [true, true] // When both numbers are negative we add the absolute values and then reverse the sign
|
|
2425
|
+
? ReverseSign<SumPositives<Absolute<A>, Absolute<B>>> // When the signs are different we can subtract the absolute values, remove the sign
|
|
2426
|
+
// and then reverse the sign if the larger absolute value is negative
|
|
2427
|
+
: Absolute<Subtract<Absolute<A>, Absolute<B>>> extends infer Result extends number ? TupleMax<[Absolute<A>, Absolute<B>]> extends infer Max_ extends number ? Max_ extends A | B // The larger absolute value is positive, so the result is positive
|
|
2428
|
+
? Result // The larger absolute value is negative, so the result is negative
|
|
2429
|
+
: ReverseSign<Result> : never : never;
|
|
2430
|
+
/**
|
|
2431
|
+
Adds two positive numbers.
|
|
2432
|
+
*/
|
|
2433
|
+
type SumPositives<A extends number, B extends number> = [...TupleOf<A>, ...TupleOf<B>]['length'] extends infer Result extends number ? Result : never;
|
|
2434
|
+
//#endregion
|
|
2435
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/exclude-exactly.d.ts
|
|
2436
|
+
/**
|
|
2437
|
+
A stricter version of `Exclude<T, U>` that excludes types only when they are exactly identical.
|
|
2438
|
+
|
|
2439
|
+
@example
|
|
2440
|
+
```
|
|
2441
|
+
import type {ExcludeExactly} from 'type-fest';
|
|
2442
|
+
|
|
2443
|
+
type TestExclude1 = Exclude<'a' | 'b' | 'c' | 1 | 2 | 3, string>;
|
|
2444
|
+
//=> 1 | 2 | 3
|
|
2445
|
+
|
|
2446
|
+
type TestExcludeExactly1 = ExcludeExactly<'a' | 'b' | 'c' | 1 | 2 | 3, string>;
|
|
2447
|
+
//=> 'a' | 'b' | 'c' | 1 | 2 | 3
|
|
2448
|
+
|
|
2449
|
+
type TestExclude2 = Exclude<'a' | 'b' | 'c' | 1 | 2 | 3, any>;
|
|
2450
|
+
//=> never
|
|
2451
|
+
|
|
2452
|
+
type TestExcludeExactly2 = ExcludeExactly<'a' | 'b' | 'c' | 1 | 2 | 3, any>;
|
|
2453
|
+
//=> 'a' | 'b' | 'c' | 1 | 2 | 3
|
|
2454
|
+
|
|
2455
|
+
type TestExclude3 = Exclude<{a: string} | {a: string; b: string}, {a: string}>;
|
|
2456
|
+
//=> never
|
|
2457
|
+
|
|
2458
|
+
type TestExcludeExactly3 = ExcludeExactly<{a: string} | {a: string; b: string}, {a: string}>;
|
|
2459
|
+
//=> {a: string; b: string}
|
|
2460
|
+
```
|
|
2461
|
+
|
|
2462
|
+
@category Improved Built-in
|
|
2463
|
+
*/
|
|
2464
|
+
type ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Union, _ExcludeExactly<Union, Delete>, // If `Union` is `any`, then if `Delete` is `any`, return `never`, else return `Union`.
|
|
2465
|
+
If<IsAny<Delete>, never, Union>, // If `Union` is `never`, then if `Delete` is `never`, return `never`, else return `Union`.
|
|
2466
|
+
If<IsNever<Delete>, never, Union>>;
|
|
2467
|
+
type _ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Delete, Union extends unknown // For distributing `Union`
|
|
2468
|
+
? [Delete extends unknown // For distributing `Delete`
|
|
2469
|
+
? If<IsEqual<Union, Delete>, true, never> : never] extends [never] ? Union : never : never, // If `Delete` is `any` or `never`, then return `Union`,
|
|
2470
|
+
// because `Union` cannot be `any` or `never` here.
|
|
2471
|
+
Union, Union>;
|
|
2472
|
+
//#endregion
|
|
2473
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/union-member.d.ts
|
|
2474
|
+
/**
|
|
2475
|
+
Returns an arbitrary member of a union type.
|
|
2476
|
+
|
|
2477
|
+
Use-cases:
|
|
2478
|
+
- Implementing recursive type functions that accept a union type.
|
|
2479
|
+
|
|
2480
|
+
@example
|
|
2481
|
+
```
|
|
2482
|
+
import type {UnionMember, IsNever} from 'type-fest';
|
|
2483
|
+
|
|
2484
|
+
type UnionLength<T, Acc extends any[] = []> =
|
|
2485
|
+
UnionMember<T> extends infer Member
|
|
2486
|
+
? IsNever<Member> extends false
|
|
2487
|
+
? UnionLength<Exclude<T, Member>, [...Acc, Member]>
|
|
2488
|
+
: Acc['length']
|
|
2489
|
+
: never;
|
|
2490
|
+
|
|
2491
|
+
type T1 = UnionLength<'foo' | 'bar' | 'baz'>;
|
|
2492
|
+
//=> 3
|
|
2493
|
+
|
|
2494
|
+
type T2 = UnionLength<{a: string}>;
|
|
2495
|
+
//=> 1
|
|
2496
|
+
```
|
|
2497
|
+
|
|
2498
|
+
- Picking an arbitrary member from a union
|
|
2499
|
+
|
|
2500
|
+
@example
|
|
2501
|
+
```
|
|
2502
|
+
import type {UnionMember, Primitive, LiteralToPrimitive} from 'type-fest';
|
|
2503
|
+
|
|
2504
|
+
type IsHomogenous<T extends Primitive> = [T] extends [LiteralToPrimitive<UnionMember<T>>] ? true : false;
|
|
2505
|
+
|
|
2506
|
+
type T1 = IsHomogenous<1 | 2 | 3 | 4>;
|
|
2507
|
+
//=> true
|
|
2508
|
+
|
|
2509
|
+
type T2 = IsHomogenous<'foo' | 'bar'>;
|
|
2510
|
+
//=> true
|
|
2511
|
+
|
|
2512
|
+
type T3 = IsHomogenous<'foo' | 'bar' | 1>;
|
|
2513
|
+
//=> false
|
|
2514
|
+
```
|
|
2515
|
+
|
|
2516
|
+
Returns `never` when the input is `never`.
|
|
2517
|
+
|
|
2518
|
+
@example
|
|
2519
|
+
```
|
|
2520
|
+
import type {UnionMember} from 'type-fest';
|
|
2521
|
+
|
|
2522
|
+
type LastNever = UnionMember<never>;
|
|
2523
|
+
//=> never
|
|
2524
|
+
```
|
|
2525
|
+
|
|
2526
|
+
@category Type
|
|
2527
|
+
*/
|
|
2528
|
+
type UnionMember<T> = IsNever<T> extends true ? never : UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
2529
|
+
//#endregion
|
|
2530
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
2531
|
+
/**
|
|
2532
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
2533
|
+
|
|
2534
|
+
"Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
|
|
2535
|
+
|
|
2536
|
+
This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
|
|
2537
|
+
|
|
2538
|
+
@example
|
|
2539
|
+
```
|
|
2540
|
+
import type {UnionToTuple} from 'type-fest';
|
|
2541
|
+
|
|
2542
|
+
type Numbers = 1 | 2 | 3;
|
|
2543
|
+
type NumbersTuple = UnionToTuple<Numbers>;
|
|
2544
|
+
//=> [1, 2, 3]
|
|
2545
|
+
```
|
|
2546
|
+
|
|
2547
|
+
@example
|
|
2548
|
+
```
|
|
2549
|
+
import type {UnionToTuple} from 'type-fest';
|
|
2550
|
+
|
|
2551
|
+
const pets = {
|
|
2552
|
+
dog: '🐶',
|
|
2553
|
+
cat: '🐱',
|
|
2554
|
+
snake: '🐍',
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
type Pet = keyof typeof pets;
|
|
2558
|
+
//=> 'dog' | 'cat' | 'snake'
|
|
2559
|
+
|
|
2560
|
+
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
2561
|
+
//=> ['dog', 'cat', 'snake']
|
|
2562
|
+
```
|
|
2563
|
+
|
|
2564
|
+
@category Array
|
|
2565
|
+
*/
|
|
2566
|
+
type UnionToTuple<Union> = _UnionToTuple<Union> extends infer Result extends UnknownArray ? Result : never;
|
|
2567
|
+
// Nudges the compiler that `UnionToTuple` always yields an array.
|
|
2568
|
+
type _UnionToTuple<Union, Accumulator extends UnknownArray = [], Member = UnionMember<Union>> = IsNever<Union> extends true ? Accumulator : _UnionToTuple<ExcludeExactly<Union, Member>, [Member, ...Accumulator]>;
|
|
2569
|
+
//#endregion
|
|
2570
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/int-range.d.ts
|
|
2571
|
+
/**
|
|
2572
|
+
Generate a union of numbers between a specified start (inclusive) and end (exclusive), with an optional step.
|
|
2573
|
+
|
|
2574
|
+
You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8`.
|
|
2575
|
+
|
|
2576
|
+
Note: `Start` or `End` must be non-negative and smaller than `1000`.
|
|
2577
|
+
|
|
2578
|
+
Use-cases:
|
|
2579
|
+
1. This can be used to define a set of valid input/output values. for example:
|
|
2580
|
+
|
|
2581
|
+
@example
|
|
2582
|
+
```
|
|
2583
|
+
import type {IntRange} from 'type-fest';
|
|
2584
|
+
|
|
2585
|
+
type Age = IntRange<0, 20>;
|
|
2586
|
+
//=> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
|
|
2587
|
+
|
|
2588
|
+
type FontSize = IntRange<10, 20>;
|
|
2589
|
+
//=> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
|
|
2590
|
+
|
|
2591
|
+
type EvenNumber = IntRange<0, 11, 2>;
|
|
2592
|
+
//=> 0 | 2 | 4 | 6 | 8 | 10
|
|
2593
|
+
```
|
|
2594
|
+
|
|
2595
|
+
2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntRange<0, 100>;`
|
|
2596
|
+
|
|
2597
|
+
@example
|
|
2598
|
+
```
|
|
2599
|
+
import type {IntRange} from 'type-fest';
|
|
2600
|
+
|
|
2601
|
+
type ZeroToNine = IntRange<0, 10>;
|
|
2602
|
+
//=> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
2603
|
+
|
|
2604
|
+
type Hundreds = IntRange<100, 901, 100>;
|
|
2605
|
+
//=> 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
|
2606
|
+
```
|
|
2607
|
+
|
|
2608
|
+
@see {@link IntClosedRange}
|
|
2609
|
+
*/
|
|
2610
|
+
type IntRange<Start extends number, End extends number, Step extends number = 1> = PrivateIntRange<Start, End, Step>;
|
|
2611
|
+
/**
|
|
2612
|
+
The actual implementation of `IntRange`. It's private because it has some arguments that don't need to be exposed.
|
|
2613
|
+
*/
|
|
2614
|
+
type PrivateIntRange<Start extends number, End extends number, Step extends number, // The gap between each number, gap = step - 1
|
|
2615
|
+
Gap extends number = Subtract<Step, 1>, // The final `List` is `[...StartLengthTuple, ...[number, ...GapLengthTuple], ...[number, ...GapLengthTuple], ... ...]`, so can initialize the `List` with `[...StartLengthTuple]`
|
|
2616
|
+
List extends unknown[] = TupleOf<Start, never>, EndLengthTuple extends unknown[] = TupleOf<End>> = Gap extends 0 // Handle the case that without `Step`
|
|
2617
|
+
? List['length'] extends End // The result of "List[length] === End"
|
|
2618
|
+
? Exclude<List[number], never> // All unused elements are `never`, so exclude them
|
|
2619
|
+
: PrivateIntRange<Start, End, Step, Gap, [...List, List['length']]> // Handle the case that with `Step`
|
|
2620
|
+
: List extends [...(infer U), ...EndLengthTuple] // The result of "List[length] >= End", because the `...TupleOf<Gap, never>` maybe make `List` too long.
|
|
2621
|
+
? Exclude<List[number], never> : PrivateIntRange<Start, End, Step, Gap, [...List, List['length'], ...TupleOf<Gap, never>]>;
|
|
2622
|
+
//#endregion
|
|
2623
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/int-closed-range.d.ts
|
|
2624
|
+
/**
|
|
2625
|
+
Generate a union of numbers between a specified start and end (both inclusive), with an optional step.
|
|
2626
|
+
|
|
2627
|
+
You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntClosedRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8 | 10`.
|
|
2628
|
+
|
|
2629
|
+
Note: `Start` or `End` must be non-negative and smaller than `999`.
|
|
2630
|
+
|
|
2631
|
+
Use-cases:
|
|
2632
|
+
1. This can be used to define a set of valid input/output values. for example:
|
|
2633
|
+
|
|
2634
|
+
@example
|
|
2635
|
+
```
|
|
2636
|
+
import type {IntClosedRange} from 'type-fest';
|
|
2637
|
+
|
|
2638
|
+
type Age = IntClosedRange<0, 20>;
|
|
2639
|
+
//=> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
|
|
2640
|
+
|
|
2641
|
+
type FontSize = IntClosedRange<10, 20>;
|
|
2642
|
+
//=> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
|
|
2643
|
+
|
|
2644
|
+
type EvenNumber = IntClosedRange<0, 10, 2>;
|
|
2645
|
+
//=> 0 | 2 | 4 | 6 | 8 | 10
|
|
2646
|
+
```
|
|
2647
|
+
|
|
2648
|
+
2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntClosedRange<0, 100>;`
|
|
2649
|
+
|
|
2650
|
+
@example
|
|
2651
|
+
```
|
|
2652
|
+
import type {IntClosedRange} from 'type-fest';
|
|
2653
|
+
|
|
2654
|
+
type ZeroToNine = IntClosedRange<0, 9>;
|
|
2655
|
+
//=> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
2656
|
+
|
|
2657
|
+
type Hundreds = IntClosedRange<100, 900, 100>;
|
|
2658
|
+
//=> 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
|
2659
|
+
```
|
|
2660
|
+
|
|
2661
|
+
@see {@link IntRange}
|
|
2662
|
+
*/
|
|
2663
|
+
type IntClosedRange<Start extends number, End extends number, Skip extends number = 1> = IntRange<Start, Sum<End, 1>, Skip>;
|
|
2664
|
+
//#endregion
|
|
2665
|
+
//#region src/Lifecycle/LifecycleTypes.d.ts
|
|
2666
|
+
/** Actions that can occur during lifecycle phases */
|
|
2667
|
+
type LifecycleAction = 'start' | 'complete' | 'error';
|
|
2668
|
+
/**
|
|
2669
|
+
* Creates event names for lifecycle managers with phase numbers and actions
|
|
2670
|
+
* @typeParam Prefix - The prefix string for lifecycle events
|
|
2671
|
+
* @typeParam Phases - Array of phase numbers to generate events for
|
|
2672
|
+
*/
|
|
2673
|
+
type PhaseEvents<Prefix extends string, Phases extends number[]> = `phase:${IntClosedRange<1, Phases['length']>}:${TypedExclude<LifecycleAction, 'error'>}` | `${Prefix}:${LifecycleAction}`;
|
|
2674
|
+
/**
|
|
2675
|
+
* Strict-event-emitter payload map for a lifecycle: phase + prefix `start`/`complete` events
|
|
2676
|
+
* carry no payload; the `${Prefix}:error` event carries the thrown error.
|
|
2677
|
+
* @typeParam Prefix - The prefix string for lifecycle events
|
|
2678
|
+
* @typeParam Phases - Array of phase numbers to generate events for
|
|
2679
|
+
*/
|
|
2680
|
+
type PhaseEventMap<Prefix extends string, Phases extends number[]> = { [K in PhaseEvents<Prefix, Phases>]: K extends `${string}:error` ? readonly [error: unknown] : readonly [] };
|
|
2681
|
+
/** Base interface for a lifecycle task */
|
|
2682
|
+
interface LifecycleTask {
|
|
2683
|
+
/** Name of the task */
|
|
2684
|
+
name: string;
|
|
2685
|
+
/** Function to execute the task */
|
|
2686
|
+
task: () => Promise<void>;
|
|
2687
|
+
/** Timeout for the task */
|
|
2688
|
+
timeout: number;
|
|
2689
|
+
}
|
|
2690
|
+
//#endregion
|
|
2691
|
+
//#region src/Lifecycle/CoordinatedLifecycle.d.ts
|
|
2692
|
+
/**
|
|
2693
|
+
* Abstract base class for coordinated lifecycle management (startup/shutdown)
|
|
2694
|
+
*/
|
|
2695
|
+
declare abstract class CoordinatedLifecycle<TPhase extends number, TEvents extends SEEventMapLike<TEvents>> extends StrictEventEmitter<TEvents> {
|
|
2696
|
+
protected readonly phaseOrder: TPhase[];
|
|
2697
|
+
protected readonly phaseEnum: Record<number, string>;
|
|
2698
|
+
protected readonly logger: Logger;
|
|
2699
|
+
protected readonly tasksMap: Map<TPhase, LifecycleTask[]>;
|
|
2700
|
+
protected constructor(loggerName: string, phaseOrder: TPhase[], phaseEnum: Record<number, string>);
|
|
2701
|
+
/**
|
|
2702
|
+
* Adds a lifecycle task to a specific phase.
|
|
2703
|
+
*
|
|
2704
|
+
* Tasks are executed in phase order during lifecycle operations.
|
|
2705
|
+
* Each task has a timeout to prevent hanging operations.
|
|
2706
|
+
*
|
|
2707
|
+
* @param phase - The lifecycle phase to add the task to
|
|
2708
|
+
* @param taskName - Unique name for the task (used for logging and removal)
|
|
2709
|
+
* @param task - Async function to execute during the phase
|
|
2710
|
+
* @param timeoutMs - Maximum time allowed for task execution in milliseconds
|
|
2711
|
+
* @example
|
|
2712
|
+
* ```typescript
|
|
2713
|
+
* lifecycle.addTask(StartupPhase.Services, 'start-database', async () => {
|
|
2714
|
+
* await database.connect();
|
|
2715
|
+
* }, 10000);
|
|
2716
|
+
* ```
|
|
2717
|
+
*/
|
|
2718
|
+
addTask(phase: TPhase, taskName: string, task: () => Promise<void>, timeoutMs: number): void;
|
|
2719
|
+
/**
|
|
2720
|
+
* Removes a lifecycle task from a specific phase.
|
|
2721
|
+
*
|
|
2722
|
+
* @param phase - The lifecycle phase to remove the task from
|
|
2723
|
+
* @param taskName - Name of the task to remove
|
|
2724
|
+
* @returns True if the task was found and removed, false otherwise
|
|
2725
|
+
*/
|
|
2726
|
+
removeTask(phase: TPhase, taskName: string): boolean;
|
|
2727
|
+
/**
|
|
2728
|
+
* Run all tasks in a specific phase
|
|
2729
|
+
*/
|
|
2730
|
+
protected runPhase(phase: TPhase): Promise<void>;
|
|
2731
|
+
/**
|
|
2732
|
+
* Run a single task with timeout
|
|
2733
|
+
*/
|
|
2734
|
+
protected runTaskWithTimeout(phase: TPhase, task: LifecycleTask): Promise<void>;
|
|
2735
|
+
private emitPhase;
|
|
2736
|
+
protected abstract canAddTask(): boolean;
|
|
2737
|
+
protected abstract canRemoveTask(): boolean;
|
|
2738
|
+
protected abstract getTaskType(): string;
|
|
2739
|
+
protected abstract executeTasksInPhase(phase: TPhase, tasks: LifecycleTask[]): Promise<PromiseSettledResult<void>[]>;
|
|
2740
|
+
}
|
|
2741
|
+
//#endregion
|
|
2742
|
+
//#region src/Lifecycle/CoordinatedShutdown.d.ts
|
|
2743
|
+
/**
|
|
2744
|
+
* Shutdown phases for coordinated application shutdown.
|
|
2745
|
+
*/
|
|
2746
|
+
declare enum ShutdownPhase {
|
|
2747
|
+
/** Stop accepting new requests/interactions */
|
|
2748
|
+
StopAcceptingRequests = 1,
|
|
2749
|
+
/** Stop background services (health checks, etc.) */
|
|
2750
|
+
StopServices = 2,
|
|
2751
|
+
/** Disconnect from external resources (database, APIs) */
|
|
2752
|
+
ExternalResources = 3,
|
|
2753
|
+
/** Disconnect from Discord */
|
|
2754
|
+
DiscordCleanup = 4,
|
|
2755
|
+
/** Final cleanup tasks */
|
|
2756
|
+
FinalCleanup = 5
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Strict-event-emitter payload map for coordinated shutdown phases.
|
|
2760
|
+
*/
|
|
2761
|
+
type CoordinatedShutdownEvents = PhaseEventMap<'shutdown', UnionToTuple<ShutdownPhase>>;
|
|
2762
|
+
/**
|
|
2763
|
+
* CoordinatedShutdown manages graceful application shutdown by executing registered tasks across defined phases.
|
|
2764
|
+
*
|
|
2765
|
+
* It listens for termination signals (SIGINT, SIGTERM) and runs tasks in parallel within each phase.
|
|
2766
|
+
* Tasks can be added or removed dynamically, and each task has an associated timeout.
|
|
2767
|
+
*/
|
|
2768
|
+
declare class CoordinatedShutdown extends CoordinatedLifecycle<ShutdownPhase, CoordinatedShutdownEvents> {
|
|
2769
|
+
private readonly isShutdownEnabled;
|
|
2770
|
+
private isShuttingDown;
|
|
2771
|
+
private exitCode;
|
|
2772
|
+
private onSigTerm;
|
|
2773
|
+
private onSigInt;
|
|
2774
|
+
constructor(enabled?: boolean);
|
|
2775
|
+
protected canAddTask(): boolean;
|
|
2776
|
+
protected canRemoveTask(): boolean;
|
|
2777
|
+
protected getTaskType(): string;
|
|
2778
|
+
protected executeTasksInPhase(phase: ShutdownPhase, tasks: LifecycleTask[]): Promise<PromiseSettledResult<void>[]>;
|
|
2779
|
+
private registerSignalHandlers;
|
|
2780
|
+
private removeSignalHandlers;
|
|
2781
|
+
/**
|
|
2782
|
+
* Adds a task to a specific shutdown phase with timeout.
|
|
2783
|
+
*
|
|
2784
|
+
* @param phase - The shutdown phase from {@link ShutdownPhase}
|
|
2785
|
+
* @param taskName - Unique identifier for the task
|
|
2786
|
+
* @param task - Async function to execute
|
|
2787
|
+
* @param timeoutMs - Task timeout in milliseconds {@default 5000}
|
|
2788
|
+
*/
|
|
2789
|
+
addTask(phase: ShutdownPhase, taskName: string, task: () => Promise<void>, timeoutMs?: number): void;
|
|
2790
|
+
/**
|
|
2791
|
+
* Removes a task from a specific shutdown phase.
|
|
2792
|
+
*
|
|
2793
|
+
* @param phase - The shutdown phase to remove from
|
|
2794
|
+
* @param taskName - Name of the task to remove
|
|
2795
|
+
* @returns True if task was found and removed
|
|
2796
|
+
*/
|
|
2797
|
+
removeTask(phase: ShutdownPhase, taskName: string): boolean;
|
|
2798
|
+
/**
|
|
2799
|
+
* Executes the coordinated shutdown sequence.
|
|
2800
|
+
*
|
|
2801
|
+
* Runs all registered tasks across shutdown phases in reverse order.
|
|
2802
|
+
* Tasks within each phase are executed in parallel for faster shutdown.
|
|
2803
|
+
* Process exits with the specified code when complete.
|
|
2804
|
+
*
|
|
2805
|
+
* @param exitCode - Process exit code {@default 0}
|
|
2806
|
+
* @param exitProcess - Whether to exit the process after shutdown {@default true}
|
|
2807
|
+
* @returns Promise that resolves when shutdown is complete
|
|
2808
|
+
* @example
|
|
2809
|
+
* ```typescript
|
|
2810
|
+
* shutdown.addTask(ShutdownPhase.Services, 'database', () => db.disconnect(), 5000);
|
|
2811
|
+
* await shutdown.run(0); // Graceful shutdown
|
|
2812
|
+
* ```
|
|
2813
|
+
*/
|
|
2814
|
+
run(exitCode?: number, exitProcess?: boolean): Promise<void>;
|
|
2815
|
+
}
|
|
2816
|
+
//#endregion
|
|
2817
|
+
//#region src/HealthCheck.d.ts
|
|
2818
|
+
/**
|
|
2819
|
+
* HTTP health check service for monitoring bot status.
|
|
2820
|
+
*
|
|
2821
|
+
* Provides a simple HTTP endpoint that responds with JSON status
|
|
2822
|
+
* information, useful for container orchestration and monitoring.
|
|
2823
|
+
*/
|
|
2824
|
+
declare class HealthCheck {
|
|
2825
|
+
readonly logger: Logger;
|
|
2826
|
+
readonly port: number;
|
|
2827
|
+
readonly path: string;
|
|
2828
|
+
readonly host: string | undefined;
|
|
2829
|
+
private server?;
|
|
2830
|
+
constructor(shutdown: CoordinatedShutdown, options?: HealthCheckConfig);
|
|
2831
|
+
/**
|
|
2832
|
+
* Starts the health check server.
|
|
2833
|
+
* @returns Promise that resolves when the server is listening
|
|
2834
|
+
*/
|
|
2835
|
+
init(): Promise<void>;
|
|
2836
|
+
/**
|
|
2837
|
+
* Stops the health check server.
|
|
2838
|
+
*
|
|
2839
|
+
* @returns Promise that resolves when the server is closed
|
|
2840
|
+
*/
|
|
2841
|
+
stop(): Promise<void>;
|
|
2842
|
+
}
|
|
2843
|
+
//#endregion
|
|
2844
|
+
//#region src/Lifecycle/CoordinatedStartup.d.ts
|
|
2845
|
+
/**
|
|
2846
|
+
* Startup phases for coordinated initialization
|
|
2847
|
+
*
|
|
2848
|
+
* Defines the order in which different components are initialized during bot startup.
|
|
2849
|
+
*/
|
|
2850
|
+
declare enum StartupPhase {
|
|
2851
|
+
/** Validate environment variables and config files */
|
|
2852
|
+
Validation = 1,
|
|
2853
|
+
/** Discover plugin constructors via decorators or registry */
|
|
2854
|
+
Discovery = 2,
|
|
2855
|
+
/** Register plugin metadata and declared dependencies */
|
|
2856
|
+
Registration = 3,
|
|
2857
|
+
/** Inject and validate plugin-specific configuration */
|
|
2858
|
+
Configuration = 4,
|
|
2859
|
+
/** Instantiate plugin classes with Core and arguments */
|
|
2860
|
+
Instantiation = 5,
|
|
2861
|
+
/** Activate plugins by calling their init/setup methods */
|
|
2862
|
+
Activation = 6,
|
|
2863
|
+
/** Mark seedcord as ready and start handling interactions */
|
|
2864
|
+
Ready = 7
|
|
2865
|
+
}
|
|
2866
|
+
/**
|
|
2867
|
+
* Strict-event-emitter payload map for coordinated startup phases.
|
|
2868
|
+
*/
|
|
2869
|
+
type CoordinatedStartupEvents = PhaseEventMap<'startup', UnionToTuple<StartupPhase>>;
|
|
2870
|
+
/**
|
|
2871
|
+
* Manages bot startup lifecycle with ordered phases
|
|
2872
|
+
*
|
|
2873
|
+
* Coordinates initialization of all bot components in a predictable sequence.
|
|
2874
|
+
* Tasks are executed within their designated phases to ensure proper dependency order.
|
|
2875
|
+
*/
|
|
2876
|
+
declare class CoordinatedStartup extends CoordinatedLifecycle<StartupPhase, CoordinatedStartupEvents> {
|
|
2877
|
+
private isStartingUp;
|
|
2878
|
+
private hasStarted;
|
|
2879
|
+
constructor();
|
|
2880
|
+
/**
|
|
2881
|
+
* Adds a task to a specific startup phase with timeout.
|
|
2882
|
+
*
|
|
2883
|
+
* @param phase - The startup phase from {@link StartupPhase}
|
|
2884
|
+
* @param taskName - Unique identifier for the task
|
|
2885
|
+
* @param task - Async function to execute
|
|
2886
|
+
* @param timeoutMs - Task timeout in milliseconds {@default 10000}
|
|
2887
|
+
*/
|
|
2888
|
+
addTask(phase: StartupPhase, taskName: string, task: () => Promise<void>, timeoutMs?: number): void;
|
|
2889
|
+
protected canAddTask(): boolean;
|
|
2890
|
+
protected canRemoveTask(): boolean;
|
|
2891
|
+
protected getTaskType(): string;
|
|
2892
|
+
protected executeTasksInPhase(phase: StartupPhase, tasks: LifecycleTask[]): Promise<PromiseSettledResult<void>[]>;
|
|
2893
|
+
/**
|
|
2894
|
+
* Executes the coordinated startup sequence.
|
|
2895
|
+
*
|
|
2896
|
+
* Runs all registered tasks across startup phases in the correct order.
|
|
2897
|
+
* Each phase completes before the next phase begins. Tasks within a phase
|
|
2898
|
+
* are executed sequentially to maintain predictable initialization.
|
|
2899
|
+
*
|
|
2900
|
+
* @returns Promise that resolves when startup is complete
|
|
2901
|
+
* @throws An {@link Error} If startup fails or is called multiple times
|
|
2902
|
+
* @example
|
|
2903
|
+
* ```typescript
|
|
2904
|
+
* const startup = new CoordinatedStartup();
|
|
2905
|
+
* startup.addTask(StartupPhase.Services, 'database', () => db.connect(), 10000);
|
|
2906
|
+
* await startup.run();
|
|
2907
|
+
* ```
|
|
2908
|
+
*/
|
|
2909
|
+
run(): Promise<void>;
|
|
2910
|
+
protected runTaskWithTimeout(phase: StartupPhase, task: LifecycleTask): Promise<void>;
|
|
2911
|
+
/**
|
|
2912
|
+
* Aborts the startup sequence if it is currently running.
|
|
2913
|
+
*/
|
|
2914
|
+
abort(): void;
|
|
2915
|
+
/**
|
|
2916
|
+
* Check if startup has completed
|
|
2917
|
+
*/
|
|
2918
|
+
get isReady(): boolean;
|
|
2919
|
+
/**
|
|
2920
|
+
* Check if startup is currently running
|
|
2921
|
+
*/
|
|
2922
|
+
get isRunning(): boolean;
|
|
2923
|
+
}
|
|
2924
|
+
//#endregion
|
|
2925
|
+
//#region src/index.d.ts
|
|
2926
|
+
/** Package version */
|
|
2927
|
+
declare const version: string;
|
|
2928
|
+
//#endregion
|
|
2929
|
+
export { type BaseSeedcordError, type BaseTransportConfig, type ChannelConfig, type ConsoleTransportConfig, CooldownManager, CooldownOptions, CoordinatedLifecycle, CoordinatedShutdown, CoordinatedShutdownEvents, CoordinatedStartup, CoordinatedStartupEvents, type FileTransportConfig, HealthCheck, type ILoggerSink, type ILoggerSinkHandle, type LifecycleTask, Logger, LoggerChannelRegistry, type LoggerConfiguration, type LoggerFileConfig, type LoggerFilePatternsConfig, type LoggerFormatMode, type LoggerLevel, type LoggerOptions, type LoggerSinkLogEntry, LoggerUtilities, SEArgsTuple, SEEventMapLike, SENoEvents, SeedcordErrorCode, type SeedcordErrorTypeString, ShutdownPhase, StartupPhase, type StreamTransportConfig, StrictEventEmitter, type TransportConfig, isSeedcordError, version };
|
|
2930
|
+
//# sourceMappingURL=index.d.mts.map
|