commit
This commit is contained in:
parent
68f4b60012
commit
41ae7ff4bd
1010 changed files with 38622 additions and 17071 deletions
29
node_modules/@sapphire/shapeshift/CHANGELOG.md
generated
vendored
29
node_modules/@sapphire/shapeshift/CHANGELOG.md
generated
vendored
|
@ -2,6 +2,35 @@
|
|||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [3.9.2](https://github.com/sapphiredev/shapeshift/compare/v3.9.1...v3.9.2) - (2023-06-04)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **arrayvalidator:** Fixed runaway type instantiation with TypeScript >=5.1 (#275) ([f59d901](https://github.com/sapphiredev/shapeshift/commit/f59d90112181e6625230c28e6a4f0f065ced6344))
|
||||
|
||||
# [3.9.1](https://github.com/sapphiredev/shapeshift/compare/v3.9.0...v3.9.1) - (2023-06-02)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **types:** Move the `types` condition to the front (#273) ([5a3e202](https://github.com/sapphiredev/shapeshift/commit/5a3e202e9ceafb3d330a568e93c060dd5aac1dde))
|
||||
|
||||
# [3.9.0](https://github.com/sapphiredev/shapeshift/compare/v3.8.2...v3.9.0) - (2023-05-09)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- Resolve minor grammar mistake (#260) ([62df609](https://github.com/sapphiredev/shapeshift/commit/62df6094845ffa118aa93ea3c5f47f81f1c5d99f))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add BaseValidator.describe (#267) ([d9e1a2d](https://github.com/sapphiredev/shapeshift/commit/d9e1a2d2f3c5e6378f0025becf8497138ee6d97c))
|
||||
|
||||
# [3.8.2](https://github.com/sapphiredev/shapeshift/compare/v3.8.1...v3.8.2) - (2023-04-02)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- ***:** TypeScript 5.x compatibility (#253) ([eba2a88](https://github.com/sapphiredev/shapeshift/commit/eba2a88b91fb6631f431313753299ec7a70cf6ce))
|
||||
- Remove `node:` prefix (#249) ([af766b5](https://github.com/sapphiredev/shapeshift/commit/af766b504c1013f3cd24f7bf803ac9ff7442a8d7))
|
||||
|
||||
# [3.8.1](https://github.com/sapphiredev/shapeshift/compare/v3.8.0...v3.8.1) - (2022-12-15)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
|
35
node_modules/@sapphire/shapeshift/README.md
generated
vendored
35
node_modules/@sapphire/shapeshift/README.md
generated
vendored
|
@ -1,6 +1,6 @@
|
|||
<div align="center">
|
||||
|
||||

|
||||

|
||||
|
||||
# @sapphire/shapeshift
|
||||
|
||||
|
@ -920,36 +920,15 @@ below to donate through your method of choice.
|
|||
|
||||
[Back to top][toc]
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
Please make sure to read the [Contributing Guide][contributing] before making a pull request.
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antonio Román</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=kyranet" title="Code">💻</a> <a href="https://github.com/sapphiredev/shapeshift/commits?author=kyranet" title="Documentation">📖</a> <a href="#ideas-kyranet" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=vladfrangu" title="Code">💻</a> <a href="https://github.com/sapphiredev/shapeshift/commits?author=vladfrangu" title="Documentation">📖</a> <a href="#ideas-vladfrangu" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center"><a href="https://favware.tech/"><img src="https://avatars.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=favna" title="Documentation">📖</a> <a href="#maintenance-favna" title="Maintenance">🚧</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/Khasms"><img src="https://avatars.githubusercontent.com/u/36800359?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=Khasms" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=imranbarbhuiya" title="Code">💻</a> <a href="https://github.com/sapphiredev/shapeshift/commits?author=imranbarbhuiya" title="Tests">⚠️</a> <a href="https://github.com/sapphiredev/shapeshift/issues?q=author%3Aimranbarbhuiya" title="Bug reports">🐛</a> <a href="https://github.com/sapphiredev/shapeshift/commits?author=imranbarbhuiya" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=allcontributors[bot]" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="#tool-RealShadowNova" title="Tools">🔧</a></td>
|
||||
<td align="center"><a href="https://github.com/legendhimslef"><img src="https://avatars.githubusercontent.com/u/69213593?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Voxelli</b></sub></a><br /><a href="https://github.com/sapphiredev/shapeshift/commits?author=legendhimslef" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
Thank you to all the people who already contributed to Sapphire!
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
|
||||
Contributions of any kind welcome!
|
||||
<a href="https://github.com/sapphiredev/shapeshift/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=sapphiredev/shapeshift" />
|
||||
</a>
|
||||
|
||||
[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md
|
||||
[`zod`]: https://github.com/colinhacks/zod
|
||||
[documentation]: https://www.sapphirejs.dev/docs/Documentation/api-shapeshift/
|
||||
[toc]: #table-of-contents
|
||||
|
|
8
node_modules/@sapphire/shapeshift/dist/index.d.ts
generated
vendored
8
node_modules/@sapphire/shapeshift/dist/index.d.ts
generated
vendored
|
@ -1,4 +1,4 @@
|
|||
import { InspectOptionsStylized } from 'node:util';
|
||||
import { InspectOptionsStylized } from 'util';
|
||||
|
||||
declare class Result<T, E extends Error = Error> {
|
||||
readonly success: boolean;
|
||||
|
@ -301,7 +301,7 @@ declare class ObjectValidator<T extends object, I = UndefinedToOptional<T>> exte
|
|||
private handleStrictStrategy;
|
||||
private handlePassthroughStrategy;
|
||||
}
|
||||
declare const enum ObjectValidatorStrategy {
|
||||
declare enum ObjectValidatorStrategy {
|
||||
Ignore = 0,
|
||||
Strict = 1,
|
||||
Passthrough = 2
|
||||
|
@ -500,6 +500,7 @@ declare class ArrayValidator<T extends unknown[], I = T[number]> extends BaseVal
|
|||
}
|
||||
|
||||
declare abstract class BaseValidator<T> {
|
||||
description?: string;
|
||||
protected parent?: object;
|
||||
protected constraints: readonly IConstraint<T>[];
|
||||
protected isValidationEnabled: boolean | (() => boolean) | null;
|
||||
|
@ -517,6 +518,7 @@ declare abstract class BaseValidator<T> {
|
|||
reshape<R extends Result<unknown>, O = InferResultType<R>>(cb: (input: T) => R): BaseValidator<O>;
|
||||
default(value: Exclude<T, undefined> | (() => Exclude<T, undefined>)): DefaultValidator<Exclude<T, undefined>>;
|
||||
when<Key extends WhenKey, This extends BaseValidator<any> = this>(key: Key, options: WhenOptions<This, Key>): this;
|
||||
describe(description: string): this;
|
||||
run(value: unknown): Result<T, BaseError>;
|
||||
parse<R extends T = T>(value: unknown): R;
|
||||
is<R extends T = T>(value: unknown): value is R;
|
||||
|
@ -650,7 +652,7 @@ type ExpandSmallerTuples<T extends [...any[]]> = T extends [T[0], ...infer Tail]
|
|||
type Shift<A extends Array<any>> = ((...args: A) => void) extends (...args: [A[0], ...infer R]) => void ? R : never;
|
||||
type GrowExpRev<A extends Array<any>, N extends number, P extends Array<Array<any>>> = A['length'] extends N ? A : GrowExpRev<[...A, ...P[0]][N] extends undefined ? [...A, ...P[0]] : A, N, Shift<P>>;
|
||||
type GrowExp<A extends Array<any>, N extends number, P extends Array<Array<any>>> = [...A, ...A][N] extends undefined ? GrowExp<[...A, ...A], N, [A, ...P]> : GrowExpRev<A, N, P>;
|
||||
type Tuple<T, N extends number> = number extends N ? Array<T> : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]>;
|
||||
type Tuple<T, N extends number> = N extends number ? number extends N ? Array<T> : N extends 0 ? [] : N extends 1 ? [T] : GrowExp<[T], N, [[]]> : never;
|
||||
|
||||
declare class LazyValidator<T extends BaseValidator<unknown>, R = Unwrap<T>> extends BaseValidator<R> {
|
||||
private readonly validator;
|
||||
|
|
40
node_modules/@sapphire/shapeshift/dist/index.global.js
generated
vendored
40
node_modules/@sapphire/shapeshift/dist/index.global.js
generated
vendored
|
@ -20,6 +20,10 @@ var SapphireShapeshift = (function (exports) {
|
|||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
@ -1255,7 +1259,7 @@ var SapphireShapeshift = (function (exports) {
|
|||
// src/constraints/ObjectConstrains.ts
|
||||
var import_get = __toESM(require_get());
|
||||
|
||||
// node-modules-polyfills:node:util
|
||||
// node-modules-polyfills:util
|
||||
var e;
|
||||
var t;
|
||||
var n;
|
||||
|
@ -1823,7 +1827,7 @@ var SapphireShapeshift = (function (exports) {
|
|||
}, X.isBuffer = i$1;
|
||||
var Se = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
function Be() {
|
||||
var e3 = new Date(), t3 = [Oe(e3.getHours()), Oe(e3.getMinutes()), Oe(e3.getSeconds())].join(":");
|
||||
var e3 = /* @__PURE__ */ new Date(), t3 = [Oe(e3.getHours()), Oe(e3.getMinutes()), Oe(e3.getSeconds())].join(":");
|
||||
return [e3.getDate(), Se[e3.getMonth()], t3].join(" ");
|
||||
}
|
||||
__name(Be, "Be");
|
||||
|
@ -2101,6 +2105,11 @@ ${givenBlock}`;
|
|||
when(key, options) {
|
||||
return this.addConstraint(whenConstraint(key, options, this));
|
||||
}
|
||||
describe(description) {
|
||||
const clone = this.clone();
|
||||
clone.description = description;
|
||||
return clone;
|
||||
}
|
||||
run(value) {
|
||||
let result = this.handle(value);
|
||||
if (result.isErr())
|
||||
|
@ -2121,6 +2130,11 @@ ${givenBlock}`;
|
|||
is(value) {
|
||||
return this.run(value).isOk();
|
||||
}
|
||||
/**
|
||||
* Sets if the validator should also run constraints or just do basic checks.
|
||||
* @param isValidationEnabled Whether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing.
|
||||
* Set to `null` to go off of the global configuration.
|
||||
*/
|
||||
setValidationEnabled(isValidationEnabled) {
|
||||
const clone = this.clone();
|
||||
clone.isValidationEnabled = isValidationEnabled;
|
||||
|
@ -3020,7 +3034,7 @@ ${errors}`;
|
|||
|
||||
// src/validators/ObjectValidator.ts
|
||||
var ObjectValidator = class extends BaseValidator {
|
||||
constructor(shape, strategy = ObjectValidatorStrategy.Ignore, constraints = []) {
|
||||
constructor(shape, strategy = 0 /* Ignore */, constraints = []) {
|
||||
super(constraints);
|
||||
this.keys = [];
|
||||
this.requiredKeys = /* @__PURE__ */ new Map();
|
||||
|
@ -3029,14 +3043,14 @@ ${errors}`;
|
|||
this.shape = shape;
|
||||
this.strategy = strategy;
|
||||
switch (this.strategy) {
|
||||
case ObjectValidatorStrategy.Ignore:
|
||||
case 0 /* Ignore */:
|
||||
this.handleStrategy = (value) => this.handleIgnoreStrategy(value);
|
||||
break;
|
||||
case ObjectValidatorStrategy.Strict: {
|
||||
case 1 /* Strict */: {
|
||||
this.handleStrategy = (value) => this.handleStrictStrategy(value);
|
||||
break;
|
||||
}
|
||||
case ObjectValidatorStrategy.Passthrough:
|
||||
case 2 /* Passthrough */:
|
||||
this.handleStrategy = (value) => this.handlePassthroughStrategy(value);
|
||||
break;
|
||||
}
|
||||
|
@ -3074,13 +3088,13 @@ ${errors}`;
|
|||
}
|
||||
}
|
||||
get strict() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Strict, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 1 /* Strict */, this.constraints]);
|
||||
}
|
||||
get ignore() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Ignore, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 0 /* Ignore */, this.constraints]);
|
||||
}
|
||||
get passthrough() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Passthrough, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 2 /* Passthrough */, this.constraints]);
|
||||
}
|
||||
get partial() {
|
||||
const shape = Object.fromEntries(this.keys.map((key) => [key, this.shape[key].optional]));
|
||||
|
@ -3224,12 +3238,6 @@ ${errors}`;
|
|||
}
|
||||
};
|
||||
__name(ObjectValidator, "ObjectValidator");
|
||||
var ObjectValidatorStrategy = /* @__PURE__ */ ((ObjectValidatorStrategy2) => {
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Ignore"] = 0] = "Ignore";
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Strict"] = 1] = "Strict";
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Passthrough"] = 2] = "Passthrough";
|
||||
return ObjectValidatorStrategy2;
|
||||
})(ObjectValidatorStrategy || {});
|
||||
|
||||
// src/validators/PassthroughValidator.ts
|
||||
var PassthroughValidator = class extends BaseValidator {
|
||||
|
@ -3522,7 +3530,7 @@ ${givenBlock}`;
|
|||
try {
|
||||
url = new URL(input);
|
||||
} catch {
|
||||
return Result.err(new ExpectedConstraintError("s.string.url", "Invalid URL", input, "expected to match an URL"));
|
||||
return Result.err(new ExpectedConstraintError("s.string.url", "Invalid URL", input, "expected to match a URL"));
|
||||
}
|
||||
const validatorFnResult = validatorFn(input, url);
|
||||
if (validatorFnResult === null)
|
||||
|
|
2
node_modules/@sapphire/shapeshift/dist/index.global.js.map
generated
vendored
2
node_modules/@sapphire/shapeshift/dist/index.global.js.map
generated
vendored
File diff suppressed because one or more lines are too long
42
node_modules/@sapphire/shapeshift/dist/index.js
generated
vendored
42
node_modules/@sapphire/shapeshift/dist/index.js
generated
vendored
|
@ -5,6 +5,12 @@ var util = require('util');
|
|||
var fastDeepEqual = require('fast-deep-equal/es6/index.js');
|
||||
var uniqWith = require('lodash/uniqWith.js');
|
||||
|
||||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
||||
|
||||
var get__default = /*#__PURE__*/_interopDefault(get);
|
||||
var fastDeepEqual__default = /*#__PURE__*/_interopDefault(fastDeepEqual);
|
||||
var uniqWith__default = /*#__PURE__*/_interopDefault(uniqWith);
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
|
||||
|
@ -121,7 +127,7 @@ function whenConstraint(key, options, validator) {
|
|||
return Result.err(new ExpectedConstraintError("s.object(T.when)", "Validator has no parent", parent, "Validator to have a parent"));
|
||||
}
|
||||
const isKeyArray = Array.isArray(key);
|
||||
const value = isKeyArray ? key.map((k) => get(parent, k)) : get(parent, key);
|
||||
const value = isKeyArray ? key.map((k) => get__default.default(parent, k)) : get__default.default(parent, key);
|
||||
const predicate = resolveBooleanIs(options, value, isKeyArray) ? options.then : options.otherwise;
|
||||
if (predicate) {
|
||||
return predicate(validator).run(input);
|
||||
|
@ -183,6 +189,11 @@ var BaseValidator = class {
|
|||
when(key, options) {
|
||||
return this.addConstraint(whenConstraint(key, options, this));
|
||||
}
|
||||
describe(description) {
|
||||
const clone = this.clone();
|
||||
clone.description = description;
|
||||
return clone;
|
||||
}
|
||||
run(value) {
|
||||
let result = this.handle(value);
|
||||
if (result.isErr())
|
||||
|
@ -203,6 +214,11 @@ var BaseValidator = class {
|
|||
is(value) {
|
||||
return this.run(value).isOk();
|
||||
}
|
||||
/**
|
||||
* Sets if the validator should also run constraints or just do basic checks.
|
||||
* @param isValidationEnabled Whether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing.
|
||||
* Set to `null` to go off of the global configuration.
|
||||
*/
|
||||
setValidationEnabled(isValidationEnabled) {
|
||||
const clone = this.clone();
|
||||
clone.isValidationEnabled = isValidationEnabled;
|
||||
|
@ -229,7 +245,7 @@ __name(BaseValidator, "BaseValidator");
|
|||
function isUnique(input) {
|
||||
if (input.length < 2)
|
||||
return true;
|
||||
const uniqueArray2 = uniqWith(input, fastDeepEqual);
|
||||
const uniqueArray2 = uniqWith__default.default(input, fastDeepEqual__default.default);
|
||||
return uniqueArray2.length === input.length;
|
||||
}
|
||||
__name(isUnique, "isUnique");
|
||||
|
@ -1092,7 +1108,7 @@ __name(UnionValidator, "UnionValidator");
|
|||
|
||||
// src/validators/ObjectValidator.ts
|
||||
var ObjectValidator = class extends BaseValidator {
|
||||
constructor(shape, strategy = ObjectValidatorStrategy.Ignore, constraints = []) {
|
||||
constructor(shape, strategy = 0 /* Ignore */, constraints = []) {
|
||||
super(constraints);
|
||||
this.keys = [];
|
||||
this.requiredKeys = /* @__PURE__ */ new Map();
|
||||
|
@ -1101,14 +1117,14 @@ var ObjectValidator = class extends BaseValidator {
|
|||
this.shape = shape;
|
||||
this.strategy = strategy;
|
||||
switch (this.strategy) {
|
||||
case ObjectValidatorStrategy.Ignore:
|
||||
case 0 /* Ignore */:
|
||||
this.handleStrategy = (value) => this.handleIgnoreStrategy(value);
|
||||
break;
|
||||
case ObjectValidatorStrategy.Strict: {
|
||||
case 1 /* Strict */: {
|
||||
this.handleStrategy = (value) => this.handleStrictStrategy(value);
|
||||
break;
|
||||
}
|
||||
case ObjectValidatorStrategy.Passthrough:
|
||||
case 2 /* Passthrough */:
|
||||
this.handleStrategy = (value) => this.handlePassthroughStrategy(value);
|
||||
break;
|
||||
}
|
||||
|
@ -1146,13 +1162,13 @@ var ObjectValidator = class extends BaseValidator {
|
|||
}
|
||||
}
|
||||
get strict() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Strict, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 1 /* Strict */, this.constraints]);
|
||||
}
|
||||
get ignore() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Ignore, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 0 /* Ignore */, this.constraints]);
|
||||
}
|
||||
get passthrough() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Passthrough, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 2 /* Passthrough */, this.constraints]);
|
||||
}
|
||||
get partial() {
|
||||
const shape = Object.fromEntries(this.keys.map((key) => [key, this.shape[key].optional]));
|
||||
|
@ -1296,12 +1312,6 @@ var ObjectValidator = class extends BaseValidator {
|
|||
}
|
||||
};
|
||||
__name(ObjectValidator, "ObjectValidator");
|
||||
var ObjectValidatorStrategy = /* @__PURE__ */ ((ObjectValidatorStrategy2) => {
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Ignore"] = 0] = "Ignore";
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Strict"] = 1] = "Strict";
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Passthrough"] = 2] = "Passthrough";
|
||||
return ObjectValidatorStrategy2;
|
||||
})(ObjectValidatorStrategy || {});
|
||||
|
||||
// src/validators/PassthroughValidator.ts
|
||||
var PassthroughValidator = class extends BaseValidator {
|
||||
|
@ -1592,7 +1602,7 @@ function stringUrl(options) {
|
|||
try {
|
||||
url = new URL(input);
|
||||
} catch {
|
||||
return Result.err(new ExpectedConstraintError("s.string.url", "Invalid URL", input, "expected to match an URL"));
|
||||
return Result.err(new ExpectedConstraintError("s.string.url", "Invalid URL", input, "expected to match a URL"));
|
||||
}
|
||||
const validatorFnResult = validatorFn(input, url);
|
||||
if (validatorFnResult === null)
|
||||
|
|
2
node_modules/@sapphire/shapeshift/dist/index.js.map
generated
vendored
2
node_modules/@sapphire/shapeshift/dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
34
node_modules/@sapphire/shapeshift/dist/index.mjs
generated
vendored
34
node_modules/@sapphire/shapeshift/dist/index.mjs
generated
vendored
|
@ -1,5 +1,5 @@
|
|||
import get from 'lodash/get.js';
|
||||
import { inspect } from 'node:util';
|
||||
import { inspect } from 'util';
|
||||
import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
||||
import uniqWith from 'lodash/uniqWith.js';
|
||||
|
||||
|
@ -181,6 +181,11 @@ var BaseValidator = class {
|
|||
when(key, options) {
|
||||
return this.addConstraint(whenConstraint(key, options, this));
|
||||
}
|
||||
describe(description) {
|
||||
const clone = this.clone();
|
||||
clone.description = description;
|
||||
return clone;
|
||||
}
|
||||
run(value) {
|
||||
let result = this.handle(value);
|
||||
if (result.isErr())
|
||||
|
@ -201,6 +206,11 @@ var BaseValidator = class {
|
|||
is(value) {
|
||||
return this.run(value).isOk();
|
||||
}
|
||||
/**
|
||||
* Sets if the validator should also run constraints or just do basic checks.
|
||||
* @param isValidationEnabled Whether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing.
|
||||
* Set to `null` to go off of the global configuration.
|
||||
*/
|
||||
setValidationEnabled(isValidationEnabled) {
|
||||
const clone = this.clone();
|
||||
clone.isValidationEnabled = isValidationEnabled;
|
||||
|
@ -1090,7 +1100,7 @@ __name(UnionValidator, "UnionValidator");
|
|||
|
||||
// src/validators/ObjectValidator.ts
|
||||
var ObjectValidator = class extends BaseValidator {
|
||||
constructor(shape, strategy = ObjectValidatorStrategy.Ignore, constraints = []) {
|
||||
constructor(shape, strategy = 0 /* Ignore */, constraints = []) {
|
||||
super(constraints);
|
||||
this.keys = [];
|
||||
this.requiredKeys = /* @__PURE__ */ new Map();
|
||||
|
@ -1099,14 +1109,14 @@ var ObjectValidator = class extends BaseValidator {
|
|||
this.shape = shape;
|
||||
this.strategy = strategy;
|
||||
switch (this.strategy) {
|
||||
case ObjectValidatorStrategy.Ignore:
|
||||
case 0 /* Ignore */:
|
||||
this.handleStrategy = (value) => this.handleIgnoreStrategy(value);
|
||||
break;
|
||||
case ObjectValidatorStrategy.Strict: {
|
||||
case 1 /* Strict */: {
|
||||
this.handleStrategy = (value) => this.handleStrictStrategy(value);
|
||||
break;
|
||||
}
|
||||
case ObjectValidatorStrategy.Passthrough:
|
||||
case 2 /* Passthrough */:
|
||||
this.handleStrategy = (value) => this.handlePassthroughStrategy(value);
|
||||
break;
|
||||
}
|
||||
|
@ -1144,13 +1154,13 @@ var ObjectValidator = class extends BaseValidator {
|
|||
}
|
||||
}
|
||||
get strict() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Strict, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 1 /* Strict */, this.constraints]);
|
||||
}
|
||||
get ignore() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Ignore, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 0 /* Ignore */, this.constraints]);
|
||||
}
|
||||
get passthrough() {
|
||||
return Reflect.construct(this.constructor, [this.shape, ObjectValidatorStrategy.Passthrough, this.constraints]);
|
||||
return Reflect.construct(this.constructor, [this.shape, 2 /* Passthrough */, this.constraints]);
|
||||
}
|
||||
get partial() {
|
||||
const shape = Object.fromEntries(this.keys.map((key) => [key, this.shape[key].optional]));
|
||||
|
@ -1294,12 +1304,6 @@ var ObjectValidator = class extends BaseValidator {
|
|||
}
|
||||
};
|
||||
__name(ObjectValidator, "ObjectValidator");
|
||||
var ObjectValidatorStrategy = /* @__PURE__ */ ((ObjectValidatorStrategy2) => {
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Ignore"] = 0] = "Ignore";
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Strict"] = 1] = "Strict";
|
||||
ObjectValidatorStrategy2[ObjectValidatorStrategy2["Passthrough"] = 2] = "Passthrough";
|
||||
return ObjectValidatorStrategy2;
|
||||
})(ObjectValidatorStrategy || {});
|
||||
|
||||
// src/validators/PassthroughValidator.ts
|
||||
var PassthroughValidator = class extends BaseValidator {
|
||||
|
@ -1590,7 +1594,7 @@ function stringUrl(options) {
|
|||
try {
|
||||
url = new URL(input);
|
||||
} catch {
|
||||
return Result.err(new ExpectedConstraintError("s.string.url", "Invalid URL", input, "expected to match an URL"));
|
||||
return Result.err(new ExpectedConstraintError("s.string.url", "Invalid URL", input, "expected to match a URL"));
|
||||
}
|
||||
const validatorFnResult = validatorFn(input, url);
|
||||
if (validatorFnResult === null)
|
||||
|
|
2
node_modules/@sapphire/shapeshift/dist/index.mjs.map
generated
vendored
2
node_modules/@sapphire/shapeshift/dist/index.mjs.map
generated
vendored
File diff suppressed because one or more lines are too long
70
node_modules/@sapphire/shapeshift/package.json
generated
vendored
70
node_modules/@sapphire/shapeshift/package.json
generated
vendored
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sapphire/shapeshift",
|
||||
"version": "3.8.1",
|
||||
"version": "3.9.2",
|
||||
"description": "Blazing fast input validation and transformation ⚡",
|
||||
"author": "@sapphire",
|
||||
"license": "MIT",
|
||||
|
@ -10,9 +10,9 @@
|
|||
"unpkg": "dist/index.global.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"homepage": "https://www.sapphirejs.dev",
|
||||
|
@ -21,8 +21,6 @@
|
|||
"format": "prettier --write \"{src,tests}/**/*.ts\"",
|
||||
"docs": "typedoc-json-parser",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"update": "yarn upgrade-interactive",
|
||||
"build": "tsup",
|
||||
"clean": "node scripts/clean.mjs",
|
||||
"typecheck": "tsc -p tsconfig.eslint.json",
|
||||
|
@ -32,38 +30,42 @@
|
|||
"prepack": "yarn build && pinst --disable",
|
||||
"postpack": "pinst --enable"
|
||||
},
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.3.0",
|
||||
"@commitlint/config-conventional": "^17.3.0",
|
||||
"@favware/cliff-jumper": "^1.9.0",
|
||||
"@commitlint/cli": "^17.6.5",
|
||||
"@commitlint/config-conventional": "^17.6.5",
|
||||
"@favware/cliff-jumper": "^2.0.1",
|
||||
"@favware/npm-deprecate": "^1.0.7",
|
||||
"@sapphire/eslint-config": "^4.3.8",
|
||||
"@sapphire/prettier-config": "^1.4.4",
|
||||
"@sapphire/ts-config": "^3.3.4",
|
||||
"@types/jsdom": "^20.0.1",
|
||||
"@types/lodash": "^4.14.191",
|
||||
"@types/node": "^18.11.13",
|
||||
"@typescript-eslint/eslint-plugin": "^5.46.0",
|
||||
"@typescript-eslint/parser": "^5.46.0",
|
||||
"@vitest/coverage-c8": "^0.25.7",
|
||||
"@sapphire/eslint-config": "^4.4.2",
|
||||
"@sapphire/prettier-config": "^1.4.5",
|
||||
"@sapphire/ts-config": "^4.0.0",
|
||||
"@types/jsdom": "^21.1.1",
|
||||
"@types/lodash": "^4.14.195",
|
||||
"@types/node": "^18.16.16",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.8",
|
||||
"@typescript-eslint/parser": "^5.59.8",
|
||||
"@vitest/coverage-c8": "^0.31.4",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"esbuild-plugins-node-modules-polyfill": "^1.0.7",
|
||||
"eslint": "^8.29.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"esbuild-plugins-node-modules-polyfill": "^1.0.14",
|
||||
"eslint": "^8.42.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"husky": "^8.0.2",
|
||||
"jsdom": "^20.0.3",
|
||||
"lint-staged": "^13.1.0",
|
||||
"husky": "^8.0.3",
|
||||
"jsdom": "^22.1.0",
|
||||
"lint-staged": "^13.2.2",
|
||||
"pinst": "^3.0.0",
|
||||
"prettier": "^2.8.1",
|
||||
"prettier": "^2.8.8",
|
||||
"pretty-quick": "^3.1.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsup": "^6.5.0",
|
||||
"typedoc": "^0.23.22",
|
||||
"typedoc-json-parser": "^7.0.2",
|
||||
"typescript": "^4.9.4",
|
||||
"vite": "^4.0.0",
|
||||
"vitest": "^0.25.7"
|
||||
"tsup": "^6.7.0",
|
||||
"typedoc": "^0.24.7",
|
||||
"typedoc-json-parser": "^8.1.2",
|
||||
"typescript": "^5.1.3",
|
||||
"vite": "^4.3.9",
|
||||
"vitest": "^0.31.4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -117,11 +119,7 @@
|
|||
},
|
||||
"resolutions": {
|
||||
"ansi-regex": "^5.0.1",
|
||||
"minimist": "^1.2.7"
|
||||
"minimist": "^1.2.8"
|
||||
},
|
||||
"packageManager": "yarn@3.3.0",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"lodash": "^4.17.21"
|
||||
}
|
||||
"packageManager": "yarn@3.6.0"
|
||||
}
|
31
node_modules/@sapphire/snowflake/CHANGELOG.md
generated
vendored
31
node_modules/@sapphire/snowflake/CHANGELOG.md
generated
vendored
|
@ -2,6 +2,37 @@
|
|||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [@sapphire/snowflake@3.5.1](https://github.com/sapphiredev/utilities/compare/@sapphire/snowflake@3.5.0...@sapphire/snowflake@3.5.1) - (2023-05-12)
|
||||
|
||||
## 🏠 Refactor
|
||||
|
||||
- **snowflake:** Handle out-of-bounds `increment` correctly (#596) ([b5276d7](https://github.com/sapphiredev/utilities/commit/b5276d7372c33356975a302bafb5ae8aba604431))
|
||||
|
||||
# [@sapphire/snowflake@3.5.0](https://github.com/sapphiredev/utilities/compare/@sapphire/snowflake@3.4.3...@sapphire/snowflake@3.5.0) - (2023-05-10)
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- **snowflake:** Expose `processId` and `workerId` (#595) ([b873c1c](https://github.com/sapphiredev/utilities/commit/b873c1cc3b30cb54d710a49f7618e125ac1132ad))
|
||||
|
||||
# [@sapphire/snowflake@3.4.2](https://github.com/sapphiredev/utilities/compare/@sapphire/snowflake@3.4.1...@sapphire/snowflake@3.4.2) - (2023-04-12)
|
||||
|
||||
## 🏠 Refactor
|
||||
|
||||
- **Snowflake:** Simplify `compare` logic (#578) ([886254e](https://github.com/sapphiredev/utilities/commit/886254eea2f0cc5e8f63d015acffaf0e61489357))
|
||||
|
||||
# [@sapphire/snowflake@3.4.1](https://github.com/sapphiredev/utilities/compare/@sapphire/snowflake@3.4.0...@sapphire/snowflake@3.4.1) - (2023-04-10)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **snowflake:** Ensure strings are never compared with bigints ([22199a5](https://github.com/sapphiredev/utilities/commit/22199a5aa0c6150f46e01bfbe328deecb9f818ba))
|
||||
- **deps:** Update all non-major dependencies (#577) ([291dd67](https://github.com/sapphiredev/utilities/commit/291dd6783e57d8f075ce566218ba076ef6c4bbbd))
|
||||
- **deps:** Update all non-major dependencies (#545) ([40ca040](https://github.com/sapphiredev/utilities/commit/40ca040a21d8a0949682051a3a974538183a400e))
|
||||
- **deps:** Update all non-major dependencies (#544) ([cc78f17](https://github.com/sapphiredev/utilities/commit/cc78f17390c7f3db08af92bf46a5a70a9c11dd5f))
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
- Cleanup tests ([aec1bb2](https://github.com/sapphiredev/utilities/commit/aec1bb290d0f3c00a1ae4f4c86302ebbb161d348))
|
||||
|
||||
# [@sapphire/snowflake@3.4.0](https://github.com/sapphiredev/utilities/compare/@sapphire/snowflake@3.3.0...@sapphire/snowflake@3.4.0) - (2022-12-27)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
|
80
node_modules/@sapphire/snowflake/README.md
generated
vendored
80
node_modules/@sapphire/snowflake/README.md
generated
vendored
|
@ -1,6 +1,6 @@
|
|||
<div align="center">
|
||||
|
||||

|
||||

|
||||
|
||||
# @sapphire/snowflake
|
||||
|
||||
|
@ -157,78 +157,14 @@ We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub S
|
|||
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
|
||||
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
|
||||
|
||||
## Contributors ✨
|
||||
## Contributors
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
Please make sure to read the [Contributing Guide][contributing] before making a pull request.
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">💻</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#projectManagement-favna" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">📖</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura Román</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">💻</a> <a href="#projectManagement-kyranet" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">🐛</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">👀</a> <a href="#userTesting-vladfrangu" title="User Testing">📓</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">💻</a> <a href="#projectManagement-Stitch07" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">💻</a> <a href="#tool-RealShadowNova" title="Tools">🔧</a></td>
|
||||
<td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=megatank58" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">📖</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jérémy de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">🐛</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes Genç</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/r-priyam"><img src="https://avatars.githubusercontent.com/u/50884372?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Priyam</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=r-priyam" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/legendhimslef"><img src="https://avatars.githubusercontent.com/u/69213593?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Voxelli</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=legendhimslef" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/CitTheDev"><img src="https://avatars.githubusercontent.com/u/94020875?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Cit The Dev</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=CitTheDev" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://www.goestav.com/"><img src="https://avatars.githubusercontent.com/u/27970303?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Goestav</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=goestav" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/didinele"><img src="https://avatars.githubusercontent.com/u/27137376?v=4?s=100" width="100px;" alt=""/><br /><sub><b>DD</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=didinele" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://steamcommunity.com/id/06000208"><img src="https://avatars.githubusercontent.com/u/52764066?v=4?s=100" width="100px;" alt=""/><br /><sub><b>amber</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=06000208" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
Thank you to all the people who already contributed to Sapphire!
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
<!-- prettier-ignore-end -->
|
||||
<a href="https://github.com/sapphiredev/utilities/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=sapphiredev/utilities" />
|
||||
</a>
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md
|
||||
|
|
59
node_modules/@sapphire/snowflake/dist/index.d.ts
generated
vendored
59
node_modules/@sapphire/snowflake/dist/index.d.ts
generated
vendored
|
@ -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 };
|
||||
|
|
200
node_modules/@sapphire/snowflake/dist/index.global.js
generated
vendored
200
node_modules/@sapphire/snowflake/dist/index.global.js
generated
vendored
|
@ -8,48 +8,98 @@ var SapphireSnowflake = (function (exports) {
|
|||
__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 IncrementSymbol = Symbol("@sapphire/snowflake.increment");
|
||||
var EpochSymbol = Symbol("@sapphire/snowflake.epoch");
|
||||
var ProcessIdSymbol = Symbol("@sapphire/snowflake.processId");
|
||||
var WorkerIdSymbol = Symbol("@sapphire/snowflake.workerId");
|
||||
var MaximumWorkerId = 0b11111n;
|
||||
var MaximumProcessId = 0b11111n;
|
||||
var MaximumIncrement = 0b111111111111n;
|
||||
var _a, _b, _c, _d;
|
||||
var Snowflake = class {
|
||||
/**
|
||||
* @param epoch the epoch to use
|
||||
*/
|
||||
constructor(epoch) {
|
||||
/**
|
||||
* Alias for {@link deconstruct}
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
/**
|
||||
* Internal reference of the epoch passed in the constructor
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _a);
|
||||
/**
|
||||
* Internal incrementor for generating snowflakes
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _b, 0n);
|
||||
/**
|
||||
* The process ID that will be used by default in the generate method
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _c, 1n);
|
||||
/**
|
||||
* The worker ID that will be used by default in the generate method
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _d, 0n);
|
||||
this[EpochSymbol] = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);
|
||||
}
|
||||
/**
|
||||
* The epoch for this snowflake
|
||||
*/
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
return this[EpochSymbol];
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
/**
|
||||
* Gets the configured process ID
|
||||
*/
|
||||
get processId() {
|
||||
return this[ProcessIdSymbol];
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
this[ProcessIdSymbol] = BigInt(value) & MaximumProcessId;
|
||||
}
|
||||
/**
|
||||
* Gets the configured worker ID
|
||||
*/
|
||||
get workerId() {
|
||||
return this[WorkerIdSymbol];
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
this[WorkerIdSymbol] = BigInt(value) & MaximumWorkerId;
|
||||
}
|
||||
/**
|
||||
* 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 = Date.now(),
|
||||
workerId = this[WorkerIdSymbol],
|
||||
processId = this[ProcessIdSymbol]
|
||||
} = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
|
@ -57,43 +107,76 @@ var SapphireSnowflake = (function (exports) {
|
|||
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);
|
||||
if (typeof increment !== "bigint") {
|
||||
increment = this[IncrementSymbol];
|
||||
this[IncrementSymbol] = increment + 1n & MaximumIncrement;
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
return timestamp - this[EpochSymbol] << 22n | (workerId & MaximumWorkerId) << 17n | (processId & MaximumProcessId) << 12n | increment & MaximumIncrement;
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
const bigIntId = BigInt(id);
|
||||
const epoch = this[EpochSymbol];
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
timestamp: (bigIntId >> 22n) + epoch,
|
||||
workerId: bigIntId >> 17n & MaximumWorkerId,
|
||||
processId: bigIntId >> 12n & MaximumProcessId,
|
||||
increment: bigIntId & MaximumIncrement,
|
||||
epoch
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
return Number((BigInt(id) >> 22n) + this[EpochSymbol]);
|
||||
}
|
||||
/**
|
||||
* 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, 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;
|
||||
const typeA = typeof a;
|
||||
return typeA === typeof b ? typeA === "string" ? cmpString(a, b) : cmpBigInt(a, b) : cmpBigInt(BigInt(a), BigInt(b));
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
_a = EpochSymbol, _b = IncrementSymbol, _c = ProcessIdSymbol, _d = WorkerIdSymbol;
|
||||
function cmpBigInt(a, b) {
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
__name(cmpBigInt, "cmpBigInt");
|
||||
function cmpString(a, b) {
|
||||
return a === b ? 0 : a.length < b.length ? -1 : a.length > b.length ? 1 : a < b ? -1 : 1;
|
||||
}
|
||||
__name(cmpString, "cmpString");
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
@ -102,6 +185,9 @@ var SapphireSnowflake = (function (exports) {
|
|||
var TwitterSnowflake = new Snowflake(1288834974657n);
|
||||
|
||||
exports.DiscordSnowflake = DiscordSnowflake;
|
||||
exports.MaximumIncrement = MaximumIncrement;
|
||||
exports.MaximumProcessId = MaximumProcessId;
|
||||
exports.MaximumWorkerId = MaximumWorkerId;
|
||||
exports.Snowflake = Snowflake;
|
||||
exports.TwitterSnowflake = TwitterSnowflake;
|
||||
|
||||
|
|
2
node_modules/@sapphire/snowflake/dist/index.global.js.map
generated
vendored
2
node_modules/@sapphire/snowflake/dist/index.global.js.map
generated
vendored
File diff suppressed because one or more lines are too long
200
node_modules/@sapphire/snowflake/dist/index.js
generated
vendored
200
node_modules/@sapphire/snowflake/dist/index.js
generated
vendored
|
@ -7,48 +7,98 @@ 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 IncrementSymbol = Symbol("@sapphire/snowflake.increment");
|
||||
var EpochSymbol = Symbol("@sapphire/snowflake.epoch");
|
||||
var ProcessIdSymbol = Symbol("@sapphire/snowflake.processId");
|
||||
var WorkerIdSymbol = Symbol("@sapphire/snowflake.workerId");
|
||||
var MaximumWorkerId = 0b11111n;
|
||||
var MaximumProcessId = 0b11111n;
|
||||
var MaximumIncrement = 0b111111111111n;
|
||||
var _a, _b, _c, _d;
|
||||
var Snowflake = class {
|
||||
/**
|
||||
* @param epoch the epoch to use
|
||||
*/
|
||||
constructor(epoch) {
|
||||
/**
|
||||
* Alias for {@link deconstruct}
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
/**
|
||||
* Internal reference of the epoch passed in the constructor
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _a);
|
||||
/**
|
||||
* Internal incrementor for generating snowflakes
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _b, 0n);
|
||||
/**
|
||||
* The process ID that will be used by default in the generate method
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _c, 1n);
|
||||
/**
|
||||
* The worker ID that will be used by default in the generate method
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _d, 0n);
|
||||
this[EpochSymbol] = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);
|
||||
}
|
||||
/**
|
||||
* The epoch for this snowflake
|
||||
*/
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
return this[EpochSymbol];
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
/**
|
||||
* Gets the configured process ID
|
||||
*/
|
||||
get processId() {
|
||||
return this[ProcessIdSymbol];
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
this[ProcessIdSymbol] = BigInt(value) & MaximumProcessId;
|
||||
}
|
||||
/**
|
||||
* Gets the configured worker ID
|
||||
*/
|
||||
get workerId() {
|
||||
return this[WorkerIdSymbol];
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
this[WorkerIdSymbol] = BigInt(value) & MaximumWorkerId;
|
||||
}
|
||||
/**
|
||||
* 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 = Date.now(),
|
||||
workerId = this[WorkerIdSymbol],
|
||||
processId = this[ProcessIdSymbol]
|
||||
} = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
|
@ -56,43 +106,76 @@ var Snowflake = class {
|
|||
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);
|
||||
if (typeof increment !== "bigint") {
|
||||
increment = this[IncrementSymbol];
|
||||
this[IncrementSymbol] = increment + 1n & MaximumIncrement;
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
return timestamp - this[EpochSymbol] << 22n | (workerId & MaximumWorkerId) << 17n | (processId & MaximumProcessId) << 12n | increment & MaximumIncrement;
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
const bigIntId = BigInt(id);
|
||||
const epoch = this[EpochSymbol];
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
timestamp: (bigIntId >> 22n) + epoch,
|
||||
workerId: bigIntId >> 17n & MaximumWorkerId,
|
||||
processId: bigIntId >> 12n & MaximumProcessId,
|
||||
increment: bigIntId & MaximumIncrement,
|
||||
epoch
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
return Number((BigInt(id) >> 22n) + this[EpochSymbol]);
|
||||
}
|
||||
/**
|
||||
* 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, 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;
|
||||
const typeA = typeof a;
|
||||
return typeA === typeof b ? typeA === "string" ? cmpString(a, b) : cmpBigInt(a, b) : cmpBigInt(BigInt(a), BigInt(b));
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
_a = EpochSymbol, _b = IncrementSymbol, _c = ProcessIdSymbol, _d = WorkerIdSymbol;
|
||||
function cmpBigInt(a, b) {
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
__name(cmpBigInt, "cmpBigInt");
|
||||
function cmpString(a, b) {
|
||||
return a === b ? 0 : a.length < b.length ? -1 : a.length > b.length ? 1 : a < b ? -1 : 1;
|
||||
}
|
||||
__name(cmpString, "cmpString");
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
@ -101,6 +184,9 @@ var DiscordSnowflake = new Snowflake(1420070400000n);
|
|||
var TwitterSnowflake = new Snowflake(1288834974657n);
|
||||
|
||||
exports.DiscordSnowflake = DiscordSnowflake;
|
||||
exports.MaximumIncrement = MaximumIncrement;
|
||||
exports.MaximumProcessId = MaximumProcessId;
|
||||
exports.MaximumWorkerId = MaximumWorkerId;
|
||||
exports.Snowflake = Snowflake;
|
||||
exports.TwitterSnowflake = TwitterSnowflake;
|
||||
//# sourceMappingURL=out.js.map
|
||||
|
|
2
node_modules/@sapphire/snowflake/dist/index.js.map
generated
vendored
2
node_modules/@sapphire/snowflake/dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
199
node_modules/@sapphire/snowflake/dist/index.mjs
generated
vendored
199
node_modules/@sapphire/snowflake/dist/index.mjs
generated
vendored
|
@ -5,48 +5,98 @@ 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 IncrementSymbol = Symbol("@sapphire/snowflake.increment");
|
||||
var EpochSymbol = Symbol("@sapphire/snowflake.epoch");
|
||||
var ProcessIdSymbol = Symbol("@sapphire/snowflake.processId");
|
||||
var WorkerIdSymbol = Symbol("@sapphire/snowflake.workerId");
|
||||
var MaximumWorkerId = 0b11111n;
|
||||
var MaximumProcessId = 0b11111n;
|
||||
var MaximumIncrement = 0b111111111111n;
|
||||
var _a, _b, _c, _d;
|
||||
var Snowflake = class {
|
||||
/**
|
||||
* @param epoch the epoch to use
|
||||
*/
|
||||
constructor(epoch) {
|
||||
/**
|
||||
* Alias for {@link deconstruct}
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
/**
|
||||
* Internal reference of the epoch passed in the constructor
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _a);
|
||||
/**
|
||||
* Internal incrementor for generating snowflakes
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _b, 0n);
|
||||
/**
|
||||
* The process ID that will be used by default in the generate method
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _c, 1n);
|
||||
/**
|
||||
* The worker ID that will be used by default in the generate method
|
||||
* @internal
|
||||
*/
|
||||
__publicField(this, _d, 0n);
|
||||
this[EpochSymbol] = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);
|
||||
}
|
||||
/**
|
||||
* The epoch for this snowflake
|
||||
*/
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
return this[EpochSymbol];
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
/**
|
||||
* Gets the configured process ID
|
||||
*/
|
||||
get processId() {
|
||||
return this[ProcessIdSymbol];
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
this[ProcessIdSymbol] = BigInt(value) & MaximumProcessId;
|
||||
}
|
||||
/**
|
||||
* Gets the configured worker ID
|
||||
*/
|
||||
get workerId() {
|
||||
return this[WorkerIdSymbol];
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
this[WorkerIdSymbol] = BigInt(value) & MaximumWorkerId;
|
||||
}
|
||||
/**
|
||||
* 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 = Date.now(),
|
||||
workerId = this[WorkerIdSymbol],
|
||||
processId = this[ProcessIdSymbol]
|
||||
} = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
|
@ -54,43 +104,76 @@ var Snowflake = class {
|
|||
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);
|
||||
if (typeof increment !== "bigint") {
|
||||
increment = this[IncrementSymbol];
|
||||
this[IncrementSymbol] = increment + 1n & MaximumIncrement;
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
return timestamp - this[EpochSymbol] << 22n | (workerId & MaximumWorkerId) << 17n | (processId & MaximumProcessId) << 12n | increment & MaximumIncrement;
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
const bigIntId = BigInt(id);
|
||||
const epoch = this[EpochSymbol];
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
timestamp: (bigIntId >> 22n) + epoch,
|
||||
workerId: bigIntId >> 17n & MaximumWorkerId,
|
||||
processId: bigIntId >> 12n & MaximumProcessId,
|
||||
increment: bigIntId & MaximumIncrement,
|
||||
epoch
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
return Number((BigInt(id) >> 22n) + this[EpochSymbol]);
|
||||
}
|
||||
/**
|
||||
* 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, 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;
|
||||
const typeA = typeof a;
|
||||
return typeA === typeof b ? typeA === "string" ? cmpString(a, b) : cmpBigInt(a, b) : cmpBigInt(BigInt(a), BigInt(b));
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
_a = EpochSymbol, _b = IncrementSymbol, _c = ProcessIdSymbol, _d = WorkerIdSymbol;
|
||||
function cmpBigInt(a, b) {
|
||||
return a === b ? 0 : a < b ? -1 : 1;
|
||||
}
|
||||
__name(cmpBigInt, "cmpBigInt");
|
||||
function cmpString(a, b) {
|
||||
return a === b ? 0 : a.length < b.length ? -1 : a.length > b.length ? 1 : a < b ? -1 : 1;
|
||||
}
|
||||
__name(cmpString, "cmpString");
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
@ -98,6 +181,6 @@ var DiscordSnowflake = new Snowflake(1420070400000n);
|
|||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1288834974657n);
|
||||
|
||||
export { DiscordSnowflake, Snowflake, TwitterSnowflake };
|
||||
export { DiscordSnowflake, MaximumIncrement, MaximumProcessId, MaximumWorkerId, Snowflake, TwitterSnowflake };
|
||||
//# sourceMappingURL=out.js.map
|
||||
//# sourceMappingURL=index.mjs.map
|
2
node_modules/@sapphire/snowflake/dist/index.mjs.map
generated
vendored
2
node_modules/@sapphire/snowflake/dist/index.mjs.map
generated
vendored
File diff suppressed because one or more lines are too long
16
node_modules/@sapphire/snowflake/package.json
generated
vendored
16
node_modules/@sapphire/snowflake/package.json
generated
vendored
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sapphire/snowflake",
|
||||
"version": "3.4.0",
|
||||
"version": "3.5.1",
|
||||
"description": "Deconstructs and generates snowflake IDs using BigInts",
|
||||
"author": "@sapphire",
|
||||
"license": "MIT",
|
||||
|
@ -56,12 +56,12 @@
|
|||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "^1.9.0",
|
||||
"@vitest/coverage-c8": "^0.26.2",
|
||||
"tsup": "^6.5.0",
|
||||
"typedoc": "^0.23.23",
|
||||
"typedoc-json-parser": "^7.0.2",
|
||||
"typescript": "^4.9.4",
|
||||
"vitest": "^0.26.2"
|
||||
"@favware/cliff-jumper": "^2.0.0",
|
||||
"@vitest/coverage-c8": "^0.31.0",
|
||||
"tsup": "^6.7.0",
|
||||
"typedoc": "^0.24.7",
|
||||
"typedoc-json-parser": "^7.4.0",
|
||||
"typescript": "^5.0.4",
|
||||
"vitest": "^0.31.0"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue