This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.d.ts
846 lines (740 loc) · 33.3 KB
/
global.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
/// <reference path="./@types">
declare module 'erfdb' {
/**
* Represents a database for storing key-value pairs with various utility methods.
* @template V The type of values stored in the database. Defaults to any.
*/
export class Database<V = any> {
protected readonly options: _DatabaseOptions<V>;
/**
* Creates an instance of Database.
* @param options - The options to configure the database.
*/
public constructor(options?: DatabaseOptions<V>);
/**
* Iterates over the entries in the database.
* @yields {[string, V]} The key-value pairs in the database.
*/
[Symbol.iterator](): Iterator<[string, V]>;
/**
* Gets the size of the database.
* @returns {number} The number of entries in the database.
*/
public get size(): number;
/**
* Gets whether the database is empty.
* @returns {boolean} True if database has no entries, false otherwise.
*/
public get isEmpty(): boolean;
/**
* Retrieves all entries in the database.
* @param {number} amount - The maximum number of entries to retrieve. Defaults to 0 (retrieve all).
* @returns {Set<{key: string, value: V}>} A Set of key-value pairs.
*/
public all(amount?: number): Set<{ key: string, value: V }>;
/**
* Retrieves the key or value at the specified pattern.
* @param {string} pattern - The pattern specifying whether to retrieve a key or value (format: "key:index" or "value:index").
* @returns {string | V | undefined} The key or value at the specified pattern, or undefined if not found.
* @throws {Error} If pattern is invalid or index is out of bounds.
*/
public at(pattern: string): string | V | undefined;
/**
* Creates a clone of the database.
* @param {boolean} contents - Whether to clone the contents (default: true).
* @returns {Database<V>} A new database instance with the same entries.
*/
public clone(contents?: boolean): Database<V>;
/**
* Concatenates multiple databases into one.
* @param {...Database<V>[]} databases - The databases to concatenate.
* @returns {Database<V>} A new database instance with combined entries.
* @throws {Error} If any argument is not a Database instance.
*/
public concat(...databases: Database<V>[]): Database<V>;
/**
* Deletes an entry by key.
* @param {string} key - The key of the entry to delete.
* @returns {boolean} True if the entry was deleted, false otherwise.
*/
public del(key: string): boolean;
/**
* Deletes multiple entries by keys.
* @param {...string[]} keys - The keys of entries to delete.
* @returns {number} Number of entries deleted.
*/
public deleteMany(...keys: string[]): number;
/**
* Deletes the database file associated with the driver if it exists.
* @returns {boolean} True if the database file was successfully deleted, false otherwise.
*/
public destroy(): boolean;
/**
* Iterates over each entry in the database and calls the provided callback.
* @param {Function} callback - The function to call for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {this} The database instance.
*/
public each(callback: (value: V, index: number, key: string, Database: this) => void): this;
/**
* Checks if every entry in the database satisfies the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {boolean} True if every entry satisfies the callback, false otherwise.
*/
public every(callback: (value: V, key: string, Database: this) => boolean): boolean;
/**
* Retrieves the first entry in the database.
* @returns {{key: string, value: V} | {}} The first key-value pair, or empty object if the database is empty.
*/
public first(): { key: string; value: V; } | {};
/**
* Filters the database based on the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {Database<V>} A new database instance with the filtered entries.
*/
public filter(callback: (value: V, index: number, key: string, Database: this) => boolean): Database<V>;
/**
* Finds the first entry that satisfies the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {{key: string, value: V, index: number} | undefined} The first entry that satisfies the callback, or undefined if none found.
*/
public find(callback: (value: V, index: number, key: string, Database: this) => boolean): { key: string, value: V, index: number } | undefined;
/**
* Finds all entries that satisfy the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {Array<{key: string, value: V, index: number}>} Array of matching entries.
*/
public findAll(callback: (value: V, index: number, key: string, Database: this) => boolean): { key: string, value: V, index: number }[];
/**
* Gets multiple values by their keys.
* @param {...string[]} keys - The keys to retrieve values for.
* @returns {Array<V | undefined>} Array of values in same order as keys.
*/
public getMany(...keys: string[]): (V | undefined)[];
/**
* Gets the value associated with the given key.
* @param {string} key - The key of the entry to retrieve.
* @returns {V | undefined} The value associated with the key, or undefined if not found.
*/
public get(key: string): V | undefined;
/**
* Checks if an entry with the given key exists.
* @param {string} key - The key to check.
* @returns {boolean} True if the entry exists, false otherwise.
*/
public has(key: string): boolean;
/**
* Checks if multiple keys exist in the database.
* @param {...string[]} keys - The keys to check.
* @returns {boolean} True if all keys exist, false otherwise.
*/
public hasAll(...keys: string[]): boolean;
/**
* Checks if any of the given keys exist in the database.
* @param {...string[]} keys - The keys to check.
* @returns {boolean} True if at least one key exists, false otherwise.
*/
public hasAny(...keys: string[]): boolean;
/**
* Returns the index of the given key.
* @param {string} key - The key to find the index of.
* @returns {number} The index of the key, or -1 if not found.
*/
public indexOf(key: string): number;
/**
* Creates a new database with the intersection of entries from the current database and another database.
* @param {Database<V>} other - The other database to intersect with.
* @returns {Database<V>} A new database instance with the intersected entries.
* @throws {Error} If other is not a Database instance.
*/
public intersection(other: Database<V>): Database<V>;
/**
* Retrieves the key associated with the given value.
* @param {V} value - The value to find the key for.
* @returns {string | undefined} The key associated with the value, or undefined if not found.
*/
public keyOf(value: V): string | undefined;
/**
* Retrieves all keys associated with the given value.
* @param {V} value - The value to find keys for.
* @returns {string[]} Array of keys associated with the value.
*/
public keysOf(value: V): string[];
/**
* Retrieves the last entry in the database.
* @returns {{key: string, value: V} | {}} The last key-value pair, or empty object if the database is empty.
*/
public last(): { key: string; value: V; } | {};
/**
* Performs mathematical operations on a numeric value stored in the cache.
* @param {string} key - The key of the numeric value in the cache.
* @param {MathOperators} operator - The mathematical operator ('+', '-', '*', '**', '%', '/').
* @param {number} [count=1] - The operand for the mathematical operation.
* @param {boolean} [negative=false] - Whether to allow negative results.
* @returns {number} The result of the mathematical operation.
* @throws {TypeError} If the operator is invalid or value is not a number.
* @throws {RangeError} If attempting to perform an invalid mathematical operation.
*/
public math(key: string, operator: MathOperators, count?: number, negative?: boolean): number;
/**
* Creates a new database with entries that satisfy the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {Database<V>} A new database instance with the mapped entries.
*/
public map(callback: (value: V, index: number, key: string, Database: this) => boolean): Database<V>;
/**
* Merges another database into the current database.
* @param {Database<V>} other - The other database to merge.
* @returns {this} The current database instance.
* @throws {Error} If other is not a Database instance.
*/
public merge(other: Database<V>): this;
/**
* Partitions the database into two databases based on the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {[Database<V>, Database<V>]} A tuple containing two new database instances: one with entries that satisfy the callback and one with entries that do not.
*/
public partition(callback: (value: V, index: number, key: string, Database: this) => boolean): [Database<V>, Database<V>];
/**
* Pushes a value to an array at the specified key.
* @param {string} key - The key of the entry.
* @param {V} value - The value to push.
* @returns {V[]} The updated array after the push operation.
*/
public push(key: string, value: V): V[];
/**
* Pushes multiple values to an array at the specified key.
* @param {string} key - The key of the entry.
* @param {...V[]} values - The values to push.
* @returns {V[]} The updated array after the push operations.
*/
public pushMany(key: string, ...values: V[]): V[];
/**
* Pulls a value from an array at the specified key.
* @param {string} key - The key of the entry.
* @param {V} value - The value to pull.
* @returns {V[] | undefined} The updated array after the pull operation, or undefined if the key does not exist or is not an array.
*/
public pull(key: string, value: V): V[] | undefined;
/**
* Creates a new database with only the specified keys.
* @param {...string[]} keys - The keys to pick.
* @returns {Database<V>} A new database instance with the picked entries.
* @throws {Error} If keys is not an array.
*/
public pick(...keys: string[]): Database<V>;
/**
* Creates a random key that doesn't exist in the database.
* @param {number} [length=10] - Length of the key to generate.
* @returns {string} A unique random key.
*/
public randomKey(length?: number): string;
/**
* Reduces the entries in the database to a single value based on the provided callback and initial value.
* @param {Function} callback - The function to execute on each entry.
* @param {R} callback.accumulator - The accumulator value.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @param {R} initialValue - The initial value to start the reduction.
* @returns {R} The reduced value.
* @template R The type of the reduced value.
*/
public reduce<R>(callback: (accumulator: R, value: V, index: number, key: string, Database: this) => R, initialValue: R): R;
/**
* Sets a key-value pair in the database.
* @param {string} key - The key to set.
* @param {V} value - The value to associate with the key.
* @returns {V} The value that was set.
*/
public set(key: string, value: V): V;
/**
* Sets multiple key-value pairs in the database.
* @param {Record<string, V>} entries - Object containing key-value pairs to set.
* @returns {this} The database instance.
*/
public setMany(entries: Record<string, V>): this;
/**
* Creates a new database with a subset of entries based on the start and end indices.
* @param {number} [start=0] - The starting index.
* @param {number} [end=this.size] - The ending index.
* @returns {Database<V>} A new database instance with the sliced entries.
* @throws {Error} If start or end indices are invalid.
*/
public slice(start?: number, end?: number): Database<V>;
/**
* Checks if some entries in the database satisfy the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {number} callback.index - The index of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {boolean} True if at least one entry satisfies the callback, false otherwise.
*/
public some(callback: (value: V, index: number, key: string, Database: this) => boolean): boolean;
/**
* Sorts the database entries based on the provided callback.
* @param {Function} callback - The comparison function.
* @param {V} callback.a - First value to compare.
* @param {V} callback.b - Second value to compare.
* @returns {Database<V>} A new sorted database instance.
*/
public sort(callback: (a: V, b: V) => number): Database<V>;
/**
* Sweeps entries from the database based on the provided callback.
* @param {Function} callback - The function to test for each entry.
* @param {V} callback.value - The value of the current entry.
* @param {string} callback.key - The key of the current entry.
* @param {Database<V>} callback.Database - The database instance.
* @returns {number} The number of entries removed.
*/
public sweep(callback: (value: V, key: string, Database: this) => boolean): number;
/**
* Retrieves all keys and values as separate arrays.
* @returns {{keys: string[], values: V[]}} An object containing the keys and values arrays.
*/
public toArray(): { keys: string[], values: V[] };
/**
* Converts the cache to two Sets, one for keys and one for values.
* @returns {[Set<string>, Set<V>]} A tuple containing two Sets: one for keys and one for values.
*/
public toSet(): [Set<string>, Set<V>];
/**
* Retrieves all entries in the database as a JSON object.
* @returns {Record<string, V>} A JSON object containing all entries.
*/
public toJSON(): Record<string, V>;
/**
* Determines the type of the value associated with the specified key.
* @param {string} key - The key of the entry to check.
* @returns {string | undefined} The type of the value ('array' if the value is an array, or the result of the typeof operator).
* Returns undefined if the key does not exist.
*/
public typeOf(key: string): string | undefined;
/**
* Updates an existing entry with new data.
* @param {string} key - The key of the entry to update.
* @param {Function} updater - Function that receives the old value and returns the new value.
* @param {V} updater.oldValue - The current value associated with the key.
* @returns {V | undefined} The updated value, or undefined if key doesn't exist.
*/
public update(key: string, updater: (oldValue: V) => V): V | undefined;
/**
* Retrieves the value associated with the specified key.
* Alternative to get() function. Only difference is this function uses find() function.
* @param {string} key - The key of the entry to retrieve.
* @returns {V | undefined} The value associated with the specified key, or undefined if the key is not found.
*/
public valueOf(key: string): V | undefined;
/**
* Validates and checks the options for the database.
* @param {DatabaseOptions<T>} [options] - The options to validate and check.
* @returns {_DatabaseOptions<T>} The validated and checked options.
* @template T The type of values stored in the database.
*/
static checkOptions<T>(options?: DatabaseOptions<T>): _DatabaseOptions<T>;
}
/**
* MemoryDriver is a class that manages an in-memory cache with support for various operations
* such as setting, getting, deleting, and iterating over key-value pairs.
* @template V The type of values stored in the cache.
*/
export class MemoryDriver<V = any> {
protected readonly _cache: Map<string, V>;
protected readonly options: _MemoryDriverOptions;
private _size: number;
/**
* Creates an instance of MemoryDriver.
* @param {MemoryDriverOptions} [options={}] The options for the memory driver.
*/
public constructor(options?: MemoryDriverOptions);
protected read(): void;
protected write(): void;
public get cache(): Map<string, V>;
[Symbol.iterator](): IterableIterator<[string, V]>;
/**
* Gets the number of entries in the cache.
* @returns {number} The size of the cache.
*/
public get size(): number;
/**
* Sets a value in the cache.
* @param {string} key The key to set.
* @param {V} value The value to set.
* @returns {V} The set value.
*/
public set(key: string, value: V): V;
/**
* Sets multiple key-value pairs at once.
* @param {Array<[string, V]>} entries Array of key-value pairs
* @returns {this} The driver instance
*/
public setMany(entries: Array<[string, V]>): this;
/**
* Gets a value from the cache.
* @param {string} key The key to get.
* @returns {V | undefined} The value associated with the key, or undefined if the key does not exist.
*/
public get(key: string): V | undefined;
/**
* Gets multiple values at once.
* @param {string[]} keys Array of keys to get
* @returns {Array<V | undefined>} Array of values
*/
public getMany(keys: string[]): Array<V | undefined>;
/**
* Checks if a key exists in the cache.
* @param {string} key The key to check.
* @returns {boolean} True if the key exists, false otherwise.
*/
public has(key: string): boolean;
/**
* Deletes a key from the cache.
* @param {string} key The key to delete.
* @returns {boolean} True if the key was deleted, false otherwise.
*/
public del(key: string): boolean;
/**
* Deletes the database file associated with the driver if it exists.
* This method only applies to subclasses of MemoryDriver and not to the MemoryDriver itself.
*
* @returns {boolean} True if the database file was successfully deleted, false otherwise.
*/
public destroy(): boolean;
/**
* Clears all entries in the cache.
*/
public clear(): void;
/**
* Converts the cache to a JSON object.
* @returns {Record<string, V>} The JSON representation of the cache.
*/
public toJSON(): Record<string, V>;
/**
* Converts the cache to an array of key-value pairs.
* @returns {{ key: string, value: V }[]} The array representation of the cache.
*/
public toArray(): { key: string, value: V }[];
/**
* Converts the cache to a Set of key-value pairs.
* @returns A Set containing objects with key-value pairs.
*/
public toSet(): Set<{ key: string, value: V }>;
/**
* Executes a callback for each entry in the cache.
* @param {(value: V, key: string, Driver: this) => void} callback The callback to execute.
*/
public each(callback: (value: V, key: string, Driver: this) => void): void;
/**
* Creates a new MemoryDriver instance containing only the entries that satisfy the provided callback function.
*
* @param {(value: V, key: string, driver: this) => boolean} callback - The function to test each entry.
* It is called with three arguments: the value of the entry, the key of the entry, and the MemoryDriver instance itself.
*
* @returns {MemoryDriver<V>} A new MemoryDriver instance with entries that pass the test implemented by the callback.
*/
public map(callback: (value: V, key: string, Driver: this) => boolean): MemoryDriver<V>;
/**
* Validates and sets default values for the provided options.
* @param {MemoryDriverOptions} [o={}] The options to validate.
* @returns {MemoryDriverOptions} The validated and defaulted options.
*/
static checkOptions(o?: MemoryDriverOptions): _MemoryDriverOptions;
}
/**
* BsonDriver is a class that extends MemoryDriver to provide support for reading and writing
* BSON data using a specialized engine.
* @template V The type of the values stored in the driver.
*/
export class BsonDriver<V = any> extends MemoryDriver<V> {
/**
* Creates an instance of BsonDriver.
* @param options The options for configuring the BSON driver.
*/
constructor(options?: MemoryDriverOptions);
/**
* Reads data from the BSON file and populates the cache.
* Uses lodash to traverse and set nested properties.
*/
protected read(): void;
/**
* Writes current cache contents to the BSON file.
* @returns The number of bytes written.
*/
protected write(): number;
}
/**
* JsonDriver is a class that extends MemoryDriver to add support for reading and writing
* JSON data to a file using the Bun engine.
* @template V The type of the values stored in the cache.
*/
export class JsonDriver<V = any> extends MemoryDriver<V> {
public readonly options: _JsonDriverOptions;
/**
* Creates an instance of JsonDriver.
* @param {JsonDriverOptions} [options={}] The options for the JSON driver.
*/
constructor(options?: JsonDriverOptions);
/**
* Reads the JSON data from the file and populates the cache.
* @protected
*/
protected read(): void;
/**
* Writes the current cache to the JSON file.
* @returns {number} The number of bytes written to the file.
* @protected
*/
protected write(): number;
}
/**
* YamlDriver is a class that extends MemoryDriver to add support for reading and writing
* YAML data to a file using the Bun engine.
* @template V The type of the values stored in the cache.
*/
export class YamlDriver<V = any> extends MemoryDriver<V> {
public readonly options: _MemoryDriverOptions;
/**
* Creates an instance of YamlDriver.
* @param {MemoryDriverOptions} [options={}] The options for the YAML driver.
*/
constructor(options?: MemoryDriverOptions);
/**
* Reads data from the YAML file and populates the cache.
* Uses lodash to traverse and set nested properties.
* @protected
*/
protected read(): void;
/**
* Writes current cache contents to the YAML file.
* @returns {number} The number of bytes written.
* @protected
*/
protected write(): number;
}
import Shapeshift from '@sapphire/shapeshift';
/**
* A utility class providing static validation methods and schemas for common data types.
* Built on top of the @sapphire/shapeshift validation library.
*/
export class Validator {
/**
* Base validation schema for string values
* @example
* Validator.StringValidation.parse('hello') // Returns 'hello'
* Validator.StringValidation.parse(123) // Throws ValidationError
*/
static StringValidation = s.string();
/**
* Base validation schema for numeric values
* @example
* Validator.NumberValidation.parse(123) // Returns 123
* Validator.NumberValidation.parse('123') // Throws ValidationError
*/
static NumberValidation = s.number();
/**
* Base validation schema for null or undefined values
* @example
* Validator.NullishValidation.parse(null) // Returns null
* Validator.NullishValidation.parse(undefined) // Returns undefined
* Validator.NullishValidation.parse(0) // Throws ValidationError
*/
static NullishValidation = s.nullish();
/**
* Base validation schema that accepts any value
* @example
* Validator.AnyValidation.parse('anything') // Returns 'anything'
* Validator.AnyValidation.parse(null) // Returns null
*/
static AnyValidation = s.any();
/**
* Base validation schema for object values
* @example
* Validator.ObjectValidation.parse({}) // Returns {}
* Validator.ObjectValidation.parse('not an object') // Throws ValidationError
*/
static ObjectValidation = s.object({});
/**
* Base validation schema for URL instances
* @example
* Validator.URLValidation.parse(new URL('https://example.com')) // Returns URL instance
* Validator.URLValidation.parse('https://example.com') // Throws ValidationError
*/
static URLValidation = s.instance(URL);
/**
* Base validation schema for Function instances
* @example
* Validator.FunctionValidation.parse(() => {}) // Returns function
* Validator.FunctionValidation.parse({}) // Throws ValidationError
*/
static FunctionValidation = s.instance(Function);
/**
* Base validation schema for boolean values
* @example
* Validator.BooleanValidation.parse(true) // Returns true
* Validator.BooleanValidation.parse(1) // Throws ValidationError
*/
static BooleanValidation = s.boolean();
/**
* Creates a validation schema that only accepts specific string literal values
* @param values - The allowed string values
* @returns A union validator that only accepts the specified string values
* @throws {Error} If no values are provided
* @example
* const colorValidator = Validator.stringInput('red', 'blue', 'green')
* colorValidator.parse('red') // Returns 'red'
* colorValidator.parse('yellow') // Throws ValidationError
*/
static stringInput(...values: string[]): ReturnType<typeof s.union>;
/**
* Generic validation method that applies a schema to a value
* @template T The expected type of the validated value
* @param schema - The validation schema to apply
* @param value - The value to validate
* @returns The validated value cast to type T
* @throws {ValidationError} If validation fails
*/
static validate<T>(schema: BaseValidator<T>, value: any): T;
/**
* Validates boolean values with optional exact matching
* @param value - The value to validate
* @param options - Optional validation configuration
* @param options.exact - If provided, requires the value to exactly match true or false
* @returns The validated boolean value
* @throws {ValidationError} If validation fails
* @example
* Validator.boolean(true) // Returns true
* Validator.boolean(1) // Throws ValidationError
* Validator.boolean(true, { exact: false }) // Throws ValidationError
*/
static boolean(value: any, options?: { exact?: boolean }): boolean;
/**
* Validates string values with optional length constraints
* @param value - The value to validate
* @param options - Optional validation configuration
* @param options.minLength - Minimum required string length
* @param options.maxLength - Maximum allowed string length
* @returns The validated string value
* @throws {ValidationError} If validation fails
* @example
* Validator.string('test') // Returns 'test'
* Validator.string('abc', { minLength: 5 }) // Throws ValidationError
* Validator.string('toolong', { maxLength: 5 }) // Throws ValidationError
*/
static string(value: any, options?: { minLength?: number; maxLength?: number }): string;
/**
* Validates numeric values with optional range and integer constraints
* @param value - The value to validate
* @param options - Optional validation configuration
* @param options.min - Minimum allowed value
* @param options.max - Maximum allowed value
* @param options.integer - If true, requires the value to be an integer
* @returns The validated number value
* @throws {ValidationError} If validation fails
* @example
* Validator.number(123) // Returns 123
* Validator.number(5, { min: 10 }) // Throws ValidationError
* Validator.number(3.14, { integer: true }) // Throws ValidationError
*/
static number(value: any, options?: { min?: number; max?: number; integer?: boolean }): number;
/**
* Validates object values with optional schema validation
* @template T The expected type of the validated object
* @param value - The value to validate
* @param schema - Optional object schema for validating properties
* @returns The validated object cast to type T
* @throws {ValidationError} If validation fails
* @example
* Validator.object({ name: 'test' }) // Returns { name: 'test' }
* Validator.object({ age: '25' }, { age: Validator.NumberValidation }) // Throws ValidationError
*/
static object<T extends Record<string, any>>(value: any, schema?: Record<string, BaseValidator<any>>): T;
/**
* Validates array values with optional type and length constraints
* @template T The expected type of array elements
* @param value - The value to validate
* @param options - Optional validation configuration
* @param options.itemValidation - Validation schema for array elements
* @param options.minLength - Minimum required array length
* @param options.maxLength - Maximum allowed array length
* @returns The validated array of type T[]
* @throws {ValidationError} If validation fails
* @example
* Validator.array([1, 2, 3]) // Returns [1, 2, 3]
* Validator.array([1, '2'], { itemValidation: Validator.NumberValidation }) // Throws ValidationError
*/
static array<T>(value: any, options?: { itemValidation?: BaseValidator<T>; minLength?: number; maxLength?: number }): T[];
/**
* Validates values against an enum type
* @template T The enum type to validate against
* @param enumObj - The enum object containing valid values
* @param value - The value to validate
* @returns The validated enum value
* @throws {Error} If the enum object is empty
* @throws {ValidationError} If validation fails
* @example
* enum Color { Red = 'red', Blue = 'blue' }
* Validator.enum(Color, 'red') // Returns 'red'
* Validator.enum(Color, 'yellow') // Throws ValidationError
*/
static enum<T extends Record<string, string | number>>(enumObj: T, value: any): T[keyof T];
/**
* Validates that a value is an instance of a specific class
* @template T The expected instance type
* @param constructor - The class constructor to check against
* @param value - The value to validate
* @returns The validated instance of type T
* @throws {ValidationError} If validation fails
* @example
* class User {}
* Validator.instance(User, new User()) // Returns User instance
* Validator.instance(User, {}) // Throws ValidationError
*/
static instance<T>(constructor: new (...args: any[]) => T, value: any): T;
/**
* Validates function values with optional arity constraints
* @param value - The value to validate
* @param options - Optional validation configuration
* @param options.arity - The exact number of parameters the function should accept
* @returns The validated function
* @throws {ValidationError} If validation fails or arity doesn't match
* @example
* Validator.function((a, b) => a + b) // Returns the function
* Validator.function((a) => a, { arity: 2 }) // Throws Error
*/
static function(value: any, options?: { arity?: number }): Function;
}
export {
Database,
JsonDriver, YamlDriver, BsonDriver, MemoryDriver,
Validator
}
export default Database;
}