@discordkit/core 1.1.0-next.2 → 3.0.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/index.d.ts +2 -8
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/{DiscordSession.d.ts → requests/DiscordSession.d.ts} +3 -3
- package/dist/{DiscordSession.js → requests/DiscordSession.js} +3 -1
- package/dist/requests/DiscordSession.js.map +1 -0
- package/dist/requests/addParams.d.ts +2 -0
- package/dist/{addParams.js → requests/addParams.js} +2 -2
- package/dist/requests/addParams.js.map +1 -0
- package/dist/requests/buildURL.d.ts +2 -0
- package/dist/requests/buildURL.js.map +1 -0
- package/dist/requests/getAsset.js.map +1 -0
- package/dist/requests/index.d.ts +7 -0
- package/dist/requests/index.js +8 -0
- package/dist/requests/index.js.map +1 -0
- package/dist/{methods.d.ts → requests/methods.d.ts} +6 -2
- package/dist/requests/methods.js.map +1 -0
- package/dist/requests/request.js +35 -0
- package/dist/requests/request.js.map +1 -0
- package/dist/requests/toProcedure.d.ts +31 -0
- package/dist/{toProcedure.js → requests/toProcedure.js} +5 -6
- package/dist/requests/toProcedure.js.map +1 -0
- package/dist/{toQuery.d.ts → requests/toQuery.d.ts} +3 -3
- package/dist/requests/toQuery.js.map +1 -0
- package/dist/requests/toValidated.d.ts +13 -0
- package/dist/requests/toValidated.js +29 -0
- package/dist/requests/toValidated.js.map +1 -0
- package/dist/{isNonNullable.d.ts → utils/isNonNullable.d.ts} +2 -1
- package/dist/utils/isNonNullable.js.map +1 -0
- package/dist/utils/isObject.js.map +1 -0
- package/dist/utils/toCamelCase.js.map +1 -0
- package/dist/utils/toCamelKeys.js.map +1 -0
- package/dist/utils/toSnakeCase.js.map +1 -0
- package/dist/utils/toSnakeKeys.js.map +1 -0
- package/dist/validations/asDigits.d.ts +3 -0
- package/dist/validations/asDigits.js +3 -0
- package/dist/validations/asDigits.js.map +1 -0
- package/dist/validations/asInteger.d.ts +3 -0
- package/dist/validations/asInteger.js +3 -0
- package/dist/validations/asInteger.js.map +1 -0
- package/dist/validations/bitfield.d.ts +5 -0
- package/dist/validations/bitfield.js +24 -0
- package/dist/validations/bitfield.js.map +1 -0
- package/dist/validations/datauri.d.ts +19 -0
- package/dist/validations/datauri.js +20 -0
- package/dist/validations/datauri.js.map +1 -0
- package/dist/validations/hasMimeType.d.ts +10 -0
- package/dist/validations/hasMimeType.js +18 -0
- package/dist/validations/hasMimeType.js.map +1 -0
- package/dist/validations/hasSize.d.ts +5 -0
- package/dist/validations/hasSize.js +13 -0
- package/dist/validations/hasSize.js.map +1 -0
- package/dist/validations/index.d.ts +7 -0
- package/dist/validations/index.js +8 -0
- package/dist/validations/index.js.map +1 -0
- package/dist/validations/snowflake.d.ts +26 -0
- package/dist/validations/snowflake.js +34 -0
- package/dist/validations/snowflake.js.map +1 -0
- package/dist/validations/toBlob.d.ts +4 -0
- package/dist/validations/toBlob.js +19 -0
- package/dist/validations/toBlob.js.map +1 -0
- package/package.json +9 -4
- package/dist/DiscordSession.js.map +0 -1
- package/dist/addParams.d.ts +0 -2
- package/dist/addParams.js.map +0 -1
- package/dist/buildURL.d.ts +0 -1
- package/dist/buildURL.js.map +0 -1
- package/dist/getAsset.js.map +0 -1
- package/dist/isNonNullable.js.map +0 -1
- package/dist/isObject.js.map +0 -1
- package/dist/methods.js.map +0 -1
- package/dist/request.js +0 -21
- package/dist/request.js.map +0 -1
- package/dist/snowflake.d.ts +0 -1
- package/dist/snowflake.js +0 -11
- package/dist/snowflake.js.map +0 -1
- package/dist/toCamelCase.js.map +0 -1
- package/dist/toCamelKeys.js.map +0 -1
- package/dist/toProcedure.d.ts +0 -36
- package/dist/toProcedure.js.map +0 -1
- package/dist/toQuery.js.map +0 -1
- package/dist/toSnakeCase.js.map +0 -1
- package/dist/toSnakeKeys.js.map +0 -1
- package/dist/toValidated.d.ts +0 -12
- package/dist/toValidated.js +0 -23
- package/dist/toValidated.js.map +0 -1
- package/dist/wrap.d.ts +0 -18
- package/dist/wrap.js +0 -34
- package/dist/wrap.js.map +0 -1
- /package/dist/{buildURL.js → requests/buildURL.js} +0 -0
- /package/dist/{getAsset.d.ts → requests/getAsset.d.ts} +0 -0
- /package/dist/{getAsset.js → requests/getAsset.js} +0 -0
- /package/dist/{methods.js → requests/methods.js} +0 -0
- /package/dist/{request.d.ts → requests/request.d.ts} +0 -0
- /package/dist/{toQuery.js → requests/toQuery.js} +0 -0
- /package/dist/{isNonNullable.js → utils/isNonNullable.js} +0 -0
- /package/dist/{isObject.d.ts → utils/isObject.d.ts} +0 -0
- /package/dist/{isObject.js → utils/isObject.js} +0 -0
- /package/dist/{toCamelCase.d.ts → utils/toCamelCase.d.ts} +0 -0
- /package/dist/{toCamelCase.js → utils/toCamelCase.js} +0 -0
- /package/dist/{toCamelKeys.d.ts → utils/toCamelKeys.d.ts} +0 -0
- /package/dist/{toCamelKeys.js → utils/toCamelKeys.js} +0 -0
- /package/dist/{toSnakeCase.d.ts → utils/toSnakeCase.d.ts} +0 -0
- /package/dist/{toSnakeCase.js → utils/toSnakeCase.js} +0 -0
- /package/dist/{toSnakeKeys.d.ts → utils/toSnakeKeys.d.ts} +0 -0
- /package/dist/{toSnakeKeys.js → utils/toSnakeKeys.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./getAsset.js";
|
|
4
|
-
export * from "./methods.js";
|
|
5
|
-
export * from "./toProcedure.js";
|
|
6
|
-
export * from "./toQuery.js";
|
|
7
|
-
export * from "./toValidated.js";
|
|
8
|
-
export * from "./snowflake.js";
|
|
1
|
+
export * from "./requests/index.js";
|
|
2
|
+
export * from "./validations/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./getAsset.js";
|
|
4
|
-
export * from "./methods.js";
|
|
5
|
-
export * from "./toProcedure.js";
|
|
6
|
-
export * from "./toQuery.js";
|
|
7
|
-
export * from "./toValidated.js";
|
|
8
|
-
export * from "./snowflake.js";
|
|
1
|
+
export * from "./requests/index.js";
|
|
2
|
+
export * from "./validations/index.js";
|
|
9
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC"}
|
|
@@ -4,13 +4,13 @@ export declare class DiscordSession {
|
|
|
4
4
|
#private;
|
|
5
5
|
endpoint: string;
|
|
6
6
|
get ready(): boolean;
|
|
7
|
-
constructor(authToken?: string | null);
|
|
7
|
+
constructor(authToken?: `${`Bot` | `Bearer`} ${string}` | null);
|
|
8
8
|
/**
|
|
9
9
|
* Clears the current session details, then attempts to set
|
|
10
10
|
* new session values
|
|
11
11
|
*/
|
|
12
|
-
setToken: (token: string) =>
|
|
13
|
-
clearSession: () =>
|
|
12
|
+
setToken: (token: `${`Bot` | `Bearer`} ${string}`) => this;
|
|
13
|
+
clearSession: () => this;
|
|
14
14
|
getSession: () => string;
|
|
15
15
|
}
|
|
16
16
|
export declare const discord: DiscordSession;
|
|
@@ -17,16 +17,18 @@ export class DiscordSession {
|
|
|
17
17
|
*/
|
|
18
18
|
setToken = (token) => {
|
|
19
19
|
this.#authToken = null;
|
|
20
|
-
if (
|
|
20
|
+
if (token.length === 0) {
|
|
21
21
|
throw new Error(`Must provide a non-empty string to set Auth Token`);
|
|
22
22
|
}
|
|
23
23
|
if (!token.startsWith(`Bot `) && !token.startsWith(`Bearer `)) {
|
|
24
24
|
throw new Error(`Token must begin with either "Bot " or "Bearer ", received: ${token}`);
|
|
25
25
|
}
|
|
26
26
|
this.#authToken = token;
|
|
27
|
+
return this;
|
|
27
28
|
};
|
|
28
29
|
clearSession = () => {
|
|
29
30
|
this.#authToken = null;
|
|
31
|
+
return this;
|
|
30
32
|
};
|
|
31
33
|
getSession = () => {
|
|
32
34
|
const token = this.#authToken;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiscordSession.js","sourceRoot":"","sources":["../../src/requests/DiscordSession.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,8BAA8B,CAAC;AAEvD,gBAAgB;AAChB,MAAM,OAAO,cAAc;IACzB,QAAQ,GAAW,QAAQ,CAAC;IAC5B,UAAU,GAAkB,IAAI,CAAC;IACjC,IAAI,KAAK;QACP,OAAO,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,YAAY,SAAkD;QAC5D,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,QAAQ,GAAG,CAAC,KAAsC,EAAQ,EAAE;QAC1D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CACb,+DAA+D,KAAK,EAAE,CACvE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,YAAY,GAAG,GAAS,EAAE;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,UAAU,GAAG,GAAW,EAAE;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC;QAE9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;CACH;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isNonNullable } from "
|
|
2
|
-
import { toSnakeCase } from "
|
|
1
|
+
import { isNonNullable } from "../utils/isNonNullable.js";
|
|
2
|
+
import { toSnakeCase } from "../utils/toSnakeCase.js";
|
|
3
3
|
export const addParams = (url, params) => {
|
|
4
4
|
for (const [key, value] of Object.entries(params)) {
|
|
5
5
|
if (isNonNullable(value)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addParams.js","sourceRoot":"","sources":["../../src/requests/addParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAStD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAQ,EAAE,MAAqB,EAAO,EAAE;IAChE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildURL.js","sourceRoot":"","sources":["../../src/requests/buildURL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAsB,MAAM,gBAAgB,CAAC;AAE/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAgB,EAChB,MAAsB,EACtB,IAAa,EACR,EAAE,CACP,SAAS,CACP,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,IAAI,IAAI,QAAQ,CAAC,EACtD,MAAM,IAAI,EAAE,CACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAsset.js","sourceRoot":"","sources":["../../src/requests/getAsset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAgB,EAChB,MAAuC,EAC/B,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,6BAA6B,CAAC,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { endpoint, discord } from "./DiscordSession.js";
|
|
2
|
+
export * from "./buildURL.js";
|
|
3
|
+
export * from "./getAsset.js";
|
|
4
|
+
export * from "./methods.js";
|
|
5
|
+
export * from "./toProcedure.js";
|
|
6
|
+
export * from "./toQuery.js";
|
|
7
|
+
export * from "./toValidated.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/requests/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACxD,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenericSchema, GenericSchemaAsync, InferOutput } from "valibot";
|
|
2
2
|
import type { RequestParams } from "./addParams.js";
|
|
3
3
|
import type { RequestBody } from "./request.js";
|
|
4
|
-
export type Fetcher<
|
|
4
|
+
export type Fetcher<
|
|
5
|
+
/** A schema to validate the input arguments of a fetch call */
|
|
6
|
+
S extends GenericSchema | GenericSchemaAsync | null = null,
|
|
7
|
+
/** The return value expected from the fetch call */
|
|
8
|
+
R = void> = S extends null ? () => Promise<R> : (config: InferOutput<NonNullable<S>>) => Promise<R>;
|
|
5
9
|
export declare const get: <T>(url: string, params?: RequestParams) => Promise<T>;
|
|
6
10
|
export declare const post: <T>(url: string, body?: RequestBody) => Promise<T>;
|
|
7
11
|
export declare const put: <T>(url: string, body?: RequestBody) => Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/requests/methods.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAWvC,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EAAK,GAAW,EAAE,MAAsB,EAAc,EAAE,CAC9E,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAK,GAAW,EAAE,IAAkB,EAAc,EAAE,CAC3E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EAAK,GAAW,EAAE,IAAkB,EAAc,EAAE,CAC1E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAK,GAAW,EAAE,IAAkB,EAAc,EAAE,CAC5E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAY,GAAW,EAAc,EAAE,CAChE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { discord } from "./DiscordSession.js";
|
|
2
|
+
import { toCamelKeys } from "../utils/toCamelKeys.js";
|
|
3
|
+
import { toSnakeKeys } from "../utils/toSnakeKeys.js";
|
|
4
|
+
export const request = async (resource, method = `GET`, body) => {
|
|
5
|
+
const token = discord.getSession();
|
|
6
|
+
if (!token) {
|
|
7
|
+
throw new Error(`Auth Token must be set before requests can be made.`);
|
|
8
|
+
}
|
|
9
|
+
const json = () => {
|
|
10
|
+
try {
|
|
11
|
+
return body ? JSON.stringify(toSnakeKeys(body)) : body; //?
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
console.error(`Received malformed request body:\n\n`, { body });
|
|
15
|
+
throw new Error(`Failed to stringify request body!`, err);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const res = await fetch(resource.toString(), {
|
|
19
|
+
method,
|
|
20
|
+
body: json(),
|
|
21
|
+
headers: {
|
|
22
|
+
Authorization: token
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
throw new Error(`Request to resource '${resource.toString()}' failed:\n\n${res.statusText}`);
|
|
27
|
+
}
|
|
28
|
+
// Return `void` on `204 No Content` responses
|
|
29
|
+
if (res.status === 204) {
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return toCamelKeys(await res.json());
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/requests/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAItD,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAC1B,QAAa,EACb,MAAM,GAAG,KAAK,EACd,IAAkB,EACN,EAAE;IACd,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAEnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,IAAI,GAAG,GAA8B,EAAE;QAC3C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG;QAC7D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE;QAC3C,MAAM;QACN,IAAI,EAAE,IAAI,EAAE;QACZ,OAAO,EAAE;YACP,aAAa,EAAE,KAAK;SACrB;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,wBAAwB,QAAQ,CAAC,QAAQ,EAAE,gBACzC,GAAG,CAAC,UACN,EAAE,CACH,CAAC;IACJ,CAAC;IAED,8CAA8C;IAC9C,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACvB,mBAAmB;QACnB,OAAO;IACT,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACvC,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GenericSchema, GenericSchemaAsync, InferInput, InferOutput } from "valibot";
|
|
2
|
+
import type { AnyProcedureBuilder, MutationProcedure, ProcedureType, QueryProcedure, SubscriptionProcedure } from "@trpc/server/unstable-core-do-not-import";
|
|
3
|
+
import type { Fetcher } from "./methods.js";
|
|
4
|
+
type Result<T = void> = T extends GenericSchema | GenericSchemaAsync ? InferOutput<T> : T;
|
|
5
|
+
type Schema = GenericSchema | GenericSchemaAsync;
|
|
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>;
|
|
9
|
+
meta: unknown;
|
|
10
|
+
} : {
|
|
11
|
+
input: InferInput<I>;
|
|
12
|
+
output: undefined;
|
|
13
|
+
meta: unknown;
|
|
14
|
+
} : O extends Schema ? {
|
|
15
|
+
input: undefined;
|
|
16
|
+
output: InferOutput<O>;
|
|
17
|
+
meta: unknown;
|
|
18
|
+
} : {
|
|
19
|
+
input: undefined;
|
|
20
|
+
output: undefined;
|
|
21
|
+
meta: unknown;
|
|
22
|
+
};
|
|
23
|
+
type BaseProcedure<T extends ProcedureType, I extends Schema | null = null, O extends Schema | null = null> = T extends `query` ? QueryProcedure<ProvedureDef<I, O>> : T extends `mutation` ? MutationProcedure<ProvedureDef<I, O>> : SubscriptionProcedure<ProvedureDef<I, O>>;
|
|
24
|
+
/**
|
|
25
|
+
* Given a {@link Fetcher | Fetcher} function and it's associated input and
|
|
26
|
+
* output Zod schemas, this produces a function which accepts a tRPC procedure
|
|
27
|
+
* builder of the given procedure type. This can then be used in a tRPC router
|
|
28
|
+
* to scaffold an API route to forward a request to Discord's API.
|
|
29
|
+
*/
|
|
30
|
+
export declare const toProcedure: <T extends ProcedureType, I extends GenericSchema | GenericSchemaAsync | null = null, O extends GenericSchema | GenericSchemaAsync | null = null>(type: T, fn: Fetcher<I extends GenericSchema | GenericSchemaAsync ? I : null, Result<O>>, input?: I, output?: O) => (procedure: AnyProcedureBuilder) => BaseProcedure<T, I, O>;
|
|
31
|
+
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isNonNullable } from "./isNonNullable.js";
|
|
1
|
+
import { isNonNullable } from "../utils/isNonNullable.js";
|
|
3
2
|
/**
|
|
4
3
|
* Given a {@link Fetcher | Fetcher} function and it's associated input and
|
|
5
4
|
* output Zod schemas, this produces a function which accepts a tRPC procedure
|
|
@@ -10,16 +9,16 @@ export const toProcedure = (type, fn, input, output) => (procedure) => {
|
|
|
10
9
|
if (isNonNullable(input) && isNonNullable(output)) {
|
|
11
10
|
// @ts-expect-error
|
|
12
11
|
return procedure
|
|
13
|
-
.input(
|
|
14
|
-
.output(
|
|
12
|
+
.input(input)
|
|
13
|
+
.output(output)[type](async (opts) => fn(opts.input));
|
|
15
14
|
}
|
|
16
15
|
if (isNonNullable(input) && !isNonNullable(output)) {
|
|
17
16
|
// @ts-expect-error
|
|
18
|
-
return procedure.input(
|
|
17
|
+
return procedure.input(input)[type](async (opts) => fn(opts.input));
|
|
19
18
|
}
|
|
20
19
|
if (!isNonNullable(input) && isNonNullable(output)) {
|
|
21
20
|
// @ts-expect-error
|
|
22
|
-
return procedure.output(
|
|
21
|
+
return procedure.output(output)[type](async () => fn());
|
|
23
22
|
}
|
|
24
23
|
// @ts-expect-error
|
|
25
24
|
return procedure[type](async () => fn());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toProcedure.js","sourceRoot":"","sources":["../../src/requests/toProcedure.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAsC1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,CAKE,IAAO,EACP,EAGC,EACD,KAAS,EACT,MAAU,EACV,EAAE,CACJ,CAAC,SAA8B,EAA0B,EAAE;IACzD,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,mBAAmB;QACnB,OAAO,SAAS;aACb,KAAK,CAAC,KAAK,CAAC;aACZ,MAAM,CAAC,MAAM,CAAC,CACd,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,mBAAmB;QACnB,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;IACtE,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,mBAAmB;QACnB,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,mBAAmB;IACnB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenericSchema } from "valibot";
|
|
2
2
|
import type { Fetcher } from "./methods.js";
|
|
3
3
|
interface Register {
|
|
4
4
|
}
|
|
@@ -6,7 +6,7 @@ type QueryKey = readonly unknown[];
|
|
|
6
6
|
type QueryMeta = Register extends {
|
|
7
7
|
queryMeta: infer TQueryMeta;
|
|
8
8
|
} ? TQueryMeta extends Record<string, unknown> ? TQueryMeta : Record<string, unknown> : Record<string, unknown>;
|
|
9
|
-
type FetchDirection =
|
|
9
|
+
type FetchDirection = `backward` | `forward`;
|
|
10
10
|
type QueryFunctionContext<TQueryKey extends QueryKey = QueryKey, TPageParam = never> = [TPageParam] extends [never] ? {
|
|
11
11
|
queryKey: TQueryKey;
|
|
12
12
|
signal: AbortSignal;
|
|
@@ -24,5 +24,5 @@ export type QueryFunction<T = unknown, TQueryKey extends QueryKey = QueryKey, TP
|
|
|
24
24
|
* which can then be used with React-Query as a query function without
|
|
25
25
|
* the need for any additional boilerplate.
|
|
26
26
|
*/
|
|
27
|
-
export declare const toQuery: <S extends
|
|
27
|
+
export declare const toQuery: <S extends GenericSchema | null, R, T extends Fetcher<S, R>>(fn: T) => Parameters<T>[`length`] extends 0 ? () => QueryFunction<Awaited<ReturnType<T>>> : (config: Parameters<T>[0]) => QueryFunction<Awaited<ReturnType<T>>>;
|
|
28
28
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toQuery.js","sourceRoot":"","sources":["../../src/requests/toQuery.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAClB,CACE,EAAK,EAGiE,EAAE;AAC1E,mBAAmB;AACnB,CAAC,GAAG,MAAiB,EAAE,EAAE,CACzB,KAAK,IAAI,EAAE,CACT,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type GenericSchema, type GenericSchemaAsync, type InferOutput } from "valibot";
|
|
2
|
+
import type { Fetcher } from "./methods.js";
|
|
3
|
+
type InferFetcherSchema<F> = F extends Fetcher<infer S, unknown> ? S : never;
|
|
4
|
+
type InferFetcherReturn<F> = F extends Fetcher<GenericSchema | GenericSchemaAsync | null, infer R> ? R : never;
|
|
5
|
+
/**
|
|
6
|
+
* Given a {@link Fetcher | Fetcher} function and it's associated input
|
|
7
|
+
* and output Zod schemas, this returns a new validated {@link Fetcher | Fetcher} function which will validate it's input and result at runtime.
|
|
8
|
+
* This is useful in contexts where you want strong guarantees on runtime
|
|
9
|
+
* type-safety when dealing with raw user input in a framework agnostic
|
|
10
|
+
* environment.
|
|
11
|
+
*/
|
|
12
|
+
export declare const toValidated: <F extends Fetcher<GenericSchema | GenericSchemaAsync, InferOutput<GenericSchema | GenericSchemaAsync>> | Fetcher<GenericSchema | GenericSchemaAsync> | Fetcher<null, null> | Fetcher<null, InferOutput<GenericSchema | GenericSchemaAsync>>>(fn: F, input?: InferFetcherSchema<F> | null, output?: GenericSchema<unknown, InferFetcherReturn<F>> | GenericSchemaAsync<unknown, InferFetcherReturn<F>>) => F;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isOfKind, safeParseAsync, summarize } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Given a {@link Fetcher | Fetcher} function and it's associated input
|
|
4
|
+
* and output Zod schemas, this returns a new validated {@link Fetcher | Fetcher} function which will validate it's input and result at runtime.
|
|
5
|
+
* This is useful in contexts where you want strong guarantees on runtime
|
|
6
|
+
* type-safety when dealing with raw user input in a framework agnostic
|
|
7
|
+
* environment.
|
|
8
|
+
*/
|
|
9
|
+
export const toValidated = (fn, input, output) => new Proxy(fn, {
|
|
10
|
+
async apply(target, _, [config]) {
|
|
11
|
+
// Validate the fetcher args before fetching
|
|
12
|
+
if (input && isOfKind(`schema`, input)) {
|
|
13
|
+
const { issues } = await safeParseAsync(input, config);
|
|
14
|
+
if (issues) {
|
|
15
|
+
throw new Error(`Failed to parse input schema: ${input.reference.name}\n\n${summarize(issues)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const result = await target(config);
|
|
19
|
+
// Validate the result of the fetch call before returning
|
|
20
|
+
if (output && isOfKind(`schema`, output)) {
|
|
21
|
+
const { issues } = await safeParseAsync(output, result);
|
|
22
|
+
if (issues) {
|
|
23
|
+
throw new Error(`Failed to parse input schema: ${output.reference.name}\n\n${summarize(issues)}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=toValidated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toValidated.js","sourceRoot":"","sources":["../../src/requests/toValidated.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EACR,cAAc,EACd,SAAS,EACV,MAAM,SAAS,CAAC;AASjB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAUzB,EAAK,EACL,KAAoC,EACpC,MAEsD,EACnD,EAAE,CACL,IAAI,KAAK,CAAI,EAAE,EAAE;IACf,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC;QAC7B,4CAA4C;QAC5C,IAAI,KAAK,IAAI,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC;YACvC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACvD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CACb,iCAAiC,KAAK,CAAC,SAAS,CAAC,IAAI,OAAO,SAAS,CAAC,MAAM,CAAC,EAAE,CAChF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QAEpC,yDAAyD;QACzD,IAAI,MAAM,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;YACzC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACxD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CACb,iCAAiC,MAAM,CAAC,SAAS,CAAC,IAAI,OAAO,SAAS,CAAC,MAAM,CAAC,EAAE,CACjF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,MAAuB,CAAC;IACjC,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type Maybe<T> = T | null | undefined;
|
|
1
2
|
/**
|
|
2
3
|
* Used to test whether a `Maybe` typed value is `null` or `undefined`.
|
|
3
4
|
*
|
|
@@ -16,4 +17,4 @@
|
|
|
16
17
|
* }
|
|
17
18
|
* ```
|
|
18
19
|
*/
|
|
19
|
-
export declare const isNonNullable: <T extends unknown
|
|
20
|
+
export declare const isNonNullable: <T extends Maybe<unknown>>(val?: T) => val is NonNullable<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNonNullable.js","sourceRoot":"","sources":["../../src/utils/isNonNullable.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAO,EACgB,EAAE,CAAC,OAAO,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isObject.js","sourceRoot":"","sources":["../../src/utils/isObject.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAiB,EAAE,CACtD,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toCamelCase.js","sourceRoot":"","sources":["../../src/utils/toCamelCase.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE,CACjD,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toCamelKeys.js","sourceRoot":"","sources":["../../src/utils/toCamelKeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,CAAI,EACyB,EAAE;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC,GAAG,CAAC,WAAW,CAAgC,CAAC;IAC3D,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpD,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAgC,CAAC;IACxC,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toSnakeCase.js","sourceRoot":"","sources":["../../src/utils/toSnakeCase.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE,CACjD,GAAG;KACA,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;KACzD,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toSnakeKeys.js","sourceRoot":"","sources":["../../src/utils/toSnakeKeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,CAAI,EACyB,EAAE;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC,GAAG,CAAC,WAAW,CAAgC,CAAC;IAC3D,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpD,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAgC,CAAC;IACxC,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CustomSchema, DigitsAction, SchemaWithPipe, TransformAction } from "valibot";
|
|
2
|
+
import type { bitfield } from "./bitfield.js";
|
|
3
|
+
export declare const asDigits: (schema: ReturnType<typeof bitfield>) => SchemaWithPipe<readonly [CustomSchema<string | number | bigint, string>, TransformAction<string | number | bigint, string>, DigitsAction<string, undefined>]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asDigits.js","sourceRoot":"","sources":["../../src/validations/asDigits.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGlD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,MAAmC,EAOnC,EAAE,CACF,IAAI,CACF,MAAM,EACN,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,EAClC,MAAM,EAAE,CACT,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CustomSchema, IntegerAction, SchemaWithPipe, TransformAction } from "valibot";
|
|
2
|
+
import type { bitfield } from "./bitfield.js";
|
|
3
|
+
export declare const asInteger: (schema: ReturnType<typeof bitfield>) => SchemaWithPipe<readonly [CustomSchema<string | number | bigint, string>, TransformAction<string | number | bigint, number>, IntegerAction<number, undefined>]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asInteger.js","sourceRoot":"","sources":["../../src/validations/asInteger.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGnD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,MAAmC,EAOnC,EAAE,CACF,IAAI,CACF,MAAM,EACN,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,EAChD,OAAO,EAAE,CACV,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SchemaWithPipe, type TitleAction, type CustomSchema } from "valibot";
|
|
2
|
+
export interface Flags {
|
|
3
|
+
[key: string]: number | bigint | string;
|
|
4
|
+
}
|
|
5
|
+
export declare const bitfield: <TName extends string>(name: TName, flags: Flags, message?: string) => SchemaWithPipe<readonly [CustomSchema<string | number | bigint, string>, TitleAction<string | number | bigint, TName>]>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { custom, pipe, title } from "valibot";
|
|
2
|
+
import { isNonNullable } from "../utils/isNonNullable.js";
|
|
3
|
+
export const bitfield = (name, flags, message = `Invalid Bitfield`) => {
|
|
4
|
+
// because enums are bidirectionally indexed, pick only the numerical values
|
|
5
|
+
const flagValues = Object.values(flags).filter(
|
|
6
|
+
// flag enums have numerical values, so remove all the key name strings
|
|
7
|
+
(flag) => !isNaN(Number(flag)));
|
|
8
|
+
if (!flagValues.every((flag) => typeof flag === typeof flagValues[0])) {
|
|
9
|
+
throw new Error(`Provided Flags enum must contain values of the same type`);
|
|
10
|
+
}
|
|
11
|
+
// combine the flags to create a validation mask
|
|
12
|
+
const mask = flagValues.reduce((total, flag) => total | BigInt(flag), 0n);
|
|
13
|
+
return pipe(custom((val) =>
|
|
14
|
+
// short-circuit on null + undefined
|
|
15
|
+
isNonNullable(val) &&
|
|
16
|
+
// only work on supported types
|
|
17
|
+
(typeof val === `number` ||
|
|
18
|
+
typeof val === `bigint` ||
|
|
19
|
+
typeof val === `string`)
|
|
20
|
+
? // validate the value against the given flags
|
|
21
|
+
(BigInt(val) & mask) === BigInt(val)
|
|
22
|
+
: false, message), title(name));
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=bitfield.js.map
|
|
@@ -0,0 +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;AAM1D,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAW,EACX,KAAY,EACZ,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,OAAO,GAAG,KAAK,QAAQ,CAAC;QACxB,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,19 @@
|
|
|
1
|
+
export declare const datauriRegex: RegExp;
|
|
2
|
+
/**
|
|
3
|
+
* Extracts metadata from a given Data URI such as it's
|
|
4
|
+
* MIME type, params, and encoding
|
|
5
|
+
*
|
|
6
|
+
* Returns an empty object when given an invalid Data URI
|
|
7
|
+
*/
|
|
8
|
+
export declare const extractDataURIMetadata: (val: string) => Partial<{
|
|
9
|
+
mediaType: string;
|
|
10
|
+
mimeType: `${string}/${string}`;
|
|
11
|
+
params: string;
|
|
12
|
+
encoding: string;
|
|
13
|
+
data: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const toBase64: (data: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Validates that a string is a [data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)
|
|
18
|
+
*/
|
|
19
|
+
export declare const datauri: import("valibot").SchemaWithPipe<readonly [import("valibot").CustomSchema<string, import("valibot").ErrorMessage<import("valibot").CustomIssue> | undefined>, import("valibot").TitleAction<string, "datauri">]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { custom, is, nonEmpty, pipe, regex, string, title } from "valibot";
|
|
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
|
+
/**
|
|
4
|
+
* Extracts metadata from a given Data URI such as it's
|
|
5
|
+
* MIME type, params, and encoding
|
|
6
|
+
*
|
|
7
|
+
* Returns an empty object when given an invalid Data URI
|
|
8
|
+
*/
|
|
9
|
+
export const extractDataURIMetadata = (val) => datauriRegex.exec(val)?.groups ?? {};
|
|
10
|
+
export const toBase64 = (data) => typeof Buffer !== `undefined`
|
|
11
|
+
? Buffer.from(data, `base64`).toString()
|
|
12
|
+
: atob(btoa(String.fromCharCode(...new TextEncoder().encode(data)))
|
|
13
|
+
.replace(/\+/g, `-`)
|
|
14
|
+
.replace(/\//g, `_`)
|
|
15
|
+
.replace(/=/g, ``));
|
|
16
|
+
/**
|
|
17
|
+
* Validates that a string is a [data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)
|
|
18
|
+
*/
|
|
19
|
+
export const datauri = pipe(custom((val) => is(pipe(string(), nonEmpty(), regex(datauriRegex)), val), `Invalid Data URI`), title(`datauri`));
|
|
20
|
+
//# sourceMappingURL=datauri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datauri.js","sourceRoot":"","sources":["../../src/validations/datauri.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE3E,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,GAAG,IAAI,CACzB,MAAM,CACJ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,EACjE,kBAAkB,CACnB,EACD,KAAK,CAAC,SAAS,CAAC,CACjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CheckAction } from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Validation action to check if the given `datauri` string
|
|
4
|
+
* has one of the provided [MIME types](https://en.wikipedia.org/wiki/Media_type)
|
|
5
|
+
*/
|
|
6
|
+
export declare const hasMimeType: (
|
|
7
|
+
/** an array of MIME types to validate against */
|
|
8
|
+
requirement: Array<`${string}/${string}`>,
|
|
9
|
+
/** an optional error message on failed validation */
|
|
10
|
+
message?: "Received badly formatted Data URI") => CheckAction<string, typeof message>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { check } from "valibot";
|
|
2
|
+
import { extractDataURIMetadata } from "./datauri.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validation action to check if the given `datauri` string
|
|
5
|
+
* has one of the provided [MIME types](https://en.wikipedia.org/wiki/Media_type)
|
|
6
|
+
*/
|
|
7
|
+
export const hasMimeType = (
|
|
8
|
+
/** an array of MIME types to validate against */
|
|
9
|
+
requirement,
|
|
10
|
+
/** an optional error message on failed validation */
|
|
11
|
+
message = `Received badly formatted Data URI`) => check((input) => {
|
|
12
|
+
const { mimeType } = extractDataURIMetadata(input);
|
|
13
|
+
if (typeof mimeType === `undefined`) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return requirement.includes(mimeType);
|
|
17
|
+
}, message);
|
|
18
|
+
//# sourceMappingURL=hasMimeType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasMimeType.js","sourceRoot":"","sources":["../../src/validations/hasMimeType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAoB,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;AACzB,iDAAiD;AACjD,WAAyC;AACzC,qDAAqD;AACrD,UAAU,mCAA4C,EACjB,EAAE,CACvC,KAAK,CAAC,CAAC,KAAa,EAAE,EAAE;IACtB,MAAM,EAAE,QAAQ,EAAE,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { check } from "valibot";
|
|
2
|
+
import { extractDataURIMetadata, toBase64 } from "./datauri.js";
|
|
3
|
+
export const hasSize = (size, message = `Data URI is the incorrect size`) => check((dataURI) => {
|
|
4
|
+
const { data } = extractDataURIMetadata(dataURI);
|
|
5
|
+
if (typeof data === `undefined`) {
|
|
6
|
+
throw new Error(`Received badly formatted Data URI`);
|
|
7
|
+
}
|
|
8
|
+
const actual = toBase64(data).length;
|
|
9
|
+
return typeof size === `number`
|
|
10
|
+
? size === actual
|
|
11
|
+
: actual >= (size.min ?? 0) && actual <= (size.max ?? Infinity);
|
|
12
|
+
}, message);
|
|
13
|
+
//# sourceMappingURL=hasSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasSize.js","sourceRoot":"","sources":["../../src/validations/hasSize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,IAA6C,EAC7C,UAAU,gCAAyC,EACd,EAAE,CACvC,KAAK,CAAC,CAAC,OAAe,EAAE,EAAE;IACxB,MAAM,EAAE,IAAI,EAAE,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEjD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACrC,OAAO,OAAO,IAAI,KAAK,QAAQ;QAC7B,CAAC,CAAC,IAAI,KAAK,MAAM;QACjB,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC;AACpE,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./asDigits.js";
|
|
2
|
+
export * from "./asInteger.js";
|
|
3
|
+
export * from "./bitfield.js";
|
|
4
|
+
export * from "./datauri.js";
|
|
5
|
+
export * from "./hasMimeType.js";
|
|
6
|
+
export * from "./toBlob.js";
|
|
7
|
+
export * from "./snowflake.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
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
|
+
* Converts a `snowflake` string to a Date relative to the given epoch
|
|
5
|
+
*
|
|
6
|
+
* Uses Discord's epoch by default
|
|
7
|
+
*
|
|
8
|
+
* https://discord.com/developers/docs/reference#snowflakes
|
|
9
|
+
*/
|
|
10
|
+
export declare const snowflakeToDate: (
|
|
11
|
+
/** A snowflake string to convert */
|
|
12
|
+
val: string,
|
|
13
|
+
/** time in milliseconds to use as the epoch to derive a Date from */
|
|
14
|
+
epoch?: bigint) => Date;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a Date to a `snowflake` string relative to the given epoch
|
|
17
|
+
*
|
|
18
|
+
* Uses Discord's epoch by default
|
|
19
|
+
*
|
|
20
|
+
* https://discord.com/developers/docs/reference#snowflakes
|
|
21
|
+
*/
|
|
22
|
+
export declare const dateToSnowflake: (
|
|
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;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { custom, pipe, transform, union, string, number, is, title } from "valibot";
|
|
2
|
+
import { isNonNullable } from "../utils/isNonNullable.js";
|
|
3
|
+
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
|
+
/**
|
|
11
|
+
* Converts a `snowflake` string to a Date relative to the given epoch
|
|
12
|
+
*
|
|
13
|
+
* Uses Discord's epoch by default
|
|
14
|
+
*
|
|
15
|
+
* https://discord.com/developers/docs/reference#snowflakes
|
|
16
|
+
*/
|
|
17
|
+
export const snowflakeToDate = (
|
|
18
|
+
/** A snowflake string to convert */
|
|
19
|
+
val,
|
|
20
|
+
/** time in milliseconds to use as the epoch to derive a Date from */
|
|
21
|
+
epoch = DISCORD_EPOCH) => new Date(Number((BigInt(val) >> 22n) + epoch));
|
|
22
|
+
/**
|
|
23
|
+
* Converts a Date to a `snowflake` string relative to the given epoch
|
|
24
|
+
*
|
|
25
|
+
* Uses Discord's epoch by default
|
|
26
|
+
*
|
|
27
|
+
* https://discord.com/developers/docs/reference#snowflakes
|
|
28
|
+
*/
|
|
29
|
+
export const dateToSnowflake = (
|
|
30
|
+
/** A Date to convert to a `snowflake` */
|
|
31
|
+
val,
|
|
32
|
+
/** time in milliseconds to use as the epoch to derive a `snowflake` from */
|
|
33
|
+
epoch = DISCORD_EPOCH) => String((BigInt(val.getMilliseconds()) - epoch) << 22n);
|
|
34
|
+
//# sourceMappingURL=snowflake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snowflake.js","sourceRoot":"","sources":["../../src/validations/snowflake.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,SAAS,EACT,KAAK,EACL,MAAM,EACN,MAAM,EACN,EAAE,EACF,KAAK,EACN,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAE5C,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAC3B,MAAM,CACJ,CAAC,GAAG,EAAE,EAAE,CACN,aAAa,CAAC,GAAG,CAAC;IAClB,CAAC,OAAO,GAAG,KAAK,QAAQ;QACtB,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,KAAK,QAAQ,CAAC;IACxB,CAAC,CAAC,EAAE,CACA,IAAI,CACF,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,EAC3B,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CACtC,EACD,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,aAAa,CAAC,CAC7C;IACH,CAAC,CAAC,KAAK,EACX,sBAAsB,CACvB,EACD,KAAK,CAAC,WAAW,CAAC,CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;AAC7B,oCAAoC;AACpC,GAAW;AACX,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;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;AAC7B,yCAAyC;AACzC,GAAS;AACT,4EAA4E;AAC5E,KAAK,GAAG,aAAa,EACb,EAAE,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { transform } from "valibot";
|
|
2
|
+
import { extractDataURIMetadata, toBase64 } from "./datauri.js";
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a `datauri` string to a Blob
|
|
5
|
+
*/
|
|
6
|
+
export const toBlob = transform((dataURI) => {
|
|
7
|
+
const { mimeType, data } = extractDataURIMetadata(dataURI);
|
|
8
|
+
if (typeof mimeType === `undefined` || typeof data === `undefined`) {
|
|
9
|
+
throw new Error(`Received badly formatted Data URI`);
|
|
10
|
+
}
|
|
11
|
+
const base64 = toBase64(data);
|
|
12
|
+
const ab = new ArrayBuffer(base64.length);
|
|
13
|
+
const ia = new Uint8Array(ab);
|
|
14
|
+
for (let i = 0; i < base64.length; i++) {
|
|
15
|
+
ia[i] = base64.charCodeAt(i);
|
|
16
|
+
}
|
|
17
|
+
return new Blob([ab], { type: mimeType });
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=toBlob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toBlob.js","sourceRoot":"","sources":["../../src/validations/toBlob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,OAAe,EAAQ,EAAE;IACxD,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAE3D,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE9B,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discordkit/core",
|
|
3
3
|
"description": "Core utility functions for Discordkit",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Drake Costa <drake@saeris.gg> (https://saeris.gg)",
|
|
7
7
|
"keywords": [
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"module": "./dist/index.js",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"imports": {
|
|
27
|
+
"#mock-utils": "../../scripts/mock-utils.ts",
|
|
27
28
|
"#test-utils": "../../scripts/test-utils.ts"
|
|
28
29
|
},
|
|
29
30
|
"exports": {
|
|
@@ -43,12 +44,16 @@
|
|
|
43
44
|
"sideEffects": false,
|
|
44
45
|
"scripts": {
|
|
45
46
|
"dev": "yarn build --watch --declarationmap",
|
|
46
|
-
"build": "tsc
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"lint": "eslint --cache"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
|
-
"valibot": ">= 0.
|
|
51
|
+
"valibot": ">= 1.0.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"typescript": "^5.3
|
|
54
|
+
"typescript": "^5.8.3"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"type-fest": "^4.41.0"
|
|
53
58
|
}
|
|
54
59
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DiscordSession.js","sourceRoot":"","sources":["../src/DiscordSession.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,8BAA8B,CAAC;AAEvD,gBAAgB;AAChB,MAAM,OAAO,cAAc;IACzB,QAAQ,GAAW,QAAQ,CAAC;IAC5B,UAAU,GAAkB,IAAI,CAAC;IACjC,IAAI,KAAK;QACP,OAAO,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,YAAY,SAAyB;QACnC,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,QAAQ,GAAG,CAAC,KAAa,EAAQ,EAAE;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CACb,+DAA+D,KAAK,EAAE,CACvE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC,CAAC;IAEF,YAAY,GAAG,GAAS,EAAE;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC,CAAC;IAEF,UAAU,GAAG,GAAW,EAAE;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC;QAE9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;CACH;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
package/dist/addParams.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export type RequestParams = Partial<Record<string, number[] | string[] | boolean | number | string | null | undefined>>;
|
|
2
|
-
export declare const addParams: <P extends Partial<Record<string, string | number | boolean | string[] | number[] | null | undefined>>>(url: URL, params: P) => URL;
|
package/dist/addParams.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addParams.js","sourceRoot":"","sources":["../src/addParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAS/C,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,GAAQ,EACR,MAAS,EACJ,EAAE;IACP,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
package/dist/buildURL.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const buildURL: <P extends Partial<Record<string, string | number | boolean | string[] | number[] | null | undefined>>>(resource: string, params?: P | undefined, base?: string) => URL;
|
package/dist/buildURL.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildURL.js","sourceRoot":"","sources":["../src/buildURL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAsB,MAAM,gBAAgB,CAAC;AAE/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAgB,EAChB,MAAU,EACV,IAAa,EACR,EAAE,CACP,SAAS,CACP,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,IAAI,IAAI,QAAQ,CAAC,EACtD,MAAM,IAAI,EAAE,CACb,CAAC"}
|
package/dist/getAsset.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAsset.js","sourceRoot":"","sources":["../src/getAsset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAgB,EAChB,MAAuC,EAC/B,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,6BAA6B,CAAC,CAAC,IAAI,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isNonNullable.js","sourceRoot":"","sources":["../src/isNonNullable.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAO,EACgB,EAAE,CAAC,OAAO,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,IAAI,CAAC"}
|
package/dist/isObject.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isObject.js","sourceRoot":"","sources":["../src/isObject.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAiB,EAAE,CACtD,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/methods.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AASvC,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EAAK,GAAW,EAAE,MAAsB,EAAc,EAAE,CAC9E,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAK,GAAW,EAAE,IAAkB,EAAc,EAAE,CAC3E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EAAK,GAAW,EAAE,IAAkB,EAAc,EAAE,CAC1E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAK,GAAW,EAAE,IAAkB,EAAc,EAAE,CAC5E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAY,GAAW,EAAc,EAAE,CAChE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC"}
|
package/dist/request.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { discord } from "./DiscordSession.js";
|
|
2
|
-
import { toCamelKeys } from "./toCamelKeys.js";
|
|
3
|
-
import { toSnakeKeys } from "./toSnakeKeys.js";
|
|
4
|
-
export const request = async (resource, method = `GET`, body) => {
|
|
5
|
-
const token = discord.getSession();
|
|
6
|
-
if (!token) {
|
|
7
|
-
throw new Error(`Auth Token must be set before requests can be made.`);
|
|
8
|
-
}
|
|
9
|
-
const res = await fetch(resource.toString(), {
|
|
10
|
-
method,
|
|
11
|
-
body: body ? JSON.stringify(toSnakeKeys(body)) : body,
|
|
12
|
-
headers: {
|
|
13
|
-
Authorization: token
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
if (!res.ok) {
|
|
17
|
-
throw new Error(`Request to resource '${resource.toString()}' failed:\n\n${res.statusText}`);
|
|
18
|
-
}
|
|
19
|
-
return toCamelKeys(await res.json());
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=request.js.map
|
package/dist/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAC1B,QAAa,EACb,MAAM,GAAG,KAAK,EACd,IAAkB,EACN,EAAE;IACd,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAEnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE;QAC3C,MAAM;QACN,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;QACrD,OAAO,EAAE;YACP,aAAa,EAAE,KAAK;SACrB;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,wBAAwB,QAAQ,CAAC,QAAQ,EAAE,gBACzC,GAAG,CAAC,UACN,EAAE,CACH,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACvC,CAAC,CAAC"}
|
package/dist/snowflake.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const snowflake: import("valibot").SpecialSchema<string, string>;
|
package/dist/snowflake.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { special, coerce, date, is } from "valibot";
|
|
2
|
-
import { isNonNullable } from "./isNonNullable.js";
|
|
3
|
-
export const snowflake = special((val) => isNonNullable(val) &&
|
|
4
|
-
(typeof val === `bigint` ||
|
|
5
|
-
typeof val === `number` ||
|
|
6
|
-
typeof val === `string`)
|
|
7
|
-
? is(coerce(date(), (input) => new Date(input)),
|
|
8
|
-
// eslint-disable-next-line no-bitwise
|
|
9
|
-
Number((BigInt(val) >> 22n) + 1420070400000n))
|
|
10
|
-
: false, `Invalid Snowflake ID`);
|
|
11
|
-
//# sourceMappingURL=snowflake.js.map
|
package/dist/snowflake.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snowflake.js","sourceRoot":"","sources":["../src/snowflake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAC9B,CAAC,GAAG,EAAE,EAAE,CACN,aAAa,CAAC,GAAG,CAAC;IAClB,CAAC,OAAO,GAAG,KAAK,QAAQ;QACtB,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,KAAK,QAAQ,CAAC;IACxB,CAAC,CAAC,EAAE,CACA,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,sCAAsC;IACtC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,cAAc,CAAC,CAC9C;IACH,CAAC,CAAC,KAAK,EACX,sBAAsB,CACvB,CAAC"}
|
package/dist/toCamelCase.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toCamelCase.js","sourceRoot":"","sources":["../src/toCamelCase.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE,CACjD,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC"}
|
package/dist/toCamelKeys.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toCamelKeys.js","sourceRoot":"","sources":["../src/toCamelKeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,CAAI,EACyB,EAAE;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC,GAAG,CAAC,WAAW,CAAgC,CAAC;IAC3D,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpD,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAgC,CAAC;IACxC,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC,CAAC"}
|
package/dist/toProcedure.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { BaseSchema, Output } from "valibot";
|
|
2
|
-
import type { AnyRootConfig, inferParser, Procedure, unsetMarker } from "@trpc/server";
|
|
3
|
-
import { type Wrap } from "./wrap.js";
|
|
4
|
-
import type { Fetcher } from "./methods.js";
|
|
5
|
-
type Result<T = void> = T extends BaseSchema ? Output<T> : T;
|
|
6
|
-
type UnsetMarker = typeof unsetMarker;
|
|
7
|
-
type BaseProcedure<T extends "mutation" | "query" | "subscription", I extends BaseSchema | null = null, O extends BaseSchema | null = null> = Procedure<T, {
|
|
8
|
-
_config: AnyRootConfig;
|
|
9
|
-
_ctx_out: object;
|
|
10
|
-
_input_in: I extends BaseSchema ? inferParser<Wrap<I>>["in"] : UnsetMarker;
|
|
11
|
-
_input_out: I extends BaseSchema ? inferParser<Wrap<I>>["out"] : UnsetMarker;
|
|
12
|
-
_output_in: O extends BaseSchema ? inferParser<Wrap<O>>["in"] : UnsetMarker;
|
|
13
|
-
_output_out: O extends BaseSchema ? inferParser<Wrap<O>>["out"] : UnsetMarker;
|
|
14
|
-
_meta: object;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* Given a {@link Fetcher | Fetcher} function and it's associated input and
|
|
18
|
-
* output Zod schemas, this produces a function which accepts a tRPC procedure
|
|
19
|
-
* builder of the given procedure type. This can then be used in a tRPC router
|
|
20
|
-
* to scaffold an API route to forward a request to Discord's API.
|
|
21
|
-
*/
|
|
22
|
-
export declare const toProcedure: <T extends "query" | "mutation" | "subscription", I extends BaseSchema | null = null, O extends BaseSchema | null = null>(type: T, fn: Fetcher<I extends BaseSchema ? I : null, Result<O>>, input?: I | undefined, output?: O | undefined) => (procedure: import("@trpc/server").ProcedureBuilder<{
|
|
23
|
-
_config: import("@trpc/server").RootConfig<{
|
|
24
|
-
ctx: object;
|
|
25
|
-
meta: object;
|
|
26
|
-
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
27
|
-
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
28
|
-
}>;
|
|
29
|
-
_ctx_out: object;
|
|
30
|
-
_input_in: typeof unsetMarker;
|
|
31
|
-
_input_out: typeof unsetMarker;
|
|
32
|
-
_output_in: typeof unsetMarker;
|
|
33
|
-
_output_out: typeof unsetMarker;
|
|
34
|
-
_meta: object;
|
|
35
|
-
}>) => BaseProcedure<T, I, O>;
|
|
36
|
-
export {};
|
package/dist/toProcedure.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toProcedure.js","sourceRoot":"","sources":["../src/toProcedure.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAa,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA8BnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,CAKE,IAAO,EACP,EAAuD,EACvD,KAAS,EACT,MAAU,EACV,EAAE,CACJ,CAAC,SAA2B,EAA0B,EAAE;IACtD,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,mBAAmB;QACnB,OAAO,SAAS;aACb,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAClB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CACpB,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,mBAAmB;QACnB,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,mBAAmB;QACnB,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,mBAAmB;IACnB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC,CAAC"}
|
package/dist/toQuery.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toQuery.js","sourceRoot":"","sources":["../src/toQuery.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAClB,CACE,EAAK,EAGiE,EAAE;AAC1E,mBAAmB;AACnB,CAAC,GAAG,MAAiB,EAAE,EAAE,CACzB,KAAK,IAAI,EAAE,CACT,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC"}
|
package/dist/toSnakeCase.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toSnakeCase.js","sourceRoot":"","sources":["../src/toSnakeCase.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE,CACjD,GAAG;KACA,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;KACzD,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/toSnakeKeys.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toSnakeKeys.js","sourceRoot":"","sources":["../src/toSnakeKeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,CAAI,EACyB,EAAE;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC,GAAG,CAAC,WAAW,CAAgC,CAAC;IAC3D,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACpD,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAgC,CAAC;IACxC,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC,CAAC"}
|
package/dist/toValidated.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BaseSchema, Output } from "valibot";
|
|
2
|
-
import type { Fetcher } from "./methods.js";
|
|
3
|
-
type ToValidated = <F extends Fetcher<BaseSchema, Output<BaseSchema>> | Fetcher<BaseSchema> | Fetcher<null, null> | Fetcher<null, Output<BaseSchema>>>(...args: F extends Fetcher<infer I, ReturnType<F> extends Promise<void> ? never : Output<BaseSchema & infer O>> ? [fn: F, input: I, output: O] : F extends Fetcher<null, ReturnType<F> extends Promise<void> ? never : Output<BaseSchema & infer O>> ? [fn: F, input: null, output: O] : F extends Fetcher<infer I> ? [fn: F, input: I] : F extends Fetcher<null, null> ? [fn: F] : never) => F;
|
|
4
|
-
/**
|
|
5
|
-
* Given a {@link Fetcher | Fetcher} function and it's associated input
|
|
6
|
-
* and output Zod schemas, this returns a new validated {@link Fetcher | Fetcher} function which will validate it's input and result at runtime.
|
|
7
|
-
* This is useful in contexts where you want strong guarantees on runtime
|
|
8
|
-
* type-safety when dealing with raw user input in a framework agnostic
|
|
9
|
-
* environment.
|
|
10
|
-
*/
|
|
11
|
-
export declare const toValidated: ToValidated;
|
|
12
|
-
export {};
|
package/dist/toValidated.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isNonNullable } from "./isNonNullable.js";
|
|
2
|
-
import { isObject } from "./isObject.js";
|
|
3
|
-
const isSchema = (val) => isNonNullable(val) && isObject(val) && `_parse` in val;
|
|
4
|
-
/**
|
|
5
|
-
* Given a {@link Fetcher | Fetcher} function and it's associated input
|
|
6
|
-
* and output Zod schemas, this returns a new validated {@link Fetcher | Fetcher} function which will validate it's input and result at runtime.
|
|
7
|
-
* This is useful in contexts where you want strong guarantees on runtime
|
|
8
|
-
* type-safety when dealing with raw user input in a framework agnostic
|
|
9
|
-
* environment.
|
|
10
|
-
*/
|
|
11
|
-
export const toValidated = (fn, input, output) =>
|
|
12
|
-
// @ts-expect-error
|
|
13
|
-
async (config) => {
|
|
14
|
-
if (isSchema(input)) {
|
|
15
|
-
input._parse(config);
|
|
16
|
-
}
|
|
17
|
-
const result = await fn(config);
|
|
18
|
-
if (isSchema(output)) {
|
|
19
|
-
output._parse(result);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=toValidated.js.map
|
package/dist/toValidated.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toValidated.js","sourceRoot":"","sources":["../src/toValidated.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAqB,EAAE,CACnD,aAAa,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,IAAI,GAAG,CAAC;AA4BzD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;AACtB,mBAAmB;AACnB,KAAK,EAAE,MAAM,EAAE,EAAE;IACf,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAEhC,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/wrap.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type BaseSchema, type BaseSchemaAsync, type Input, type Output } from "valibot";
|
|
2
|
-
export interface ValidationIssue {
|
|
3
|
-
message: string;
|
|
4
|
-
path?: unknown[];
|
|
5
|
-
}
|
|
6
|
-
export interface TypeSchema<TOutput, TInput = TOutput> {
|
|
7
|
-
_input: TInput;
|
|
8
|
-
_output: TOutput;
|
|
9
|
-
assert(data: unknown): Promise<TOutput>;
|
|
10
|
-
parse(data: unknown): Promise<TOutput>;
|
|
11
|
-
validate(data: unknown): Promise<{
|
|
12
|
-
data: TOutput;
|
|
13
|
-
} | {
|
|
14
|
-
issues: ValidationIssue[];
|
|
15
|
-
}>;
|
|
16
|
-
}
|
|
17
|
-
export type Wrap<T extends BaseSchema | BaseSchemaAsync> = TypeSchema<Output<T>, Input<T>>;
|
|
18
|
-
export declare function wrap<TSchema extends BaseSchema | BaseSchemaAsync>(schema: TSchema): TypeSchema<Output<TSchema>, Input<TSchema>>;
|
package/dist/wrap.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { safeParseAsync } from "valibot";
|
|
2
|
-
// Adapted from https://github.com/decs/typeschema
|
|
3
|
-
export function wrap(schema) {
|
|
4
|
-
const validate = async (data) => {
|
|
5
|
-
const result = await safeParseAsync(schema, data);
|
|
6
|
-
if (result.success) {
|
|
7
|
-
return {
|
|
8
|
-
data: result.output
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
issues: result.issues.map(({ message, path }) => ({
|
|
13
|
-
message,
|
|
14
|
-
path: path?.map(({ key }) => key) ?? []
|
|
15
|
-
}))
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
const assert = async (data) => {
|
|
19
|
-
const result = await validate(data);
|
|
20
|
-
if (`data` in result)
|
|
21
|
-
return result.data;
|
|
22
|
-
throw new AggregateError(result.issues, `Assertion failed`);
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
// eslint-disable-next-line no-undefined
|
|
26
|
-
_input: undefined,
|
|
27
|
-
// eslint-disable-next-line no-undefined
|
|
28
|
-
_output: undefined,
|
|
29
|
-
assert,
|
|
30
|
-
parse: assert,
|
|
31
|
-
validate
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=wrap.js.map
|
package/dist/wrap.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../src/wrap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAKf,MAAM,SAAS,CAAC;AAsBjB,kDAAkD;AAClD,MAAM,UAAU,IAAI,CAClB,MAAe;IAEf,MAAM,QAAQ,GAAG,KAAK,EACpB,IAAa,EACuD,EAAE;QACtE,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAClD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,MAAM;aACpB,CAAC;QACJ,CAAC;QACD,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBAChD,OAAO;gBACP,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE;aACxC,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,KAAK,EAAE,IAAa,EAA4B,EAAE;QAC/D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,MAAM,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC,IAAI,CAAC;QACzC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC9D,CAAC,CAAC;IAEF,OAAO;QACL,wCAAwC;QACxC,MAAM,EAAE,SAAiC;QACzC,wCAAwC;QACxC,OAAO,EAAE,SAAkC;QAC3C,MAAM;QACN,KAAK,EAAE,MAAM;QACb,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|