This commit is contained in:
Lukian 2023-06-20 15:28:07 +02:00
parent 68f4b60012
commit 41ae7ff4bd
1010 changed files with 38622 additions and 17071 deletions

View file

@ -1,3 +1,19 @@
declare const IncrementSymbol: unique symbol;
declare const EpochSymbol: unique symbol;
declare const ProcessIdSymbol: unique symbol;
declare const WorkerIdSymbol: unique symbol;
/**
* The maximum value the `workerId` field accepts in snowflakes.
*/
declare const MaximumWorkerId = 31n;
/**
* The maximum value the `processId` field accepts in snowflakes.
*/
declare const MaximumProcessId = 31n;
/**
* The maximum value the `increment` field accepts in snowflakes.
*/
declare const MaximumIncrement = 4095n;
/**
* A class for generating and deconstructing Twitter snowflakes.
*
@ -12,19 +28,56 @@
* ```
*/
declare class Snowflake {
#private;
/**
* Alias for {@link deconstruct}
*/
decode: (id: string | bigint) => DeconstructedSnowflake;
/**
* Internal reference of the epoch passed in the constructor
* @internal
*/
private readonly [EpochSymbol];
/**
* Internal incrementor for generating snowflakes
* @internal
*/
private [IncrementSymbol];
/**
* The process ID that will be used by default in the generate method
* @internal
*/
private [ProcessIdSymbol];
/**
* The worker ID that will be used by default in the generate method
* @internal
*/
private [WorkerIdSymbol];
/**
* @param epoch the epoch to use
*/
constructor(epoch: number | bigint | Date);
/**
* The epoch for this snowflake.
* The epoch for this snowflake
*/
get epoch(): bigint;
/**
* Gets the configured process ID
*/
get processId(): bigint;
/**
* Sets the process ID that will be used by default for the {@link generate} method
* @param value The new value, will be coerced to BigInt and masked with `0b11111n`
*/
set processId(value: number | bigint);
/**
* Gets the configured worker ID
*/
get workerId(): bigint;
/**
* Sets the worker ID that will be used by default for the {@link generate} method
* @param value The new value, will be coerced to BigInt and masked with `0b11111n`
*/
set workerId(value: number | bigint);
/**
* Generates a snowflake given an epoch and optionally a timestamp
* @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}
@ -146,4 +199,4 @@ declare const DiscordSnowflake: Snowflake;
*/
declare const TwitterSnowflake: Snowflake;
export { DeconstructedSnowflake, DiscordSnowflake, Snowflake, SnowflakeGenerateOptions, TwitterSnowflake };
export { DeconstructedSnowflake, DiscordSnowflake, MaximumIncrement, MaximumProcessId, MaximumWorkerId, Snowflake, SnowflakeGenerateOptions, TwitterSnowflake };