-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
135 lines (120 loc) · 5.02 KB
/
index.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
import { TypedEmitter } from "tiny-typed-emitter";
declare global {
interface Array<T> {
isEmpty: boolean;
removeFirst(value: T): T | undefined;
take(amount: number): Array<T>;
takeLast(amount: number): Array<T>;
drop(amount: number): Array<T>;
dropLast(amount: number): Array<T>;
}
}
export class Mutex {
get locked(): boolean;
static wait(duration: number): Promise<void>;
take(): Promise<Release>;
cancel(): void;
}
type Release = () => void;
export class Extender<M extends Dictionary<Class>> {
readonly structures: Map<keyof M, Class>;
constructor(map: M);
get<K extends keyof M>(key: K): M[K];
extend<K extends keyof M, E extends M[K]>(key: K, extender: (base: M[K]) => E): Extender<M>;
}
export class Snowflake {
static deconstruct(snowflake: snowflake, epoch?: bigint): DeconstructedSnowflake;
static generate(options?: GenerateSnowflakeOptions): snowflake;
}
export type snowflake = string;
export interface GenerateSnowflakeOptions {
timestamp?: number | bigint;
epoch?: number | bigint;
workerId?: number | bigint;
processId?: number | bigint;
sequence?: number | bigint;
}
export interface DeconstructedSnowflake {
id: snowflake;
timestamp: bigint;
workerId: bigint;
processId: bigint;
increment: bigint;
}
export class Collection<K, V> extends Map<K, V> {
["constructor"]: typeof Collection;
static from<K, V>(tupleArrayOrObject: Dictionary<V> | Tuple<K, V>[]): Collection<K, V>;
static from<V>(values: V[]): Collection<number, V>;
first(): Tuple<K, V> | null;
first(amount: number): Tuple<K, V>[];
last(): Tuple<K, V> | null;
last(amount: number): Tuple<K, V>[];
array(): V[];
some(predicate: (value: V, key: K, col: this) => boolean, thisArg?: unknown): boolean;
all(predicate: (value: V, key: K, col: this) => boolean, thisArg?: unknown): boolean;
slice(from?: number, end?: number): Collection<K, V>;
each(fn: (value: V, key: K, col: this) => unknown, thisArg?: unknown): this;
ensure(key: K, value: ((key: K) => V) | V): V;
random(): V;
randomKey(): K;
randomEntry(): Tuple<K, V>;
sweep(fn: (value: V, key: K, col: this) => boolean, thisArg?: unknown): number;
find(fn: (value: V, key: K, col: this) => boolean, thisArg?: unknown): V | null;
reduce<A>(fn: (acc: A, value: V, key: K, col: this) => A, acc: A, thisArg?: unknown): A;
partition(predicate: (value: V, key: K, col: this) => boolean, thisArg?: unknown): Tuple<Collection<K, V>, Collection<K, V>>;
filter(fn: (value: V, key: K, col: this) => boolean, thisArg?: unknown): Collection<K, V>;
map<T>(fn: (value: V, key: K, col: this) => T, thisArg?: unknown): T[];
sort(compareFunction?: (firstValue: V, secondValue: V, firstKey?: K, secondKey?: K) => number): this;
sorted(compareFunction?: (firstValue: V, secondValue: V, firstKey?: K, secondKey?: K) => number): Collection<K, V>;
clone(): Collection<K, V>;
toString(): string;
}
type Callback = () => void | Promise<void>;
export class AsyncLimiter extends TypedEmitter<{
limited: (wait: number) => void;
}> {
readonly defaultTokens: number;
readonly waitTime: number;
readonly wait: boolean;
constructor(defaultTokens: number, waitTime: number, wait: boolean);
consume(callback: Callback, important?: boolean): Promise<void>;
lock(wait?: number): Promise<void>;
unlock(): Promise<void>;
}
export {};
export type Tuple<A = any, B = any> = [A, B];
export type Dictionary<V = any, K extends PropertyKey = string> = Record<K, V>;
export type Class<T = any> = {
new (...args: any[]): T;
};
export interface EventEmitterLike {
emit(event: string, ...args: any[]): boolean | void;
addListener(event: string, listener: (...args: any[]) => void): EventEmitterLike | any;
removeListener(event: string, listener: (...args: any[]) => void): EventEmitterLike | any;
}
export const INTERVALS: Set<NodeJS.Timeout>;
export const TIMEOUTS: Set<NodeJS.Timeout>;
export function clearIntervals(): number;
export function clearTimeouts(): number;
export function clearScheduled(): [timeouts: number, intervals: number];
export function createInterval(delay: number, block: Task, ...args: any[]): Interval;
export function createTimeout(delay: number, block: Task, ...args: any[]): Timeout;
export class Interval extends TaskScheduler {
start(delay: number, ...args: any[]): Interval;
stop(): void;
}
export class Timeout extends TaskScheduler {
start(delay: number, ...args: any[]): Timeout;
stop(): void;
}
export function isObject(input: unknown): input is Dictionary;
export function mergeObject<O extends Record<PropertyKey, any> = Record<PropertyKey, any>>(...objects: Partial<O>[]): O;
export function safeRequire<T>(name: string): T | undefined;
export abstract class TaskScheduler {
ref?: NodeJS.Timeout;
protected _task: Task;
constructor(task: Task);
abstract start(delay: number, ...args: any[]): TaskScheduler;
abstract stop(): void;
}
export type Task = (...args: any[]) => void;