commit
This commit is contained in:
parent
a15c733e45
commit
2a5130cbda
2838 changed files with 288613 additions and 0 deletions
149
node_modules/@sapphire/snowflake/dist/index.d.ts
generated
vendored
Normal file
149
node_modules/@sapphire/snowflake/dist/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* A class for generating and deconstructing Twitter snowflakes.
|
||||
*
|
||||
* A {@link https://developer.twitter.com/en/docs/twitter-ids Twitter snowflake}
|
||||
* is a 64-bit unsigned integer with 4 fields that have a fixed epoch value.
|
||||
*
|
||||
* If we have a snowflake `266241948824764416` we can represent it as binary:
|
||||
* ```
|
||||
* 64 22 17 12 0
|
||||
* 000000111011000111100001101001000101000000 00001 00000 000000000000
|
||||
* number of ms since epoch worker pid increment
|
||||
* ```
|
||||
*/
|
||||
declare class Snowflake {
|
||||
#private;
|
||||
/**
|
||||
* Alias for {@link deconstruct}
|
||||
*/
|
||||
decode: (id: string | bigint) => DeconstructedSnowflake;
|
||||
/**
|
||||
* @param epoch the epoch to use
|
||||
*/
|
||||
constructor(epoch: number | bigint | Date);
|
||||
/**
|
||||
* The epoch for this snowflake.
|
||||
*/
|
||||
get epoch(): bigint;
|
||||
/**
|
||||
* Generates a snowflake given an epoch and optionally a timestamp
|
||||
* @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}
|
||||
*
|
||||
* **note** when `increment` is not provided it defaults to the private `increment` of the instance
|
||||
* @example
|
||||
* ```typescript
|
||||
* const epoch = new Date('2000-01-01T00:00:00.000Z');
|
||||
* const snowflake = new Snowflake(epoch).generate();
|
||||
* ```
|
||||
* @returns A unique snowflake
|
||||
*/
|
||||
generate({ increment, timestamp, workerId, processId }?: SnowflakeGenerateOptions): bigint;
|
||||
/**
|
||||
* Deconstructs a snowflake given a snowflake ID
|
||||
* @param id the snowflake to deconstruct
|
||||
* @returns a deconstructed snowflake
|
||||
* @example
|
||||
* ```typescript
|
||||
* const epoch = new Date('2000-01-01T00:00:00.000Z');
|
||||
* const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
|
||||
* ```
|
||||
*/
|
||||
deconstruct(id: string | bigint): DeconstructedSnowflake;
|
||||
/**
|
||||
* Retrieves the timestamp field's value from a snowflake.
|
||||
* @param id The snowflake to get the timestamp value from.
|
||||
* @returns The UNIX timestamp that is stored in `id`.
|
||||
*/
|
||||
timestampFrom(id: string | bigint): number;
|
||||
/**
|
||||
* Returns a number indicating whether a reference snowflake comes before, or after, or is same as the given
|
||||
* snowflake in sort order.
|
||||
* @param a The first snowflake to compare.
|
||||
* @param b The second snowflake to compare.
|
||||
* @returns `-1` if `a` is older than `b`, `0` if `a` and `b` are equals, `1` if `a` is newer than `b`.
|
||||
* @example Sort snowflakes in ascending order
|
||||
* ```typescript
|
||||
* const ids = ['737141877803057244', '1056191128120082432', '254360814063058944'];
|
||||
* console.log(ids.sort((a, b) => Snowflake.compare(a, b)));
|
||||
* // → ['254360814063058944', '737141877803057244', '1056191128120082432'];
|
||||
* ```
|
||||
* @example Sort snowflakes in descending order
|
||||
* ```typescript
|
||||
* const ids = ['737141877803057244', '1056191128120082432', '254360814063058944'];
|
||||
* console.log(ids.sort((a, b) => -Snowflake.compare(a, b)));
|
||||
* // → ['1056191128120082432', '737141877803057244', '254360814063058944'];
|
||||
* ```
|
||||
*/
|
||||
static compare(a: string | bigint, b: string | bigint): -1 | 0 | 1;
|
||||
}
|
||||
/**
|
||||
* Options for Snowflake#generate
|
||||
*/
|
||||
interface SnowflakeGenerateOptions {
|
||||
/**
|
||||
* Timestamp or date of the snowflake to generate
|
||||
* @default Date.now()
|
||||
*/
|
||||
timestamp?: number | bigint | Date;
|
||||
/**
|
||||
* The increment to use
|
||||
* @default 0n
|
||||
* @remark keep in mind that this bigint is auto-incremented between generate calls
|
||||
*/
|
||||
increment?: bigint;
|
||||
/**
|
||||
* The worker ID to use, will be truncated to 5 bits (0-31)
|
||||
* @default 0n
|
||||
*/
|
||||
workerId?: bigint;
|
||||
/**
|
||||
* The process ID to use, will be truncated to 5 bits (0-31)
|
||||
* @default 1n
|
||||
*/
|
||||
processId?: bigint;
|
||||
}
|
||||
/**
|
||||
* Object returned by Snowflake#deconstruct
|
||||
*/
|
||||
interface DeconstructedSnowflake {
|
||||
/**
|
||||
* The id in BigInt form
|
||||
*/
|
||||
id: bigint;
|
||||
/**
|
||||
* The timestamp stored in the snowflake
|
||||
*/
|
||||
timestamp: bigint;
|
||||
/**
|
||||
* The worker id stored in the snowflake
|
||||
*/
|
||||
workerId: bigint;
|
||||
/**
|
||||
* The process id stored in the snowflake
|
||||
*/
|
||||
processId: bigint;
|
||||
/**
|
||||
* The increment stored in the snowflake
|
||||
*/
|
||||
increment: bigint;
|
||||
/**
|
||||
* The epoch to use in the snowflake
|
||||
*/
|
||||
epoch: bigint;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class for parsing snowflake ids using Discord's snowflake epoch
|
||||
*
|
||||
* Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}
|
||||
*/
|
||||
declare const DiscordSnowflake: Snowflake;
|
||||
|
||||
/**
|
||||
* A class for parsing snowflake ids using Twitter's snowflake epoch
|
||||
*
|
||||
* Which is 2010-11-04 at 01:42:54.657 UTC+0, found in the archived snowflake repository {@linkplain https://github.com/twitter-archive/snowflake/blob/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231/src/main/scala/com/twitter/service/snowflake/IdWorker.scala#L25}
|
||||
*/
|
||||
declare const TwitterSnowflake: Snowflake;
|
||||
|
||||
export { DeconstructedSnowflake, DiscordSnowflake, Snowflake, SnowflakeGenerateOptions, TwitterSnowflake };
|
112
node_modules/@sapphire/snowflake/dist/index.global.js
generated
vendored
Normal file
112
node_modules/@sapphire/snowflake/dist/index.global.js
generated
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
var SapphireSnowflake = (function (exports) {
|
||||
'use strict';
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => ({
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
});
|
||||
|
||||
// src/lib/Snowflake.ts
|
||||
var ProcessId = 1n;
|
||||
var WorkerId = 0n;
|
||||
var _increment, _epoch;
|
||||
var Snowflake = class {
|
||||
constructor(epoch) {
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
}
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
timestamp = BigInt(timestamp);
|
||||
else if (typeof timestamp !== "bigint") {
|
||||
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
||||
}
|
||||
if (typeof increment === "bigint" && increment >= 4095n)
|
||||
increment = 0n;
|
||||
else {
|
||||
increment = __privateWrapper(this, _increment)._++;
|
||||
if (__privateGet(this, _increment) >= 4095n)
|
||||
__privateSet(this, _increment, 0n);
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
}
|
||||
deconstruct(id) {
|
||||
const bigIntId = BigInt(id);
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
};
|
||||
}
|
||||
timestampFrom(id) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
}
|
||||
static compare(a, b) {
|
||||
if (typeof a === "bigint" || typeof b === "bigint") {
|
||||
if (typeof a === "string")
|
||||
a = BigInt(a);
|
||||
else if (typeof b === "string")
|
||||
b = BigInt(b);
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
return a === b ? 0 : a.length < b.length ? -1 : a.length > b.length ? 1 : a < b ? -1 : 1;
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
||||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1288834974657n);
|
||||
|
||||
exports.DiscordSnowflake = DiscordSnowflake;
|
||||
exports.Snowflake = Snowflake;
|
||||
exports.TwitterSnowflake = TwitterSnowflake;
|
||||
|
||||
return exports;
|
||||
|
||||
})({});
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index.global.js.map
|
1
node_modules/@sapphire/snowflake/dist/index.global.js.map
generated
vendored
Normal file
1
node_modules/@sapphire/snowflake/dist/index.global.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
107
node_modules/@sapphire/snowflake/dist/index.js
generated
vendored
Normal file
107
node_modules/@sapphire/snowflake/dist/index.js
generated
vendored
Normal file
|
@ -0,0 +1,107 @@
|
|||
'use strict';
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => ({
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
});
|
||||
|
||||
// src/lib/Snowflake.ts
|
||||
var ProcessId = 1n;
|
||||
var WorkerId = 0n;
|
||||
var _increment, _epoch;
|
||||
var Snowflake = class {
|
||||
constructor(epoch) {
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
}
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
timestamp = BigInt(timestamp);
|
||||
else if (typeof timestamp !== "bigint") {
|
||||
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
||||
}
|
||||
if (typeof increment === "bigint" && increment >= 4095n)
|
||||
increment = 0n;
|
||||
else {
|
||||
increment = __privateWrapper(this, _increment)._++;
|
||||
if (__privateGet(this, _increment) >= 4095n)
|
||||
__privateSet(this, _increment, 0n);
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
}
|
||||
deconstruct(id) {
|
||||
const bigIntId = BigInt(id);
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
};
|
||||
}
|
||||
timestampFrom(id) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
}
|
||||
static compare(a, b) {
|
||||
if (typeof a === "bigint" || typeof b === "bigint") {
|
||||
if (typeof a === "string")
|
||||
a = BigInt(a);
|
||||
else if (typeof b === "string")
|
||||
b = BigInt(b);
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
return a === b ? 0 : a.length < b.length ? -1 : a.length > b.length ? 1 : a < b ? -1 : 1;
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
||||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1288834974657n);
|
||||
|
||||
exports.DiscordSnowflake = DiscordSnowflake;
|
||||
exports.Snowflake = Snowflake;
|
||||
exports.TwitterSnowflake = TwitterSnowflake;
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/@sapphire/snowflake/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@sapphire/snowflake/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
103
node_modules/@sapphire/snowflake/dist/index.mjs
generated
vendored
Normal file
103
node_modules/@sapphire/snowflake/dist/index.mjs
generated
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
var __defProp = Object.defineProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => ({
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
});
|
||||
|
||||
// src/lib/Snowflake.ts
|
||||
var ProcessId = 1n;
|
||||
var WorkerId = 0n;
|
||||
var _increment, _epoch;
|
||||
var Snowflake = class {
|
||||
constructor(epoch) {
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
}
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
timestamp = BigInt(timestamp);
|
||||
else if (typeof timestamp !== "bigint") {
|
||||
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
||||
}
|
||||
if (typeof increment === "bigint" && increment >= 4095n)
|
||||
increment = 0n;
|
||||
else {
|
||||
increment = __privateWrapper(this, _increment)._++;
|
||||
if (__privateGet(this, _increment) >= 4095n)
|
||||
__privateSet(this, _increment, 0n);
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
}
|
||||
deconstruct(id) {
|
||||
const bigIntId = BigInt(id);
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
};
|
||||
}
|
||||
timestampFrom(id) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
}
|
||||
static compare(a, b) {
|
||||
if (typeof a === "bigint" || typeof b === "bigint") {
|
||||
if (typeof a === "string")
|
||||
a = BigInt(a);
|
||||
else if (typeof b === "string")
|
||||
b = BigInt(b);
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
return a === b ? 0 : a.length < b.length ? -1 : a.length > b.length ? 1 : a < b ? -1 : 1;
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
||||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1288834974657n);
|
||||
|
||||
export { DiscordSnowflake, Snowflake, TwitterSnowflake };
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index.mjs.map
|
1
node_modules/@sapphire/snowflake/dist/index.mjs.map
generated
vendored
Normal file
1
node_modules/@sapphire/snowflake/dist/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue