@sapphire/plugin-api 7.0.0-next.7ba75bc → 7.0.0-next.821ff70
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/cjs/index.cjs +5 -24
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +79 -82
- package/dist/cjs/lib/structures/Route.cjs +0 -5
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs +128 -4
- package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpMethods.cjs +1 -0
- package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs +1 -8
- package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterRoot.cjs +0 -1
- package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -1
- package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs +100 -0
- package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs.map +1 -0
- package/dist/cjs/lib/utils/_body/RequestProxy.cjs +123 -0
- package/dist/cjs/lib/utils/_body/RequestProxy.cjs.map +1 -0
- package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs +179 -0
- package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs.map +1 -0
- package/dist/cjs/lib/utils/constants.cjs +8 -0
- package/dist/cjs/lib/utils/constants.cjs.map +1 -0
- package/dist/cjs/listeners/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/body.cjs +1 -17
- package/dist/cjs/middlewares/body.cjs.map +1 -1
- package/dist/cjs/register.cjs +2 -3
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/cjs/register.d.cts +0 -1
- package/dist/cjs/routes/_load.cjs.map +1 -1
- package/dist/cjs/routes/oauth/callback.post.cjs +1 -1
- package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -1
- package/dist/esm/index.d.mts +79 -82
- package/dist/esm/index.mjs +1 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/Route.mjs +0 -5
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs +122 -5
- package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpMethods.mjs +1 -0
- package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Server.mjs +1 -8
- package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterRoot.mjs +0 -1
- package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -1
- package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs +95 -0
- package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs.map +1 -0
- package/dist/esm/lib/utils/_body/RequestProxy.mjs +111 -0
- package/dist/esm/lib/utils/_body/RequestProxy.mjs.map +1 -0
- package/dist/esm/lib/utils/_body/RequestURLProxy.mjs +167 -0
- package/dist/esm/lib/utils/_body/RequestURLProxy.mjs.map +1 -0
- package/dist/esm/lib/utils/constants.mjs +8 -0
- package/dist/esm/lib/utils/constants.mjs.map +1 -0
- package/dist/esm/listeners/_load.mjs.map +1 -1
- package/dist/esm/middlewares/_load.mjs.map +1 -1
- package/dist/esm/middlewares/body.mjs +2 -16
- package/dist/esm/middlewares/body.mjs.map +1 -1
- package/dist/esm/register.d.mts +0 -1
- package/dist/esm/register.mjs +2 -3
- package/dist/esm/register.mjs.map +1 -1
- package/dist/esm/routes/_load.mjs.map +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/cjs/lib/structures/MediaParser.cjs +0 -79
- package/dist/cjs/lib/structures/MediaParser.cjs.map +0 -1
- package/dist/cjs/lib/structures/MediaParserStore.cjs +0 -27
- package/dist/cjs/lib/structures/MediaParserStore.cjs.map +0 -1
- package/dist/cjs/mediaParsers/_load.cjs +0 -20
- package/dist/cjs/mediaParsers/_load.cjs.map +0 -1
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +0 -22
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +0 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs +0 -21
- package/dist/cjs/mediaParsers/applicationJson.cjs.map +0 -1
- package/dist/cjs/mediaParsers/textPlain.cjs +0 -21
- package/dist/cjs/mediaParsers/textPlain.cjs.map +0 -1
- package/dist/esm/lib/structures/MediaParser.mjs +0 -76
- package/dist/esm/lib/structures/MediaParser.mjs.map +0 -1
- package/dist/esm/lib/structures/MediaParserStore.mjs +0 -24
- package/dist/esm/lib/structures/MediaParserStore.mjs.map +0 -1
- package/dist/esm/mediaParsers/_load.mjs +0 -17
- package/dist/esm/mediaParsers/_load.mjs.map +0 -1
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +0 -19
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +0 -1
- package/dist/esm/mediaParsers/applicationJson.mjs +0 -18
- package/dist/esm/mediaParsers/applicationJson.mjs.map +0 -1
- package/dist/esm/mediaParsers/textPlain.mjs +0 -18
- package/dist/esm/mediaParsers/textPlain.mjs.map +0 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { __name, __publicField, __privateAdd, __privateSet, __privateGet } from '../../../chunk-S573YWRP.mjs';
|
|
2
|
+
import { isNullish, isNullishOrEmpty } from '@sapphire/utilities';
|
|
3
|
+
import { Blob } from 'node:buffer';
|
|
4
|
+
import { arrayBuffer } from 'node:stream/consumers';
|
|
5
|
+
import { ReadableStream } from 'node:stream/web';
|
|
6
|
+
import { RequestHeadersProxy } from './RequestHeadersProxy.mjs';
|
|
7
|
+
import { RequestURLProxy } from './RequestURLProxy.mjs';
|
|
8
|
+
|
|
9
|
+
var _request, _url, _cachedMethod, _cachedHasBody, _abortController, _bodyStream;
|
|
10
|
+
var _RequestProxy = class _RequestProxy {
|
|
11
|
+
constructor(request) {
|
|
12
|
+
__publicField(this, "cache", "default");
|
|
13
|
+
__publicField(this, "credentials", "same-origin");
|
|
14
|
+
__publicField(this, "destination", "");
|
|
15
|
+
__publicField(this, "integrity", "");
|
|
16
|
+
__publicField(this, "keepalive", false);
|
|
17
|
+
__publicField(this, "mode", "cors");
|
|
18
|
+
__publicField(this, "redirect", "follow");
|
|
19
|
+
__publicField(this, "referrer", "about:client");
|
|
20
|
+
__publicField(this, "referrerPolicy", "");
|
|
21
|
+
__publicField(this, "headers");
|
|
22
|
+
__publicField(this, "bodyUsed", false);
|
|
23
|
+
__publicField(this, "duplex", "half");
|
|
24
|
+
__privateAdd(this, _request);
|
|
25
|
+
__privateAdd(this, _url);
|
|
26
|
+
__privateAdd(this, _cachedMethod, null);
|
|
27
|
+
__privateAdd(this, _cachedHasBody, null);
|
|
28
|
+
__privateAdd(this, _abortController, null);
|
|
29
|
+
__privateAdd(this, _bodyStream, null);
|
|
30
|
+
__privateSet(this, _request, request);
|
|
31
|
+
__privateSet(this, _url, new RequestURLProxy(request));
|
|
32
|
+
this.headers = new RequestHeadersProxy(request);
|
|
33
|
+
}
|
|
34
|
+
get url() {
|
|
35
|
+
return __privateGet(this, _url).href;
|
|
36
|
+
}
|
|
37
|
+
get method() {
|
|
38
|
+
__privateGet(this, _cachedMethod) ?? __privateSet(this, _cachedMethod, __privateGet(this, _request).method?.toUpperCase() ?? "GET");
|
|
39
|
+
return __privateGet(this, _cachedMethod);
|
|
40
|
+
}
|
|
41
|
+
get signal() {
|
|
42
|
+
__privateGet(this, _abortController) ?? __privateSet(this, _abortController, new AbortController());
|
|
43
|
+
return __privateGet(this, _abortController).signal;
|
|
44
|
+
}
|
|
45
|
+
get body() {
|
|
46
|
+
if (!this.hasBody) return null;
|
|
47
|
+
__privateGet(this, _bodyStream) ?? __privateSet(this, _bodyStream, new ReadableStream({
|
|
48
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
49
|
+
__privateGet(this, _request).on("data", (chunk) => controller.enqueue(chunk)).once("error", (error) => {
|
|
50
|
+
controller.error(error);
|
|
51
|
+
__privateGet(this, _abortController)?.abort();
|
|
52
|
+
}).once("close", () => {
|
|
53
|
+
__privateGet(this, _abortController)?.abort();
|
|
54
|
+
}).once("end", () => {
|
|
55
|
+
controller.close();
|
|
56
|
+
});
|
|
57
|
+
}, "start")
|
|
58
|
+
}));
|
|
59
|
+
return __privateGet(this, _bodyStream);
|
|
60
|
+
}
|
|
61
|
+
async arrayBuffer() {
|
|
62
|
+
const { body } = this;
|
|
63
|
+
return isNullish(body) ? new ArrayBuffer(0) : arrayBuffer(body);
|
|
64
|
+
}
|
|
65
|
+
async blob() {
|
|
66
|
+
const arrayBuffer2 = await this.arrayBuffer();
|
|
67
|
+
return new Blob([arrayBuffer2], {
|
|
68
|
+
type: this.headers.get("content-type") ?? ""
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async formData() {
|
|
72
|
+
return new Response(this.body, { headers: this.headers }).formData();
|
|
73
|
+
}
|
|
74
|
+
async json() {
|
|
75
|
+
return JSON.parse(await this.text());
|
|
76
|
+
}
|
|
77
|
+
async text() {
|
|
78
|
+
return new TextDecoder().decode(await this.arrayBuffer());
|
|
79
|
+
}
|
|
80
|
+
clone() {
|
|
81
|
+
return new _RequestProxy(__privateGet(this, _request));
|
|
82
|
+
}
|
|
83
|
+
get hasBody() {
|
|
84
|
+
if (__privateGet(this, _cachedHasBody) !== null) return __privateGet(this, _cachedHasBody);
|
|
85
|
+
const contentLengthString = this.headers.get("content-length");
|
|
86
|
+
const contentLength = isNullishOrEmpty(contentLengthString) ? 0 : Number(contentLengthString);
|
|
87
|
+
if (Number.isSafeInteger(contentLength) && contentLength > 0) {
|
|
88
|
+
__privateSet(this, _cachedHasBody, true);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
const transferEncoding = this.headers.get("transfer-encoding");
|
|
92
|
+
if (transferEncoding?.includes("chunked")) {
|
|
93
|
+
__privateSet(this, _cachedHasBody, true);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
__privateSet(this, _cachedHasBody, false);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
_request = new WeakMap();
|
|
101
|
+
_url = new WeakMap();
|
|
102
|
+
_cachedMethod = new WeakMap();
|
|
103
|
+
_cachedHasBody = new WeakMap();
|
|
104
|
+
_abortController = new WeakMap();
|
|
105
|
+
_bodyStream = new WeakMap();
|
|
106
|
+
__name(_RequestProxy, "RequestProxy");
|
|
107
|
+
var RequestProxy = _RequestProxy;
|
|
108
|
+
|
|
109
|
+
export { RequestProxy };
|
|
110
|
+
//# sourceMappingURL=RequestProxy.mjs.map
|
|
111
|
+
//# sourceMappingURL=RequestProxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/utils/_body/RequestProxy.ts"],"names":["arrayBuffer"],"mappings":";;;;;;;;AAAA,IAAA,QAAA,EAAA,IAAA,EAAA,aAAA,EAAA,cAAA,EAAA,gBAAA,EAAA,WAAA,CAAA;AAoBO,IAAM,aAAA,GAAN,MAAM,aAAgC,CAAA;AAAA,EAwBrC,YAAY,OAAqB,EAAA;AAvBxC,IAAA,aAAA,CAAA,IAAA,EAAO,OAAsB,EAAA,SAAA,CAAA,CAAA;AAC7B,IAAA,aAAA,CAAA,IAAA,EAAO,aAAkC,EAAA,aAAA,CAAA,CAAA;AACzC,IAAA,aAAA,CAAA,IAAA,EAAO,aAAkC,EAAA,EAAA,CAAA,CAAA;AACzC,IAAA,aAAA,CAAA,IAAA,EAAO,WAAoB,EAAA,EAAA,CAAA,CAAA;AAC3B,IAA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","sourcesContent":["import { isNullish, isNullishOrEmpty } from '@sapphire/utilities';\nimport { Blob } from 'node:buffer';\nimport { arrayBuffer } from 'node:stream/consumers';\nimport { ReadableStream } from 'node:stream/web';\nimport type {\n\tFormData,\n\tHeaders,\n\tReferrerPolicy,\n\tRequest,\n\tRequestCache,\n\tRequestCredentials,\n\tRequestDestination,\n\tRequestMode,\n\tRequestRedirect\n} from 'undici';\nimport type { ApiRequest } from '../../structures/api/ApiRequest';\nimport type { MethodName } from '../../structures/http/HttpMethods';\nimport { RequestHeadersProxy } from './RequestHeadersProxy';\nimport { RequestURLProxy } from './RequestURLProxy';\n\nexport class RequestProxy implements Request {\n\tpublic cache: RequestCache = 'default';\n\tpublic credentials: RequestCredentials = 'same-origin';\n\tpublic destination: RequestDestination = '';\n\tpublic integrity: string = '';\n\tpublic keepalive: boolean = false;\n\n\tpublic mode: RequestMode = 'cors';\n\tpublic redirect: RequestRedirect = 'follow';\n\tpublic referrer: string = 'about:client';\n\tpublic referrerPolicy: ReferrerPolicy = '';\n\n\tpublic headers: Headers;\n\n\tpublic bodyUsed: boolean = false;\n\tpublic duplex = 'half' as const;\n\n\treadonly #request: ApiRequest;\n\treadonly #url: RequestURLProxy;\n\t#cachedMethod: MethodName | null = null;\n\t#cachedHasBody: boolean | null = null;\n\t#abortController: AbortController | null = null;\n\t#bodyStream: ReadableStream<Uint8Array> | null = null;\n\n\tpublic constructor(request: ApiRequest) {\n\t\tthis.#request = request;\n\t\tthis.#url = new RequestURLProxy(request);\n\t\tthis.headers = new RequestHeadersProxy(request);\n\t}\n\n\tpublic get url(): string {\n\t\treturn this.#url.href;\n\t}\n\n\tpublic get method(): MethodName {\n\t\tthis.#cachedMethod ??= (this.#request.method?.toUpperCase() ?? 'GET') as MethodName;\n\t\treturn this.#cachedMethod;\n\t}\n\n\tpublic get signal() {\n\t\tthis.#abortController ??= new AbortController();\n\t\treturn this.#abortController.signal;\n\t}\n\n\tpublic get body(): ReadableStream<Uint8Array> | null {\n\t\tif (!this.hasBody) return null;\n\n\t\tthis.#bodyStream ??= new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#request\n\t\t\t\t\t.on('data', (chunk) => controller.enqueue(chunk))\n\t\t\t\t\t.once('error', (error) => {\n\t\t\t\t\t\tcontroller.error(error);\n\t\t\t\t\t\tthis.#abortController?.abort();\n\t\t\t\t\t})\n\t\t\t\t\t.once('close', () => {\n\t\t\t\t\t\tthis.#abortController?.abort();\n\t\t\t\t\t})\n\t\t\t\t\t.once('end', () => {\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\treturn this.#bodyStream;\n\t}\n\n\tpublic async arrayBuffer(): Promise<ArrayBuffer> {\n\t\tconst { body } = this;\n\t\treturn isNullish(body) ? new ArrayBuffer(0) : arrayBuffer(body);\n\t}\n\n\tpublic async blob(): Promise<Blob> {\n\t\tconst arrayBuffer = await this.arrayBuffer();\n\t\treturn new Blob([arrayBuffer], {\n\t\t\ttype: this.headers.get('content-type') ?? ''\n\t\t});\n\t}\n\n\tpublic async formData(): Promise<FormData> {\n\t\treturn new Response(this.body, { headers: this.headers }).formData(); // NOSONAR\n\t}\n\n\tpublic async json(): Promise<unknown> {\n\t\treturn JSON.parse(await this.text());\n\t}\n\n\tpublic async text(): Promise<string> {\n\t\treturn new TextDecoder().decode(await this.arrayBuffer());\n\t}\n\n\tpublic clone(): Request {\n\t\treturn new RequestProxy(this.#request);\n\t}\n\n\tprivate get hasBody() {\n\t\tif (this.#cachedHasBody !== null) return this.#cachedHasBody;\n\n\t\tconst contentLengthString = this.headers.get('content-length');\n\t\tconst contentLength = isNullishOrEmpty(contentLengthString) ? 0 : Number(contentLengthString);\n\t\tif (Number.isSafeInteger(contentLength) && contentLength > 0) {\n\t\t\tthis.#cachedHasBody = true;\n\t\t\treturn true;\n\t\t}\n\n\t\tconst transferEncoding = this.headers.get('transfer-encoding');\n\t\tif (transferEncoding?.includes('chunked')) {\n\t\t\tthis.#cachedHasBody = true;\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.#cachedHasBody = false;\n\t\treturn false;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { __name, __publicField, __privateAdd, __privateSet, __privateGet } from '../../../chunk-S573YWRP.mjs';
|
|
2
|
+
import { isNullishOrEmpty } from '@sapphire/utilities';
|
|
3
|
+
import { NodeUtilInspectSymbol } from '../constants.mjs';
|
|
4
|
+
|
|
5
|
+
var _protocol, _hostname, _port, _pathname, _search, _searchParams, _request;
|
|
6
|
+
var _RequestURLProxy = class _RequestURLProxy {
|
|
7
|
+
constructor(request) {
|
|
8
|
+
__publicField(this, "hash", "");
|
|
9
|
+
__publicField(this, "password", "");
|
|
10
|
+
__publicField(this, "username", "");
|
|
11
|
+
__privateAdd(this, _protocol, null);
|
|
12
|
+
__privateAdd(this, _hostname, null);
|
|
13
|
+
__privateAdd(this, _port, null);
|
|
14
|
+
__privateAdd(this, _pathname, null);
|
|
15
|
+
__privateAdd(this, _search, null);
|
|
16
|
+
__privateAdd(this, _searchParams, null);
|
|
17
|
+
__privateAdd(this, _request);
|
|
18
|
+
__privateSet(this, _request, request);
|
|
19
|
+
}
|
|
20
|
+
get host() {
|
|
21
|
+
return __privateGet(this, _request).headers.host ?? "";
|
|
22
|
+
}
|
|
23
|
+
set host(value) {
|
|
24
|
+
__privateSet(this, _hostname, null);
|
|
25
|
+
__privateSet(this, _port, null);
|
|
26
|
+
__privateGet(this, _request).headers.host = value;
|
|
27
|
+
}
|
|
28
|
+
get hostname() {
|
|
29
|
+
if (__privateGet(this, _hostname) === null) {
|
|
30
|
+
const [hostname, port] = parseHost(__privateGet(this, _request).headers.host);
|
|
31
|
+
__privateSet(this, _hostname, hostname);
|
|
32
|
+
__privateSet(this, _port, port === -1 ? "" : String(port));
|
|
33
|
+
}
|
|
34
|
+
return __privateGet(this, _hostname);
|
|
35
|
+
}
|
|
36
|
+
set hostname(value) {
|
|
37
|
+
__privateSet(this, _hostname, value);
|
|
38
|
+
}
|
|
39
|
+
get port() {
|
|
40
|
+
if (__privateGet(this, _port) === null) {
|
|
41
|
+
const [hostname, port] = parseHost(__privateGet(this, _request).headers.host);
|
|
42
|
+
__privateSet(this, _hostname, hostname);
|
|
43
|
+
__privateSet(this, _port, port === -1 ? String(__privateGet(this, _request).socket.localPort ?? "") : String(port));
|
|
44
|
+
}
|
|
45
|
+
return __privateGet(this, _port);
|
|
46
|
+
}
|
|
47
|
+
set port(value) {
|
|
48
|
+
__privateSet(this, _port, String(Number(value || "")));
|
|
49
|
+
}
|
|
50
|
+
get pathname() {
|
|
51
|
+
if (__privateGet(this, _pathname) === null) {
|
|
52
|
+
const [pathname, search] = parsePath(__privateGet(this, _request).url);
|
|
53
|
+
__privateSet(this, _pathname, pathname);
|
|
54
|
+
__privateGet(this, _search) ?? __privateSet(this, _search, search);
|
|
55
|
+
}
|
|
56
|
+
return __privateGet(this, _pathname);
|
|
57
|
+
}
|
|
58
|
+
set pathname(value) {
|
|
59
|
+
const normalized = value.startsWith("/") ? value : `/${value}`;
|
|
60
|
+
if (normalized === __privateGet(this, _pathname)) return;
|
|
61
|
+
__privateSet(this, _pathname, normalized);
|
|
62
|
+
__privateGet(this, _request).url = normalized + this.search;
|
|
63
|
+
}
|
|
64
|
+
get search() {
|
|
65
|
+
if (__privateGet(this, _search) === null) {
|
|
66
|
+
const [pathname, search] = parsePath(__privateGet(this, _request).url);
|
|
67
|
+
__privateGet(this, _pathname) ?? __privateSet(this, _pathname, pathname);
|
|
68
|
+
__privateSet(this, _search, search);
|
|
69
|
+
}
|
|
70
|
+
return __privateGet(this, _search);
|
|
71
|
+
}
|
|
72
|
+
set search(value) {
|
|
73
|
+
let normalized;
|
|
74
|
+
if (value === "?") {
|
|
75
|
+
normalized = "";
|
|
76
|
+
} else if (value && !value.startsWith("?")) {
|
|
77
|
+
normalized = `?${value}`;
|
|
78
|
+
} else {
|
|
79
|
+
normalized = value;
|
|
80
|
+
}
|
|
81
|
+
if (normalized === __privateGet(this, _search)) return;
|
|
82
|
+
__privateSet(this, _search, normalized);
|
|
83
|
+
__privateSet(this, _searchParams, null);
|
|
84
|
+
__privateGet(this, _request).url = this.pathname + normalized;
|
|
85
|
+
}
|
|
86
|
+
get searchParams() {
|
|
87
|
+
__privateGet(this, _searchParams) ?? __privateSet(this, _searchParams, new URLSearchParams(this.search));
|
|
88
|
+
return __privateGet(this, _searchParams);
|
|
89
|
+
}
|
|
90
|
+
set searchParams(value) {
|
|
91
|
+
__privateSet(this, _searchParams, value);
|
|
92
|
+
this.search = value.toString();
|
|
93
|
+
}
|
|
94
|
+
get protocol() {
|
|
95
|
+
__privateGet(this, _protocol) ?? __privateSet(this, _protocol, __privateGet(this, _request).socket.encrypted || __privateGet(this, _request).headers["x-forwarded-proto"] === "https" ? "https:" : "http:");
|
|
96
|
+
return __privateGet(this, _protocol);
|
|
97
|
+
}
|
|
98
|
+
set protocol(value) {
|
|
99
|
+
__privateSet(this, _protocol, value);
|
|
100
|
+
}
|
|
101
|
+
get origin() {
|
|
102
|
+
return `${this.protocol}//${this.host}`;
|
|
103
|
+
}
|
|
104
|
+
set origin(_value) {
|
|
105
|
+
}
|
|
106
|
+
get href() {
|
|
107
|
+
return `${this.protocol}//${this.host}${this.pathname}${this.search}`;
|
|
108
|
+
}
|
|
109
|
+
set href(value) {
|
|
110
|
+
const url = new URL(value);
|
|
111
|
+
__privateSet(this, _protocol, url.protocol);
|
|
112
|
+
this.username = url.username;
|
|
113
|
+
this.password = url.password;
|
|
114
|
+
__privateSet(this, _hostname, url.hostname);
|
|
115
|
+
__privateSet(this, _port, url.port);
|
|
116
|
+
__privateSet(this, _pathname, url.pathname);
|
|
117
|
+
__privateSet(this, _search, url.search);
|
|
118
|
+
this.hash = url.hash;
|
|
119
|
+
}
|
|
120
|
+
toString() {
|
|
121
|
+
return this.href;
|
|
122
|
+
}
|
|
123
|
+
toJSON() {
|
|
124
|
+
return this.href;
|
|
125
|
+
}
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
|
|
127
|
+
get [Symbol.toStringTag]() {
|
|
128
|
+
return "URL";
|
|
129
|
+
}
|
|
130
|
+
[NodeUtilInspectSymbol]() {
|
|
131
|
+
return this.href;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
_protocol = new WeakMap();
|
|
135
|
+
_hostname = new WeakMap();
|
|
136
|
+
_port = new WeakMap();
|
|
137
|
+
_pathname = new WeakMap();
|
|
138
|
+
_search = new WeakMap();
|
|
139
|
+
_searchParams = new WeakMap();
|
|
140
|
+
_request = new WeakMap();
|
|
141
|
+
__name(_RequestURLProxy, "RequestURLProxy");
|
|
142
|
+
var RequestURLProxy = _RequestURLProxy;
|
|
143
|
+
function parsePath(input) {
|
|
144
|
+
const url = (input ?? "/").replaceAll("\\", "/");
|
|
145
|
+
const index = url.indexOf("?");
|
|
146
|
+
if (index === -1) {
|
|
147
|
+
return [url, ""];
|
|
148
|
+
}
|
|
149
|
+
return [url.slice(0, index), url.slice(index)];
|
|
150
|
+
}
|
|
151
|
+
__name(parsePath, "parsePath");
|
|
152
|
+
function parseHost(host) {
|
|
153
|
+
if (isNullishOrEmpty(host)) {
|
|
154
|
+
return ["localhost", -1];
|
|
155
|
+
}
|
|
156
|
+
const index = host.indexOf(":");
|
|
157
|
+
if (index === -1) {
|
|
158
|
+
return [host, -1];
|
|
159
|
+
}
|
|
160
|
+
const port = Number(host.slice(index));
|
|
161
|
+
return [host.slice(0, index), Number.isSafeInteger(port) ? port : -1];
|
|
162
|
+
}
|
|
163
|
+
__name(parseHost, "parseHost");
|
|
164
|
+
|
|
165
|
+
export { RequestURLProxy };
|
|
166
|
+
//# sourceMappingURL=RequestURLProxy.mjs.map
|
|
167
|
+
//# sourceMappingURL=RequestURLProxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/utils/_body/RequestURLProxy.ts"],"names":[],"mappings":";;;;AAAA,IAA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AAA,GAAQ,GAAI,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AAC7B,EAAA,IAAI,UAAU,CAAI,CAAA,EAAA;AACjB,IAAO,OAAA,CAAC,KAAK,EAAE,CAAA,CAAA;AAAA,GAChB;AAEA,EAAO,OAAA,CAAC,IAAI,KAAM,CAAA,CAAA,EAAG,KAAK,CAAG,EAAA,GAAA,CAAI,KAAM,CAAA,KAAK,CAAC,CAAA,CAAA;AAC9C,CAAA;AARS,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA,CAAA;AAUT,SAAS,UAAU,IAA4D,EAAA;AAC9E,EAAI,IAAA,gBAAA,CAAiB,IAAI,CAAG,EAAA;AAC3B,IAAO,OAAA,CAAC,aAAa,CAAE,CAAA,CAAA,CAAA;AAAA,GACxB;AAEA,EAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AAC9B,EAAA,IAAI,UAAU,CAAI,CAAA,EAAA;AACjB,IAAO,OAAA,CAAC,MAAM,CAAE,CAAA,CAAA,CAAA;AAAA,GACjB;AAEA,EAAA,MAAM,IAAO,GAAA,MAAA,CAAO,IAAK,CAAA,KAAA,CAAM,KAAK,CAAC,CAAA,CAAA;AACrC,EAAO,OAAA,CAAC,IAAK,CAAA,KAAA,CAAM,CAAG,EAAA,KAAK,CAAG,EAAA,MAAA,CAAO,aAAc,CAAA,IAAI,CAAI,GAAA,IAAA,GAAO,CAAE,CAAA,CAAA,CAAA;AACrE,CAAA;AAZS,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA","file":"RequestURLProxy.mjs","sourcesContent":["import { isNullishOrEmpty } from '@sapphire/utilities';\nimport type { ApiRequest } from '../../structures/api/ApiRequest';\nimport { NodeUtilInspectSymbol } from '../constants';\n\nexport class RequestURLProxy implements URL {\n\tpublic hash: string = '';\n\tpublic password: string = '';\n\tpublic username: string = '';\n\n\t#protocol: URLProtocol | null = null;\n\t#hostname: string | null = null;\n\t#port: string | null = null;\n\n\t#pathname: string | null = null;\n\t#search: string | null = null;\n\t#searchParams: URLSearchParams | null = null;\n\n\treadonly #request: ApiRequest;\n\n\tpublic constructor(request: ApiRequest) {\n\t\tthis.#request = request;\n\t}\n\n\tpublic get host(): string {\n\t\treturn this.#request.headers.host ?? '';\n\t}\n\n\tpublic set host(value: string) {\n\t\tthis.#hostname = null;\n\t\tthis.#port = null;\n\t\tthis.#request.headers.host = value;\n\t}\n\n\tpublic get hostname(): string {\n\t\tif (this.#hostname === null) {\n\t\t\tconst [hostname, port] = parseHost(this.#request.headers.host);\n\t\t\tthis.#hostname = hostname;\n\t\t\tthis.#port = port === -1 ? '' : String(port);\n\t\t}\n\n\t\treturn this.#hostname;\n\t}\n\n\tpublic set hostname(value: string) {\n\t\tthis.#hostname = value;\n\t}\n\n\tpublic get port(): string {\n\t\tif (this.#port === null) {\n\t\t\tconst [hostname, port] = parseHost(this.#request.headers.host);\n\t\t\tthis.#hostname = hostname;\n\t\t\tthis.#port = port === -1 ? String(this.#request.socket.localPort ?? '') : String(port);\n\t\t}\n\n\t\treturn this.#port;\n\t}\n\n\tpublic set port(value: string) {\n\t\tthis.#port = String(Number(value || ''));\n\t}\n\n\tpublic get pathname(): string {\n\t\tif (this.#pathname === null) {\n\t\t\tconst [pathname, search] = parsePath(this.#request.url);\n\t\t\tthis.#pathname = pathname;\n\t\t\tthis.#search ??= search;\n\t\t}\n\n\t\treturn this.#pathname;\n\t}\n\n\tpublic set pathname(value: string) {\n\t\tconst normalized = value.startsWith('/') ? value : `/${value}`;\n\t\tif (normalized === this.#pathname) return;\n\n\t\tthis.#pathname = normalized;\n\t\tthis.#request.url = normalized + this.search;\n\t}\n\n\tpublic get search(): string {\n\t\tif (this.#search === null) {\n\t\t\tconst [pathname, search] = parsePath(this.#request.url);\n\t\t\tthis.#pathname ??= pathname;\n\t\t\tthis.#search = search;\n\t\t}\n\n\t\treturn this.#search;\n\t}\n\n\tpublic set search(value: string) {\n\t\tlet normalized: string;\n\t\tif (value === '?') {\n\t\t\tnormalized = '';\n\t\t} else if (value && !value.startsWith('?')) {\n\t\t\tnormalized = `?${value}`;\n\t\t} else {\n\t\t\tnormalized = value;\n\t\t}\n\n\t\tif (normalized === this.#search) return;\n\n\t\tthis.#search = normalized;\n\t\tthis.#searchParams = null;\n\t\tthis.#request.url = this.pathname + normalized;\n\t}\n\n\tpublic get searchParams(): URLSearchParams {\n\t\tthis.#searchParams ??= new URLSearchParams(this.search);\n\t\treturn this.#searchParams;\n\t}\n\n\tpublic set searchParams(value: URLSearchParams) {\n\t\tthis.#searchParams = value;\n\t\tthis.search = value.toString();\n\t}\n\n\tpublic get protocol(): URLProtocol {\n\t\tthis.#protocol ??= (this.#request.socket as any).encrypted || this.#request.headers['x-forwarded-proto'] === 'https' ? 'https:' : 'http:';\n\t\treturn this.#protocol;\n\t}\n\n\tpublic set protocol(value: URLProtocol) {\n\t\tthis.#protocol = value;\n\t}\n\n\tpublic get origin(): string {\n\t\treturn `${this.protocol}//${this.host}`;\n\t}\n\n\tpublic set origin(_value: string) {\n\t\t// No-op\n\t}\n\n\tpublic get href(): string {\n\t\treturn `${this.protocol}//${this.host}${this.pathname}${this.search}`;\n\t}\n\n\tpublic set href(value: string) {\n\t\tconst url = new URL(value);\n\t\tthis.#protocol = url.protocol as URLProtocol;\n\t\tthis.username = url.username;\n\t\tthis.password = url.password;\n\t\tthis.#hostname = url.hostname;\n\t\tthis.#port = url.port;\n\t\tthis.#pathname = url.pathname;\n\t\tthis.#search = url.search;\n\t\tthis.hash = url.hash;\n\t}\n\n\tpublic toString(): string {\n\t\treturn this.href;\n\t}\n\n\tpublic toJSON(): string {\n\t\treturn this.href;\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic get [Symbol.toStringTag]() {\n\t\treturn 'URL';\n\t}\n\n\tpublic [NodeUtilInspectSymbol]() {\n\t\treturn this.href;\n\t}\n}\n\nexport type URLProtocol = 'https:' | 'http:';\n\nfunction parsePath(input: string | undefined): [pathname: string, search: string] {\n\tconst url = (input ?? '/').replaceAll('\\\\', '/');\n\tconst index = url.indexOf('?');\n\tif (index === -1) {\n\t\treturn [url, ''];\n\t}\n\n\treturn [url.slice(0, index), url.slice(index)];\n}\n\nfunction parseHost(host: string | undefined): [hostname: string, port: number] {\n\tif (isNullishOrEmpty(host)) {\n\t\treturn ['localhost', -1];\n\t}\n\n\tconst index = host.indexOf(':');\n\tif (index === -1) {\n\t\treturn [host, -1];\n\t}\n\n\tconst port = Number(host.slice(index));\n\treturn [host.slice(0, index), Number.isSafeInteger(port) ? port : -1];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/constants.ts"],"names":[],"mappings":";;;AAAa,IAAA,qBAAA,GAAwB,MAAO,CAAA,GAAA,CAAI,4BAA4B","file":"constants.mjs","sourcesContent":["export const NodeUtilInspectSymbol = Symbol.for('nodejs.util.inspect.custom');\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/listeners/_load.ts"],"names":["PluginRouteError","PluginServerMiddlewareError","PluginServerMiddlewareSuccess","PluginServerRequest","PluginServerRouterBranchMethodNotAllowed","PluginServerRouterBranchNotFound","PluginServerRouterFound"],"mappings":";;;;;;;;;;AASO,SAAS,aAAgB,GAAA;AAC/B,EAAA,MAAM,KAAQ,GAAA,WAAA,CAAA;AACd,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,kBAAoB,EAAA,KAAA,EAAOA,cAAkB,EAAA,KAAA,EAAO,CAAA,CAAA;AAC5F,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,6BAA+B,EAAA,KAAA,EAAOC,gBAA6B,EAAA,KAAA,EAAO,CAAA,CAAA;AAClH,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,+BAAiC,EAAA,KAAA,EAAOC,gBAA+B,EAAA,KAAA,EAAO,CAAA,CAAA;AACtH,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,qBAAuB,EAAA,KAAA,EAAOC,gBAAqB,EAAA,KAAA,EAAO,CAAA,CAAA;AAClG,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,0CAA4C,EAAA,KAAA,EAAOC,gBAA0C,EAAA,KAAA,EAAO,CAAA,CAAA;AAC5I,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,kCAAoC,EAAA,KAAA,EAAOC,gBAAkC,EAAA,KAAA,EAAO,CAAA,CAAA;AAC5H,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,yBAA2B,EAAA,KAAA,EAAOC,gBAAyB,EAAA,KAAA,EAAO,CAAA,CAAA;AAC3G,CAAA;AATgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"_load.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginListener as PluginRouteError } from './PluginRouteError';\nimport { PluginListener as PluginServerMiddlewareError } from './PluginServerMiddlewareError';\nimport { PluginListener as PluginServerMiddlewareSuccess } from './PluginServerMiddlewareSuccess';\nimport { PluginListener as PluginServerRequest } from './PluginServerRequest';\nimport { PluginListener as PluginServerRouterBranchMethodNotAllowed } from './PluginServerRouterBranchMethodNotAllowed';\nimport { PluginListener as PluginServerRouterBranchNotFound } from './PluginServerRouterBranchNotFound';\nimport { PluginListener as PluginServerRouterFound } from './PluginServerRouterFound';\n\nexport function loadListeners() {\n\tconst store = 'listeners'
|
|
1
|
+
{"version":3,"sources":["../../../src/listeners/_load.ts"],"names":["PluginRouteError","PluginServerMiddlewareError","PluginServerMiddlewareSuccess","PluginServerRequest","PluginServerRouterBranchMethodNotAllowed","PluginServerRouterBranchNotFound","PluginServerRouterFound"],"mappings":";;;;;;;;;;AASO,SAAS,aAAgB,GAAA;AAC/B,EAAA,MAAM,KAAQ,GAAA,WAAA,CAAA;AACd,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,kBAAoB,EAAA,KAAA,EAAOA,cAAkB,EAAA,KAAA,EAAO,CAAA,CAAA;AAC5F,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,6BAA+B,EAAA,KAAA,EAAOC,gBAA6B,EAAA,KAAA,EAAO,CAAA,CAAA;AAClH,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,+BAAiC,EAAA,KAAA,EAAOC,gBAA+B,EAAA,KAAA,EAAO,CAAA,CAAA;AACtH,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,qBAAuB,EAAA,KAAA,EAAOC,gBAAqB,EAAA,KAAA,EAAO,CAAA,CAAA;AAClG,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,0CAA4C,EAAA,KAAA,EAAOC,gBAA0C,EAAA,KAAA,EAAO,CAAA,CAAA;AAC5I,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,kCAAoC,EAAA,KAAA,EAAOC,gBAAkC,EAAA,KAAA,EAAO,CAAA,CAAA;AAC5H,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,yBAA2B,EAAA,KAAA,EAAOC,gBAAyB,EAAA,KAAA,EAAO,CAAA,CAAA;AAC3G,CAAA;AATgB,MAAA,CAAA,aAAA,EAAA,eAAA,CAAA","file":"_load.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginListener as PluginRouteError } from './PluginRouteError';\nimport { PluginListener as PluginServerMiddlewareError } from './PluginServerMiddlewareError';\nimport { PluginListener as PluginServerMiddlewareSuccess } from './PluginServerMiddlewareSuccess';\nimport { PluginListener as PluginServerRequest } from './PluginServerRequest';\nimport { PluginListener as PluginServerRouterBranchMethodNotAllowed } from './PluginServerRouterBranchMethodNotAllowed';\nimport { PluginListener as PluginServerRouterBranchNotFound } from './PluginServerRouterBranchNotFound';\nimport { PluginListener as PluginServerRouterFound } from './PluginServerRouterFound';\n\nexport function loadListeners() {\n\tconst store = 'listeners';\n\tvoid container.stores.loadPiece({ name: 'PluginRouteError', piece: PluginRouteError, store });\n\tvoid container.stores.loadPiece({ name: 'PluginServerMiddlewareError', piece: PluginServerMiddlewareError, store });\n\tvoid container.stores.loadPiece({ name: 'PluginServerMiddlewareSuccess', piece: PluginServerMiddlewareSuccess, store });\n\tvoid container.stores.loadPiece({ name: 'PluginServerRequest', piece: PluginServerRequest, store });\n\tvoid container.stores.loadPiece({ name: 'PluginServerRouterBranchMethodNotAllowed', piece: PluginServerRouterBranchMethodNotAllowed, store });\n\tvoid container.stores.loadPiece({ name: 'PluginServerRouterBranchNotFound', piece: PluginServerRouterBranchNotFound, store });\n\tvoid container.stores.loadPiece({ name: 'PluginServerRouterFound', piece: PluginServerRouterFound, store });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/_load.ts"],"names":["PluginAuth","PluginBody","PluginCookies","PluginHeaders"],"mappings":";;;;;;;AAMO,SAAS,eAAkB,GAAA;AACjC,EAAA,MAAM,KAAQ,GAAA,aAAA,CAAA;AACd,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,EAAOA,gBAAY,EAAA,KAAA,EAAO,CAAA,CAAA;AAC1E,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,EAAOC,kBAAY,EAAA,KAAA,EAAO,CAAA,CAAA;AAC1E,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,SAAW,EAAA,KAAA,EAAOC,kBAAe,EAAA,KAAA,EAAO,CAAA,CAAA;AAChF,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,SAAW,EAAA,KAAA,EAAOC,kBAAe,EAAA,KAAA,EAAO,CAAA,CAAA;AACjF,CAAA;AANgB,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA","file":"_load.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginMiddleware as PluginAuth } from './auth';\nimport { PluginMiddleware as PluginBody } from './body';\nimport { PluginMiddleware as PluginCookies } from './cookies';\nimport { PluginMiddleware as PluginHeaders } from './headers';\n\nexport function loadMiddlewares() {\n\tconst store = 'middlewares'
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/_load.ts"],"names":["PluginAuth","PluginBody","PluginCookies","PluginHeaders"],"mappings":";;;;;;;AAMO,SAAS,eAAkB,GAAA;AACjC,EAAA,MAAM,KAAQ,GAAA,aAAA,CAAA;AACd,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,EAAOA,gBAAY,EAAA,KAAA,EAAO,CAAA,CAAA;AAC1E,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,EAAOC,kBAAY,EAAA,KAAA,EAAO,CAAA,CAAA;AAC1E,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,SAAW,EAAA,KAAA,EAAOC,kBAAe,EAAA,KAAA,EAAO,CAAA,CAAA;AAChF,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,SAAW,EAAA,KAAA,EAAOC,kBAAe,EAAA,KAAA,EAAO,CAAA,CAAA;AACjF,CAAA;AANgB,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA","file":"_load.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginMiddleware as PluginAuth } from './auth';\nimport { PluginMiddleware as PluginBody } from './body';\nimport { PluginMiddleware as PluginCookies } from './cookies';\nimport { PluginMiddleware as PluginHeaders } from './headers';\n\nexport function loadMiddlewares() {\n\tconst store = 'middlewares';\n\tvoid container.stores.loadPiece({ name: 'auth', piece: PluginAuth, store });\n\tvoid container.stores.loadPiece({ name: 'body', piece: PluginBody, store });\n\tvoid container.stores.loadPiece({ name: 'cookies', piece: PluginCookies, store });\n\tvoid container.stores.loadPiece({ name: 'headers', piece: PluginHeaders, store });\n}\n"]}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { __name
|
|
1
|
+
import { __name } from '../chunk-S573YWRP.mjs';
|
|
2
2
|
import { HttpCodes } from '../lib/structures/http/HttpCodes.mjs';
|
|
3
3
|
import { Middleware } from '../lib/structures/Middleware.mjs';
|
|
4
4
|
|
|
5
5
|
var _PluginMiddleware = class _PluginMiddleware extends Middleware {
|
|
6
6
|
constructor(context) {
|
|
7
7
|
super(context, { position: 20 });
|
|
8
|
-
__publicField(this, "mediaParsers");
|
|
9
|
-
this.mediaParsers = this.container.server.mediaParsers;
|
|
10
8
|
}
|
|
11
|
-
|
|
9
|
+
run(request, response) {
|
|
12
10
|
if (!request.route) return;
|
|
13
11
|
const contentType = request.headers["content-type"];
|
|
14
12
|
if (typeof contentType !== "string") return;
|
|
@@ -18,18 +16,6 @@ var _PluginMiddleware = class _PluginMiddleware extends Middleware {
|
|
|
18
16
|
const maximumLength = request.route.maximumBodyLength;
|
|
19
17
|
if (length > maximumLength) {
|
|
20
18
|
response.status(HttpCodes.PayloadTooLarge).json({ error: "Exceeded maximum content length." });
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const type = this.mediaParsers.parseContentType(contentType);
|
|
24
|
-
const parser = this.mediaParsers.get(type);
|
|
25
|
-
if (!parser || !parser.accepts(request.route)) {
|
|
26
|
-
response.status(HttpCodes.UnsupportedMediaType).json({ error: `Unsupported type ${type}.` });
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
request.body = await parser.run(request);
|
|
31
|
-
} catch {
|
|
32
|
-
response.status(HttpCodes.BadRequest).json({ error: `Cannot parse ${type} data.` });
|
|
33
19
|
}
|
|
34
20
|
}
|
|
35
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/body.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/body.ts"],"names":[],"mappings":";;;;AAGO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyB,UAAW,CAAA;AAAA,EACzC,YAAY,OAAmC,EAAA;AACrD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,QAAU,EAAA,EAAA,EAAI,CAAA,CAAA;AAAA,GAChC;AAAA,EAEgB,GAAA,CAAI,SAA6B,QAA+B,EAAA;AAC/E,IAAI,IAAA,CAAC,QAAQ,KAAO,EAAA,OAAA;AAGpB,IAAM,MAAA,WAAA,GAAc,OAAQ,CAAA,OAAA,CAAQ,cAAc,CAAA,CAAA;AAClD,IAAI,IAAA,OAAO,gBAAgB,QAAU,EAAA,OAAA;AAGrC,IAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,OAAA,CAAQ,gBAAgB,CAAA,CAAA;AACrD,IAAI,IAAA,OAAO,iBAAiB,QAAU,EAAA,OAAA;AAGtC,IAAM,MAAA,MAAA,GAAS,OAAO,YAAY,CAAA,CAAA;AAClC,IAAM,MAAA,aAAA,GAAgB,QAAQ,KAAM,CAAA,iBAAA,CAAA;AACpC,IAAA,IAAI,SAAS,aAAe,EAAA;AAC3B,MAAS,QAAA,CAAA,MAAA,CAAO,UAAU,eAAe,CAAA,CAAE,KAAK,EAAE,KAAA,EAAO,oCAAoC,CAAA,CAAA;AAAA,KAC9F;AAAA,GACD;AACD,CAAA,CAAA;AAvBiD,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAA1C,IAAM,gBAAN,GAAA","file":"body.mjs","sourcesContent":["import { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport { Middleware } from '../lib/structures/Middleware';\n\nexport class PluginMiddleware extends Middleware {\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 20 });\n\t}\n\n\tpublic override run(request: Middleware.Request, response: Middleware.Response) {\n\t\tif (!request.route) return;\n\n\t\t// RFC 1341 4.\n\t\tconst contentType = request.headers['content-type'];\n\t\tif (typeof contentType !== 'string') return;\n\n\t\t// RFC 7230 3.3.2.\n\t\tconst lengthString = request.headers['content-length'];\n\t\tif (typeof lengthString !== 'string') return;\n\n\t\t// Verify if the content length is lower than accepted:\n\t\tconst length = Number(lengthString);\n\t\tconst maximumLength = request.route.maximumBodyLength;\n\t\tif (length > maximumLength) {\n\t\t\tresponse.status(HttpCodes.PayloadTooLarge).json({ error: 'Exceeded maximum content length.' });\n\t\t}\n\t}\n}\n"]}
|
package/dist/esm/register.d.mts
CHANGED
package/dist/esm/register.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __name } from './chunk-S573YWRP.mjs';
|
|
2
|
-
import { Server, loadListeners, loadMediaParsers, loadMiddlewares, loadRoutes } from './index.mjs';
|
|
3
2
|
import { SapphireClient, postInitialization, preLogin, Plugin } from '@sapphire/framework';
|
|
3
|
+
import { Server, loadListeners, loadMiddlewares, loadRoutes } from './index.mjs';
|
|
4
4
|
|
|
5
5
|
var _Api = class _Api extends Plugin {
|
|
6
6
|
/**
|
|
@@ -8,9 +8,8 @@ var _Api = class _Api extends Plugin {
|
|
|
8
8
|
*/
|
|
9
9
|
static [postInitialization](options) {
|
|
10
10
|
this.server = new Server(options.api);
|
|
11
|
-
this.stores.register(this.server.routes).register(this.server.
|
|
11
|
+
this.stores.register(this.server.routes).register(this.server.middlewares);
|
|
12
12
|
loadListeners();
|
|
13
|
-
loadMediaParsers();
|
|
14
13
|
loadMiddlewares();
|
|
15
14
|
loadRoutes();
|
|
16
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAOO,IAAM,IAAA,GAAN,MAAM,IAAA,SAAY,MAAO,CAAA;AAAA;AAAA;AAAA;AAAA,EAI/B,QAAe,kBAAkB,CAAA,CAAwB,OAA8B,EAAA;AACtF,IAAA,IAAA,CAAK,MAAS,GAAA,IAAI,MAAO,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AACpC,IAAK,IAAA,CAAA,MAAA,CACH,SAAS,IAAK,CAAA,MAAA,CAAO,MAAM,CAC3B,CAAA,QAAA,CAAS,IAAK,CAAA,MAAA,CAAO,WAAW,CAAA,CAAA;AAElC,IAAc,aAAA,EAAA,CAAA;AACd,IAAgB,eAAA,EAAA,CAAA;AAChB,IAAW,UAAA,EAAA,CAAA;AAAA,GACZ;AAAA;AAAA;AAAA;AAAA,EAKA,cAAqB,QAAQ,CAAuC,GAAA;AACnE,IAAA,IAAI,EAAE,IAAA,CAAK,MAAO,CAAA,OAAA,CAAQ,wBAAwB,IAAO,CAAA,EAAA;AACxD,MAAA,OAAA;AAAA,KACD;AAEA,IAAM,MAAA,IAAA,CAAK,OAAO,OAAQ,EAAA,CAAA;AAAA,GAC3B;AACD,CAAA,CAAA;AAzBgC,MAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA;AAAzB,IAAM,GAAN,GAAA,KAAA;AA2BP,cAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,GAAI,CAAA,kBAAkB,GAAG,wBAAwB,CAAA,CAAA;AACvG,cAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,GAAI,CAAA,QAAQ,GAAG,cAAc,CAAA","file":"register.mjs","sourcesContent":["import { Plugin, postInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { loadListeners, loadMiddlewares, loadRoutes, Server } from './index';\n\n/**\n * @since 1.0.0\n */\nexport class Api extends Plugin {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static [postInitialization](this: SapphireClient, options: ClientOptions): void {\n\t\tthis.server = new Server(options.api);\n\t\tthis.stores\n\t\t\t.register(this.server.routes) //\n\t\t\t.register(this.server.middlewares);\n\n\t\tloadListeners();\n\t\tloadMiddlewares();\n\t\tloadRoutes();\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static async [preLogin](this: SapphireClient): Promise<void> {\n\t\tif (!(this.server.options.automaticallyConnect ?? true)) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.server.connect();\n\t}\n}\n\nSapphireClient.plugins.registerPostInitializationHook(Api[postInitialization], 'API-PostInitialization');\nSapphireClient.plugins.registerPreLoginHook(Api[preLogin], 'API-PreLogin');\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/_load.ts"],"names":["PluginOAuthCallback","PluginOAuthLogout"],"mappings":";;;;;AAIO,SAAS,UAAa,GAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,QAAA,CAAA;AACd,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,UAAY,EAAA,KAAA,EAAOA,WAAqB,EAAA,KAAA,EAAO,CAAA,CAAA;AACvF,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,QAAU,EAAA,KAAA,EAAOC,aAAmB,EAAA,KAAA,EAAO,CAAA,CAAA;AACpF,CAAA;AAJgB,MAAA,CAAA,UAAA,EAAA,YAAA,CAAA","file":"_load.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginRoute as PluginOAuthCallback } from './oauth/callback.post';\nimport { PluginRoute as PluginOAuthLogout } from './oauth/logout.post';\n\nexport function loadRoutes() {\n\tconst store = 'routes'
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/_load.ts"],"names":["PluginOAuthCallback","PluginOAuthLogout"],"mappings":";;;;;AAIO,SAAS,UAAa,GAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,QAAA,CAAA;AACd,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,UAAY,EAAA,KAAA,EAAOA,WAAqB,EAAA,KAAA,EAAO,CAAA,CAAA;AACvF,EAAK,KAAA,SAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,QAAU,EAAA,KAAA,EAAOC,aAAmB,EAAA,KAAA,EAAO,CAAA,CAAA;AACpF,CAAA;AAJgB,MAAA,CAAA,UAAA,EAAA,YAAA,CAAA","file":"_load.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginRoute as PluginOAuthCallback } from './oauth/callback.post';\nimport { PluginRoute as PluginOAuthLogout } from './oauth/logout.post';\n\nexport function loadRoutes() {\n\tconst store = 'routes';\n\tvoid container.stores.loadPiece({ name: 'callback', piece: PluginOAuthCallback, store });\n\tvoid container.stores.loadPiece({ name: 'logout', piece: PluginOAuthLogout, store });\n}\n"]}
|
|
@@ -14,7 +14,7 @@ var _PluginRoute = class _PluginRoute extends Route {
|
|
|
14
14
|
this.redirectUri = server.auth?.redirect;
|
|
15
15
|
}
|
|
16
16
|
async run(request, response) {
|
|
17
|
-
const body = request.
|
|
17
|
+
const body = await request.readBodyJson();
|
|
18
18
|
if (typeof body?.code !== "string") {
|
|
19
19
|
return response.badRequest();
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/oauth/callback.post.ts"],"names":[],"mappings":";;;;;;;AAMO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,KAAM,CAAA;AAAA,EAG/B,YAAY,OAA8B,EAAA;AAChD,IAAM,KAAA,CAAA,OAAA,EAAS,EAAE,KAAO,EAAA,gBAAA,EAAkB,SAAS,CAAC,MAAM,GAAG,CAAA,CAAA;AAH9D,IAAiB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AAKhB,IAAM,MAAA,EAAE,MAAO,EAAA,GAAI,IAAK,CAAA,SAAA,CAAA;AACxB,IAAK,IAAA,CAAA,OAAA,GAAU,OAAO,IAAS,KAAA,IAAA,CAAA;AAC/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Aa,QAAU,EAAA;AAAA,MACjD,MAAQ,EAAA,MAAA;AAAA,MACR,IAAA,EAAM,UAAU,IAAW,CAAA;AAAA,MAC3B,OAAS,EAAA;AAAA,QACR,cAAgB,EAAA,mCAAA;AAAA,OACjB;AAAA,KACA,CAAA,CAAA;AAED,IAAM,MAAA,IAAA,GAAO,MAAM,MAAA,CAAO,IAAK,EAAA,CAAA;AAC/B,IAAI,IAAA,MAAA,CAAO,IAAW,OAAA,IAAA,CAAA;AAEtB,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,IAAI,CAAA,CAAA;AAChC,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAnEuC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAAhC,IAAM,WAAN,GAAA","file":"callback.post.mjs","sourcesContent":["import { OAuth2Routes, type RESTPostOAuth2AccessTokenResult, type RESTPostOAuth2AccessTokenURLEncodedData } from 'discord.js';\nimport { stringify } from 'querystring';\nimport { fetch } from 'undici';\nimport { Route } from '../../lib/structures/Route';\nimport { HttpCodes } from '../../lib/structures/http/HttpCodes';\n\nexport class PluginRoute extends Route {\n\tprivate readonly redirectUri: string | undefined;\n\n\tpublic constructor(context: Route.LoaderContext) {\n\t\tsuper(context, { route: 'oauth/callback', methods: ['POST'] });\n\n\t\tconst { server } = this.container;\n\t\tthis.enabled = server.auth !== null;\n\t\tthis.redirectUri = server.auth?.redirect;\n\t}\n\n\tpublic override async run(request: Route.Request, response: Route.Response) {\n\t\tconst body = (await request.readBodyJson()) as OAuth2BodyData;\n\t\tif (typeof body?.code !== 'string') {\n\t\t\treturn response.badRequest();\n\t\t}\n\n\t\tconst value = await this.fetchAuth(body);\n\t\tif (value === null) {\n\t\t\treturn response.status(HttpCodes.InternalServerError).json({ error: 'Failed to fetch the token.' });\n\t\t}\n\n\t\tconst now = Date.now();\n\t\tconst auth = this.container.server.auth!;\n\t\tconst data = await auth.fetchData(value.access_token);\n\t\tif (!data.user) {\n\t\t\treturn response.status(HttpCodes.InternalServerError).json({ error: 'Failed to fetch the user.' });\n\t\t}\n\n\t\tconst token = auth.encrypt({\n\t\t\tid: data.user.id,\n\t\t\texpires: now + value.expires_in * 1000,\n\t\t\trefresh: value.refresh_token,\n\t\t\ttoken: value.access_token\n\t\t});\n\n\t\tresponse.cookies.add(auth.cookie, token, { maxAge: value.expires_in });\n\t\treturn response.json(data);\n\t}\n\n\tprivate async fetchAuth(body: OAuth2BodyData) {\n\t\tconst { id, secret } = this.container.server.auth!;\n\n\t\tconst data: RESTPostOAuth2AccessTokenURLEncodedData = {\n\t\t\t/* eslint-disable @typescript-eslint/naming-convention */\n\t\t\tclient_id: id,\n\t\t\tclient_secret: secret,\n\t\t\tcode: body.code,\n\t\t\tgrant_type: 'authorization_code',\n\t\t\tredirect_uri: this.redirectUri ?? body.redirectUri\n\t\t\t/* eslint-enable @typescript-eslint/naming-convention */\n\t\t};\n\n\t\tconst result = await fetch(OAuth2Routes.tokenURL, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: stringify(data as any),\n\t\t\theaders: {\n\t\t\t\t'content-type': 'application/x-www-form-urlencoded'\n\t\t\t}\n\t\t});\n\n\t\tconst json = await result.json();\n\t\tif (result.ok) return json as RESTPostOAuth2AccessTokenResult;\n\n\t\tthis.container.logger.error(json);\n\t\treturn null;\n\t}\n}\n\n/**\n * The OAuth2 body data sent to the callback.\n * @since 1.2.0\n */\nexport interface OAuth2BodyData {\n\t/**\n\t * The code sent by the client.\n\t * @since 1.2.0\n\t */\n\tcode: string;\n\n\t/**\n\t * The client's ID.\n\t * @since 1.2.0\n\t */\n\tclientId: string;\n\n\t/**\n\t * The redirect URI.\n\t * @since 1.2.0\n\t */\n\tredirectUri: string;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-api",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.821ff70",
|
|
4
4
|
"description": "Plugin for @sapphire/framework to expose a REST API",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@types/ws": "^8.5.12",
|
|
55
55
|
"@vladfrangu/async_event_emitter": "2.4.6",
|
|
56
|
+
"cookie-es": "^1.2.2",
|
|
56
57
|
"tldts": "^6.1.41",
|
|
57
58
|
"undici": "^6.19.8"
|
|
58
59
|
},
|
|
@@ -89,7 +90,7 @@
|
|
|
89
90
|
"@favware/rollup-type-bundler": "^3.3.0",
|
|
90
91
|
"concurrently": "^8.2.2",
|
|
91
92
|
"tsup": "^8.2.4",
|
|
92
|
-
"tsx": "^4.
|
|
93
|
+
"tsx": "^4.19.0",
|
|
93
94
|
"typedoc": "^0.25.13",
|
|
94
95
|
"typedoc-json-parser": "^10.0.0",
|
|
95
96
|
"typescript": "~5.4.5"
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var pieces = require('@sapphire/pieces');
|
|
4
|
-
var zlib = require('zlib');
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var _MediaParser = class _MediaParser extends pieces.Piece {
|
|
9
|
-
constructor(context, options = {}) {
|
|
10
|
-
super(context, options);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Checks if a route accepts the media type from this parser.
|
|
14
|
-
* @since 1.3.0
|
|
15
|
-
* @param route The route to be checked.
|
|
16
|
-
*/
|
|
17
|
-
accepts(route) {
|
|
18
|
-
return route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Reads the content body as a string, this is useful for parsing/reading plain-text data.
|
|
22
|
-
* @since 1.3.0
|
|
23
|
-
* @param request The request to read the body from.
|
|
24
|
-
*/
|
|
25
|
-
async readString(request) {
|
|
26
|
-
const stream = this.contentStream(request);
|
|
27
|
-
if (stream === null) return "";
|
|
28
|
-
let body = "";
|
|
29
|
-
for await (const chunk of stream) body += chunk;
|
|
30
|
-
return body;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Reads the content body as a buffer, this is useful for parsing/reading binary data.
|
|
34
|
-
* @since 1.3.0
|
|
35
|
-
* @param request The request to read the body from.
|
|
36
|
-
*/
|
|
37
|
-
async readBuffer(request) {
|
|
38
|
-
const stream = this.contentStream(request);
|
|
39
|
-
if (stream === null) return Buffer.alloc(0);
|
|
40
|
-
const bodies = [];
|
|
41
|
-
for await (const chunk of stream) bodies.push(chunk);
|
|
42
|
-
return Buffer.concat(bodies);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Reads the content stream from a request, piping the data through a transformer stream.
|
|
46
|
-
* @since 1.3.0
|
|
47
|
-
* @param request The request to read the body from.
|
|
48
|
-
*/
|
|
49
|
-
contentStream(request) {
|
|
50
|
-
switch ((request.headers["content-encoding"] ?? "identity").toLowerCase()) {
|
|
51
|
-
case "deflate": {
|
|
52
|
-
const stream = zlib.createInflate();
|
|
53
|
-
request.pipe(stream);
|
|
54
|
-
return stream;
|
|
55
|
-
}
|
|
56
|
-
case "x-gzip":
|
|
57
|
-
case "gzip": {
|
|
58
|
-
const stream = zlib.createGunzip();
|
|
59
|
-
request.pipe(stream);
|
|
60
|
-
return stream;
|
|
61
|
-
}
|
|
62
|
-
case "br": {
|
|
63
|
-
const stream = zlib.createBrotliDecompress();
|
|
64
|
-
request.pipe(stream);
|
|
65
|
-
return stream;
|
|
66
|
-
}
|
|
67
|
-
case "identity": {
|
|
68
|
-
return request;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
__name(_MediaParser, "MediaParser");
|
|
75
|
-
var MediaParser = _MediaParser;
|
|
76
|
-
|
|
77
|
-
exports.MediaParser = MediaParser;
|
|
78
|
-
//# sourceMappingURL=MediaParser.cjs.map
|
|
79
|
-
//# sourceMappingURL=MediaParser.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":["Piece","createInflate","createGunzip","createBrotliDecompress"],"mappings":";;;;;;;AAWO,IAAe,YAAA,GAAf,MAAe,YAAA,SAA+EA,YAA+B,CAAA;AAAA,EAC5H,WAAY,CAAA,OAAA,EAAoC,OAAmB,GAAA,EAAe,EAAA;AACxF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,KAAuB,EAAA;AACrC,IAAA,OAAO,MAAM,wBAA6B,KAAA,IAAA,IAAQ,MAAM,wBAAyB,CAAA,QAAA,CAAS,KAAK,IAAgB,CAAA,CAAA;AAAA,GAChH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAI,IAAA,MAAA,KAAW,MAAa,OAAA,EAAA,CAAA;AAE5B,IAAA,IAAI,IAAO,GAAA,EAAA,CAAA;AACX,IAAiB,WAAA,MAAA,KAAA,IAAS,QAAgB,IAAA,IAAA,KAAA,CAAA;AAE1C,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAA,IAAI,MAAW,KAAA,IAAA,EAAa,OAAA,MAAA,CAAO,MAAM,CAAC,CAAA,CAAA;AAE1C,IAAA,MAAM,SAAmB,EAAC,CAAA;AAC1B,IAAA,WAAA,MAAiB,KAAS,IAAA,MAAA,EAAe,MAAA,CAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAEnD,IAAO,OAAA,MAAA,CAAO,OAAO,MAAM,CAAA,CAAA;AAAA,GAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,OAAmE,EAAA;AAC1F,IAAA,QAAA,CAAS,QAAQ,OAAQ,CAAA,kBAAkB,CAAK,IAAA,UAAA,EAAY,aAAe;AAAA,MAK1E,KAAK,SAAW,EAAA;AACf,QAAA,MAAM,SAASC,kBAAc,EAAA,CAAA;AAC7B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAMA,KAAK,QAAA,CAAA;AAAA,MACL,KAAK,MAAQ,EAAA;AACZ,QAAA,MAAM,SAASC,iBAAa,EAAA,CAAA;AAC5B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAKA,KAAK,IAAM,EAAA;AACV,QAAA,MAAM,SAASC,2BAAuB,EAAA,CAAA;AACtC,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAIA,KAAK,UAAY,EAAA;AAChB,QAAO,OAAA,OAAA,CAAA;AAAA,OACR;AAAA,KACD;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAhGoI,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAA7H,IAAe,WAAf,GAAA","file":"MediaParser.cjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { MimeType } from '../utils/MimeType';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: MediaParser.Request): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeType);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: MediaParser.Request): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: MediaParser.Request): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: MediaParser.Request): MediaParser.Request | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n}\n"]}
|