@discordkit/core 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/requests/toProcedure.d.ts +8 -8
- package/dist/requests/toProcedure.js +24 -14
- package/dist/requests/toProcedure.js.map +1 -1
- package/dist/utils/isBetween.d.ts +1 -0
- package/dist/utils/isBetween.js +2 -0
- package/dist/utils/isBetween.js.map +1 -0
- package/dist/utils/isNumericString.d.ts +1 -0
- package/dist/utils/isNumericString.js +2 -0
- package/dist/utils/isNumericString.js.map +1 -0
- package/dist/validations/asDigits.d.ts +5 -2
- package/dist/validations/asDigits.js +5 -2
- package/dist/validations/asDigits.js.map +1 -1
- package/dist/validations/asInteger.d.ts +5 -2
- package/dist/validations/asInteger.js +5 -2
- package/dist/validations/asInteger.js.map +1 -1
- package/dist/validations/bitfield.d.ts +13 -1
- package/dist/validations/bitfield.js +15 -2
- package/dist/validations/bitfield.js.map +1 -1
- package/dist/validations/boundedArray.d.ts +6 -0
- package/dist/validations/boundedArray.js +8 -0
- package/dist/validations/boundedArray.js.map +1 -0
- package/dist/validations/boundedInteger.d.ts +6 -0
- package/dist/validations/boundedInteger.js +8 -0
- package/dist/validations/boundedInteger.js.map +1 -0
- package/dist/validations/boundedString.d.ts +6 -0
- package/dist/validations/boundedString.js +8 -0
- package/dist/validations/boundedString.js.map +1 -0
- package/dist/validations/datauri.d.ts +2 -1
- package/dist/validations/datauri.js +2 -2
- package/dist/validations/datauri.js.map +1 -1
- package/dist/validations/index.d.ts +5 -0
- package/dist/validations/index.js +5 -0
- package/dist/validations/index.js.map +1 -1
- package/dist/validations/snowflake.d.ts +10 -11
- package/dist/validations/snowflake.js +21 -16
- package/dist/validations/snowflake.js.map +1 -1
- package/dist/validations/timestamp.d.ts +3 -0
- package/dist/validations/timestamp.js +4 -0
- package/dist/validations/timestamp.js.map +1 -0
- package/dist/validations/url.d.ts +2 -0
- package/dist/validations/url.js +3 -0
- package/dist/validations/url.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as v from "valibot";
|
|
2
2
|
import type { AnyProcedureBuilder, MutationProcedure, ProcedureType, QueryProcedure, SubscriptionProcedure } from "@trpc/server/unstable-core-do-not-import";
|
|
3
3
|
import type { Fetcher } from "./methods.js";
|
|
4
|
-
type Result<T = void> = T extends GenericSchema | GenericSchemaAsync ? InferOutput<T> : T;
|
|
5
|
-
type Schema = GenericSchema | GenericSchemaAsync;
|
|
4
|
+
type Result<T = void> = T extends v.GenericSchema | v.GenericSchemaAsync ? v.InferOutput<T> : T;
|
|
5
|
+
type Schema = v.GenericSchema | v.GenericSchemaAsync;
|
|
6
6
|
type ProvedureDef<I extends Schema | null = null, O extends Schema | null = null> = I extends Schema ? O extends Schema ? {
|
|
7
|
-
input: InferInput<I>;
|
|
8
|
-
output: InferOutput<O>;
|
|
7
|
+
input: v.InferInput<I>;
|
|
8
|
+
output: v.InferOutput<O>;
|
|
9
9
|
meta: unknown;
|
|
10
10
|
} : {
|
|
11
|
-
input: InferInput<I>;
|
|
11
|
+
input: v.InferInput<I>;
|
|
12
12
|
output: undefined;
|
|
13
13
|
meta: unknown;
|
|
14
14
|
} : O extends Schema ? {
|
|
15
15
|
input: undefined;
|
|
16
|
-
output: InferOutput<O>;
|
|
16
|
+
output: v.InferOutput<O>;
|
|
17
17
|
meta: unknown;
|
|
18
18
|
} : {
|
|
19
19
|
input: undefined;
|
|
@@ -27,5 +27,5 @@ type BaseProcedure<T extends ProcedureType, I extends Schema | null = null, O ex
|
|
|
27
27
|
* builder of the given procedure type. This can then be used in a tRPC router
|
|
28
28
|
* to scaffold an API route to forward a request to Discord's API.
|
|
29
29
|
*/
|
|
30
|
-
export declare const toProcedure: <T extends ProcedureType, I extends
|
|
30
|
+
export declare const toProcedure: <T extends ProcedureType, I extends Schema | null = null, O extends Schema | null = null>(type: T, fn: Fetcher<I extends Schema ? I : null, Result<O>>, input?: I, output?: O) => (procedure: AnyProcedureBuilder, errorHandler?: (error: unknown) => void) => BaseProcedure<T, I, O>;
|
|
31
31
|
export {};
|
|
@@ -5,22 +5,32 @@ import { isNonNullable } from "../utils/isNonNullable.js";
|
|
|
5
5
|
* builder of the given procedure type. This can then be used in a tRPC router
|
|
6
6
|
* to scaffold an API route to forward a request to Discord's API.
|
|
7
7
|
*/
|
|
8
|
-
export const toProcedure = (type, fn, input, output) => (procedure) => {
|
|
9
|
-
|
|
8
|
+
export const toProcedure = (type, fn, input, output) => (procedure, errorHandler) => {
|
|
9
|
+
try {
|
|
10
|
+
if (isNonNullable(input) && isNonNullable(output)) {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
return procedure
|
|
13
|
+
.input(input)
|
|
14
|
+
.output(output)[type](async (opts) => fn(opts.input));
|
|
15
|
+
}
|
|
16
|
+
if (isNonNullable(input) && !isNonNullable(output)) {
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
return procedure.input(input)[type](async (opts) => fn(opts.input));
|
|
19
|
+
}
|
|
20
|
+
if (!isNonNullable(input) && isNonNullable(output)) {
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
return procedure.output(output)[type](async () => fn());
|
|
23
|
+
}
|
|
10
24
|
// @ts-expect-error
|
|
11
|
-
return procedure
|
|
12
|
-
.input(input)
|
|
13
|
-
.output(output)[type](async (opts) => fn(opts.input));
|
|
25
|
+
return procedure[type](async () => fn());
|
|
14
26
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (typeof errorHandler === `function`) {
|
|
29
|
+
errorHandler(error);
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Unhandled Procedure Error!`, {
|
|
32
|
+
cause: error
|
|
33
|
+
});
|
|
22
34
|
}
|
|
23
|
-
// @ts-expect-error
|
|
24
|
-
return procedure[type](async () => fn());
|
|
25
35
|
};
|
|
26
36
|
//# sourceMappingURL=toProcedure.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toProcedure.js","sourceRoot":"","sources":["../../src/requests/toProcedure.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toProcedure.js","sourceRoot":"","sources":["../../src/requests/toProcedure.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAsC1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,CAKE,IAAO,EACP,EAAmD,EACnD,KAAS,EACT,MAAU,EACV,EAAE,CACJ,CACE,SAA8B,EAC9B,YAAuC,EACf,EAAE;IAC1B,IAAI,CAAC;QACH,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,mBAAmB;YACnB,OAAO,SAAS;iBACb,KAAK,CAAC,KAAK,CAAC;iBACZ,MAAM,CAAC,MAAM,CAAC,CACd,IAAI,CAAC,CAAC,KAAK,EAAE,IAAwB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YACnD,mBAAmB;YACnB,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YACnD,mBAAmB;YACnB,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,mBAAmB;QACnB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE,CAAC;YACvC,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,EAAE;YAC5C,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isBetween: (val: number, min: number, max: number) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isBetween.js","sourceRoot":"","sources":["../../src/utils/isBetween.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW,EAAW,EAAE,CAC1E,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isNumericString: (val: unknown) => val is string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNumericString.js","sourceRoot":"","sources":["../../src/utils/isNumericString.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAY,EAAiB,EAAE,CAC7D,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
import type { bitfield } from "./bitfield.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a `bitfield` schema into a numeric string
|
|
5
|
+
*/
|
|
6
|
+
export declare const asDigits: (schema: ReturnType<typeof bitfield>) => v.GenericSchema<string>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms a `bitfield` schema into a numeric string
|
|
4
|
+
*/
|
|
5
|
+
export const asDigits = (schema) => v.pipe(schema, v.transform((val) => val.toString()), v.digits());
|
|
3
6
|
//# sourceMappingURL=asDigits.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asDigits.js","sourceRoot":"","sources":["../../src/validations/asDigits.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asDigits.js","sourceRoot":"","sources":["../../src/validations/asDigits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,MAAmC,EACV,EAAE,CAC3B,CAAC,CAAC,IAAI,CACJ,MAAM,EACN,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,EACpC,CAAC,CAAC,MAAM,EAAE,CACgB,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
import type { bitfield } from "./bitfield.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a `bitfield` schema into an integer
|
|
5
|
+
*/
|
|
6
|
+
export declare const asInteger: (schema: ReturnType<typeof bitfield>) => v.GenericSchema<number>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms a `bitfield` schema into an integer
|
|
4
|
+
*/
|
|
5
|
+
export const asInteger = (schema) => v.pipe(schema, v.transform((val) => parseInt(val.toString(), 10)), v.integer());
|
|
3
6
|
//# sourceMappingURL=asInteger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asInteger.js","sourceRoot":"","sources":["../../src/validations/asInteger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asInteger.js","sourceRoot":"","sources":["../../src/validations/asInteger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,MAAmC,EACV,EAAE,CAC3B,CAAC,CAAC,IAAI,CACJ,MAAM,EACN,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,EAClD,CAAC,CAAC,OAAO,EAAE,CACe,CAAC"}
|
|
@@ -2,4 +2,16 @@ import { type SchemaWithPipe, type TitleAction, type CustomSchema } from "valibo
|
|
|
2
2
|
export interface Flags {
|
|
3
3
|
[key: string]: number | bigint | string;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Given an enum of bitwise flags, creates a new schema that
|
|
7
|
+
* can validate a [bitfield](https://en.wikipedia.org/wiki/Bit_field)
|
|
8
|
+
* numeric value (a data structure for efficiently serializing a
|
|
9
|
+
* group of boolean values).
|
|
10
|
+
*/
|
|
11
|
+
export declare const bitfield: <TName extends string>(
|
|
12
|
+
/** A name to differentiate this custom schema */
|
|
13
|
+
name: TName,
|
|
14
|
+
/** An enum of bitwise flags */
|
|
15
|
+
flags: Flags,
|
|
16
|
+
/** An optional error message to display in the event an invalid value is parsed */
|
|
17
|
+
message?: string) => SchemaWithPipe<readonly [CustomSchema<string | number | bigint, string>, TitleAction<string | number | bigint, TName>]>;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { custom, pipe, title } from "valibot";
|
|
2
2
|
import { isNonNullable } from "../utils/isNonNullable.js";
|
|
3
|
-
|
|
3
|
+
import { isNumericString } from "../utils/isNumericString.js";
|
|
4
|
+
/**
|
|
5
|
+
* Given an enum of bitwise flags, creates a new schema that
|
|
6
|
+
* can validate a [bitfield](https://en.wikipedia.org/wiki/Bit_field)
|
|
7
|
+
* numeric value (a data structure for efficiently serializing a
|
|
8
|
+
* group of boolean values).
|
|
9
|
+
*/
|
|
10
|
+
export const bitfield = (
|
|
11
|
+
/** A name to differentiate this custom schema */
|
|
12
|
+
name,
|
|
13
|
+
/** An enum of bitwise flags */
|
|
14
|
+
flags,
|
|
15
|
+
/** An optional error message to display in the event an invalid value is parsed */
|
|
16
|
+
message = `Invalid Bitfield`) => {
|
|
4
17
|
// because enums are bidirectionally indexed, pick only the numerical values
|
|
5
18
|
const flagValues = Object.values(flags).filter(
|
|
6
19
|
// flag enums have numerical values, so remove all the key name strings
|
|
@@ -16,7 +29,7 @@ export const bitfield = (name, flags, message = `Invalid Bitfield`) => {
|
|
|
16
29
|
// only work on supported types
|
|
17
30
|
(typeof val === `number` ||
|
|
18
31
|
typeof val === `bigint` ||
|
|
19
|
-
|
|
32
|
+
isNumericString(val))
|
|
20
33
|
? // validate the value against the given flags
|
|
21
34
|
(BigInt(val) & mask) === BigInt(val)
|
|
22
35
|
: false, message), title(name));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitfield.js","sourceRoot":"","sources":["../../src/validations/bitfield.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,KAAK,EAIN,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"bitfield.js","sourceRoot":"","sources":["../../src/validations/bitfield.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,KAAK,EAIN,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAM9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;AACtB,iDAAiD;AACjD,IAAW;AACX,+BAA+B;AAC/B,KAAY;AACZ,mFAAmF;AACnF,UAAkB,kBAAkB,EAMpC,EAAE;IACF,4EAA4E;IAC5E,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM;IAC5C,uEAAuE;IACvE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAC/B,CAAC;IACF,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,gDAAgD;IAChD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAC5B,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,EACrC,EAAE,CACH,CAAC;IACF,OAAO,IAAI,CACT,MAAM,CACJ,CAAC,GAAG,EAAE,EAAE;IACN,oCAAoC;IACpC,aAAa,CAAC,GAAG,CAAC;QAClB,+BAA+B;QAC/B,CAAC,OAAO,GAAG,KAAK,QAAQ;YACtB,OAAO,GAAG,KAAK,QAAQ;YACvB,eAAe,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC,6CAA6C;YAC7C,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC;QACtC,CAAC,CAAC,KAAK,EACX,OAAO,CACR,EACD,KAAK,CAAC,IAAI,CAAC,CACZ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** A non-empty array with a length within the given bounds */
|
|
3
|
+
export const boundedArray = (items, req = {}) => v.message(typeof req === `number`
|
|
4
|
+
? v.pipe(v.array(items), v.length(req))
|
|
5
|
+
: typeof req.max === `number`
|
|
6
|
+
? v.pipe(v.array(items), v.minLength(req.min ?? 1), v.maxLength(req.max))
|
|
7
|
+
: v.pipe(v.array(items), v.minLength(req.min ?? 1)), (issue) => `Expected an array with a legnth ${typeof req === `number` ? req : `>= ${req.min ?? 0}${req.max ? `&& <= ${req.max}` : ``}`}, received has length: ${issue.received.length}`);
|
|
8
|
+
//# sourceMappingURL=boundedArray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundedArray.js","sourceRoot":"","sources":["../../src/validations/boundedArray.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,8DAA8D;AAC9D,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAA6B,EAC7B,MAA+C,EAAE,EACvB,EAAE,CAC5B,CAAC,CAAC,OAAO,CACP,OAAO,GAAG,KAAK,QAAQ;IACrB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ;QAC3B,CAAC,CAAC,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EACd,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,EACzB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CACrB;QACH,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EACvD,CAAC,KAAK,EAAE,EAAE,CACR,mCAAmC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,0BAA0B,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAC/K,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** An integer with a value within the given bounds */
|
|
3
|
+
export const boundedInteger = (req = {}) => v.message(typeof req === `number`
|
|
4
|
+
? v.pipe(v.number(), v.integer(), v.value(req))
|
|
5
|
+
: typeof req.max === `number`
|
|
6
|
+
? v.pipe(v.number(), v.integer(), v.minValue(req.min ?? 0), v.maxValue(req.max))
|
|
7
|
+
: v.pipe(v.number(), v.integer(), v.minValue(req.min ?? 0)), (issue) => `Expected an integer with a value ${typeof req === `number` ? `of ${req}` : `>= ${req.min ?? 0}${req.max ? `&& <= ${req.max}` : ``}`}, received has value: ${issue.received.length}`);
|
|
8
|
+
//# sourceMappingURL=boundedInteger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundedInteger.js","sourceRoot":"","sources":["../../src/validations/boundedInteger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,sDAAsD;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,MAA+C,EAAE,EACxB,EAAE,CAC3B,CAAC,CAAC,OAAO,CACP,OAAO,GAAG,KAAK,QAAQ;IACrB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ;QAC3B,CAAC,CAAC,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,OAAO,EAAE,EACX,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,EACxB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CACpB;QACH,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAC/D,CAAC,KAAK,EAAE,EAAE,CACR,oCAAoC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,yBAAyB,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CACvL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** A non-empty string with a length within the given bounds */
|
|
3
|
+
export const boundedString = (req = {}) => v.message(typeof req === `number`
|
|
4
|
+
? v.pipe(v.string(), v.length(req))
|
|
5
|
+
: typeof req.max === `number`
|
|
6
|
+
? v.pipe(v.string(), v.minLength(req.min ?? 1), v.maxLength(req.max))
|
|
7
|
+
: v.pipe(v.string(), v.minLength(req.min ?? 1)), (issue) => `Expected a string with a legnth ${typeof req === `number` ? req : `>= ${req.min ?? 0}${req.max ? `&& <= ${req.max}` : ``}`}, received has length: ${issue.received.length}`);
|
|
8
|
+
//# sourceMappingURL=boundedString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundedString.js","sourceRoot":"","sources":["../../src/validations/boundedString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,+DAA+D;AAC/D,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAA+C,EAAE,EACxB,EAAE,CAC3B,CAAC,CAAC,OAAO,CACP,OAAO,GAAG,KAAK,QAAQ;IACrB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ;QAC3B,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EACnD,CAAC,KAAK,EAAE,EAAE,CACR,mCAAmC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,0BAA0B,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAC/K,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
export declare const datauriRegex: RegExp;
|
|
2
3
|
/**
|
|
3
4
|
* Extracts metadata from a given Data URI such as it's
|
|
@@ -16,4 +17,4 @@ export declare const toBase64: (data: string) => string;
|
|
|
16
17
|
/**
|
|
17
18
|
* Validates that a string is a [data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)
|
|
18
19
|
*/
|
|
19
|
-
export declare const datauri:
|
|
20
|
+
export declare const datauri: v.GenericSchema<string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
export const datauriRegex = /^data:((?<mediaType>(?<mimeType>[a-z]+\/[a-z0-9-+.]+)(?<params>;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*))?(?<encoding>;base64)?,(?<data>[a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i;
|
|
3
3
|
/**
|
|
4
4
|
* Extracts metadata from a given Data URI such as it's
|
|
@@ -16,5 +16,5 @@ export const toBase64 = (data) => typeof Buffer !== `undefined`
|
|
|
16
16
|
/**
|
|
17
17
|
* Validates that a string is a [data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)
|
|
18
18
|
*/
|
|
19
|
-
export const datauri = pipe(custom((val) =>
|
|
19
|
+
export const datauri = v.pipe(v.custom((val) => typeof val === `string` && val.length > 0 && datauriRegex.test(val), `Invalid Data URI`), v.title(`datauri`));
|
|
20
20
|
//# sourceMappingURL=datauri.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datauri.js","sourceRoot":"","sources":["../../src/validations/datauri.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"datauri.js","sourceRoot":"","sources":["../../src/validations/datauri.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,MAAM,CAAC,MAAM,YAAY,GACvB,8LAA8L,CAAC;AAEjM;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAW,EAOV,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;AAE3C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAU,EAAE,CAC/C,OAAO,MAAM,KAAK,WAAW;IAC3B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE;IACxC,CAAC,CAAC,IAAI,CACF,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;SACzD,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CACrB,CAAC;AAER;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAA4B,CAAC,CAAC,IAAI,CACpD,CAAC,CAAC,MAAM,CACN,CAAC,GAAG,EAAE,EAAE,CACN,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EACrE,kBAAkB,CACnB,EACD,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CACnB,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export * from "./asDigits.js";
|
|
2
2
|
export * from "./asInteger.js";
|
|
3
3
|
export * from "./bitfield.js";
|
|
4
|
+
export * from "./boundedArray.js";
|
|
5
|
+
export * from "./boundedInteger.js";
|
|
6
|
+
export * from "./boundedString.js";
|
|
4
7
|
export * from "./datauri.js";
|
|
5
8
|
export * from "./hasMimeType.js";
|
|
6
9
|
export * from "./toBlob.js";
|
|
7
10
|
export * from "./snowflake.js";
|
|
11
|
+
export * from "./timestamp.js";
|
|
12
|
+
export * from "./url.js";
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export * from "./asDigits.js";
|
|
2
2
|
export * from "./asInteger.js";
|
|
3
3
|
export * from "./bitfield.js";
|
|
4
|
+
export * from "./boundedArray.js";
|
|
5
|
+
export * from "./boundedInteger.js";
|
|
6
|
+
export * from "./boundedString.js";
|
|
4
7
|
export * from "./datauri.js";
|
|
5
8
|
export * from "./hasMimeType.js";
|
|
6
9
|
export * from "./toBlob.js";
|
|
7
10
|
export * from "./snowflake.js";
|
|
11
|
+
export * from "./timestamp.js";
|
|
12
|
+
export * from "./url.js";
|
|
8
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validations/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validations/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** UNIX timestamp representing the first second of 2015 */
|
|
1
3
|
export declare const DISCORD_EPOCH = 1420070400000n;
|
|
2
|
-
export declare const snowflake: import("valibot").SchemaWithPipe<readonly [import("valibot").CustomSchema<string, import("valibot").ErrorMessage<import("valibot").CustomIssue> | undefined>, import("valibot").TitleAction<string, "snowflake">]>;
|
|
3
4
|
/**
|
|
4
5
|
* Converts a `snowflake` string to a Date relative to the given epoch
|
|
5
6
|
*
|
|
@@ -9,18 +10,16 @@ export declare const snowflake: import("valibot").SchemaWithPipe<readonly [impor
|
|
|
9
10
|
*/
|
|
10
11
|
export declare const snowflakeToDate: (
|
|
11
12
|
/** A snowflake string to convert */
|
|
12
|
-
val: string,
|
|
13
|
+
val: string | number | bigint,
|
|
13
14
|
/** time in milliseconds to use as the epoch to derive a Date from */
|
|
14
15
|
epoch?: bigint) => Date;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* An up to 64-bit unsigned numeric value derived from a timestamp which
|
|
18
|
+
* serves as a unique identifier within Discord.
|
|
17
19
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* Validates whether a given `number`, `bigint`, or numeric `string` is
|
|
21
|
+
* a valid [Snowflake](https://discord.com/developers/docs/reference#snowflakes)
|
|
22
|
+
* by checking if it's derived timestamp is a valid time at or after
|
|
23
|
+
* the Discord epoch (the first second of 2015, ie: `1420070400000`).
|
|
21
24
|
*/
|
|
22
|
-
export declare const
|
|
23
|
-
/** A Date to convert to a `snowflake` */
|
|
24
|
-
val: Date,
|
|
25
|
-
/** time in milliseconds to use as the epoch to derive a `snowflake` from */
|
|
26
|
-
epoch?: bigint) => string;
|
|
25
|
+
export declare const snowflake: v.GenericSchema<string>;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from "valibot";
|
|
2
2
|
import { isNonNullable } from "../utils/isNonNullable.js";
|
|
3
|
+
import { isNumericString } from "../utils/isNumericString.js";
|
|
4
|
+
/** UNIX timestamp representing the first second of 2015 */
|
|
3
5
|
export const DISCORD_EPOCH = 1420070400000n;
|
|
4
|
-
export const snowflake = pipe(custom((val) => isNonNullable(val) &&
|
|
5
|
-
(typeof val === `bigint` ||
|
|
6
|
-
typeof val === `number` ||
|
|
7
|
-
typeof val === `string`)
|
|
8
|
-
? is(pipe(union([string(), number()]), transform((input) => new Date(input))), Number((BigInt(val) >> 22n) + DISCORD_EPOCH))
|
|
9
|
-
: false, `Invalid Snowflake ID`), title(`snowflake`));
|
|
10
6
|
/**
|
|
11
7
|
* Converts a `snowflake` string to a Date relative to the given epoch
|
|
12
8
|
*
|
|
@@ -20,15 +16,24 @@ val,
|
|
|
20
16
|
/** time in milliseconds to use as the epoch to derive a Date from */
|
|
21
17
|
epoch = DISCORD_EPOCH) => new Date(Number((BigInt(val) >> 22n) + epoch));
|
|
22
18
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Uses Discord's epoch by default
|
|
19
|
+
* An up to 64-bit unsigned numeric value derived from a timestamp which
|
|
20
|
+
* serves as a unique identifier within Discord.
|
|
26
21
|
*
|
|
27
|
-
*
|
|
22
|
+
* Validates whether a given `number`, `bigint`, or numeric `string` is
|
|
23
|
+
* a valid [Snowflake](https://discord.com/developers/docs/reference#snowflakes)
|
|
24
|
+
* by checking if it's derived timestamp is a valid time at or after
|
|
25
|
+
* the Discord epoch (the first second of 2015, ie: `1420070400000`).
|
|
28
26
|
*/
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
export const snowflake = v.pipe(v.custom((val) =>
|
|
28
|
+
// at runtime this could be any value, so filter out
|
|
29
|
+
// obviously invalid input first
|
|
30
|
+
isNonNullable(val) &&
|
|
31
|
+
// then verify we have a numeric value
|
|
32
|
+
(typeof val === `bigint` ||
|
|
33
|
+
typeof val === `number` ||
|
|
34
|
+
isNumericString(val)) &&
|
|
35
|
+
// finally, verify that it accurately represents ms
|
|
36
|
+
// at or after the Discord epoch (timestamps before
|
|
37
|
+
// that cannot possibly be a valid Discord snowflake)
|
|
38
|
+
snowflakeToDate(val).getTime() >= DISCORD_EPOCH, `Invalid Snowflake`), v.title(`snowflake`));
|
|
34
39
|
//# sourceMappingURL=snowflake.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snowflake.js","sourceRoot":"","sources":["../../src/validations/snowflake.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"snowflake.js","sourceRoot":"","sources":["../../src/validations/snowflake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;AAC7B,oCAAoC;AACpC,GAA6B;AAC7B,qEAAqE;AACrE,KAAK,GAAG,aAAa,EACf,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAA4B,CAAC,CAAC,IAAI,CACtD,CAAC,CAAC,MAAM,CACN,CAAC,GAAG,EAAE,EAAE;AACN,oDAAoD;AACpD,gCAAgC;AAChC,aAAa,CAAC,GAAG,CAAC;IAClB,sCAAsC;IACtC,CAAC,OAAO,GAAG,KAAK,QAAQ;QACtB,OAAO,GAAG,KAAK,QAAQ;QACvB,eAAe,CAAC,GAAG,CAAC,CAAC;IACvB,mDAAmD;IACnD,mDAAmD;IACnD,qDAAqD;IACrD,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,aAAa,EACjD,mBAAmB,CACpB,EACD,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CACrB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** An [ISO8601](https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_iso_wd_8601-1_2016-02-16.pdf) timestamp */
|
|
3
|
+
export const timestamp = v.message(v.pipe(v.string(), v.isoTimestamp()), (issue) => `Expected a valid timestamp, received: ${issue.received}`);
|
|
4
|
+
//# sourceMappingURL=timestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../src/validations/timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,sHAAsH;AACtH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAChC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,EACpC,CAAC,KAAK,EAAE,EAAE,CAAC,yCAAyC,KAAK,CAAC,QAAQ,EAAE,CAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/validations/url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,MAAM,CAAC,MAAM,GAAG,GAA4B,CAAC,CAAC,OAAO,CACnD,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,EAC3B,CAAC,KAAK,EAAE,EAAE,CAAC,mCAAmC,KAAK,CAAC,QAAQ,EAAE,CAC/D,CAAC"}
|