@sapphire/plugin-api 7.0.0-next.7829696 → 7.0.0-next.834b446
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/README.md +0 -1
- package/dist/cjs/index.cjs +1 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +16 -32
- package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiResponse.cjs +4 -5
- package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
- package/dist/cjs/lib/utils/MimeType.cjs +4 -0
- package/dist/cjs/lib/utils/MimeType.cjs.map +1 -0
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +1 -2
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +1 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs +1 -2
- package/dist/cjs/mediaParsers/applicationJson.cjs.map +1 -1
- package/dist/cjs/mediaParsers/textPlain.cjs +1 -2
- package/dist/cjs/mediaParsers/textPlain.cjs.map +1 -1
- package/dist/esm/index.d.mts +16 -32
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs +4 -5
- package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
- package/dist/esm/lib/utils/MimeType.mjs +3 -0
- package/dist/esm/lib/utils/MimeType.mjs.map +1 -0
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -2
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +1 -1
- package/dist/esm/mediaParsers/applicationJson.mjs +1 -2
- package/dist/esm/mediaParsers/applicationJson.mjs.map +1 -1
- package/dist/esm/mediaParsers/textPlain.mjs +1 -2
- package/dist/esm/mediaParsers/textPlain.mjs.map +1 -1
- package/package.json +8 -7
- package/dist/cjs/lib/utils/MimeTypes.cjs +0 -26
- package/dist/cjs/lib/utils/MimeTypes.cjs.map +0 -1
- package/dist/esm/lib/utils/MimeTypes.mjs +0 -26
- package/dist/esm/lib/utils/MimeTypes.mjs.map +0 -1
|
@@ -2,7 +2,6 @@ import { __name, __publicField } from '../../../chunk-S573YWRP.mjs';
|
|
|
2
2
|
import { ServerResponse, STATUS_CODES } from 'node:http';
|
|
3
3
|
import { Readable } from 'node:stream';
|
|
4
4
|
import 'node:stream/web';
|
|
5
|
-
import { MimeTypes } from '../../utils/MimeTypes.mjs';
|
|
6
5
|
import { HttpCodes } from '../http/HttpCodes.mjs';
|
|
7
6
|
|
|
8
7
|
var _ApiResponse = class _ApiResponse extends ServerResponse {
|
|
@@ -96,20 +95,20 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
|
|
|
96
95
|
* @since 1.0.0
|
|
97
96
|
*/
|
|
98
97
|
json(data) {
|
|
99
|
-
this.setContentType(
|
|
98
|
+
this.setContentType("application/json").end(JSON.stringify(data));
|
|
100
99
|
}
|
|
101
100
|
/**
|
|
102
101
|
* @since 1.0.0
|
|
103
102
|
*/
|
|
104
103
|
text(data) {
|
|
105
|
-
this.setContentType(
|
|
104
|
+
this.setContentType("text/plain").end(data);
|
|
106
105
|
}
|
|
107
106
|
/**
|
|
108
107
|
* @since 6.1.0
|
|
109
108
|
*
|
|
110
109
|
* Sets the image content type and sends the image data in the response.
|
|
111
110
|
*
|
|
112
|
-
* @param type - The MIME type of the image (e.g.,
|
|
111
|
+
* @param type - The MIME type of the image (e.g., 'image/png').
|
|
113
112
|
* @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.
|
|
114
113
|
*/
|
|
115
114
|
image(type, data) {
|
|
@@ -124,7 +123,7 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
|
|
|
124
123
|
* @since 5.1.0
|
|
125
124
|
*/
|
|
126
125
|
html(code, data) {
|
|
127
|
-
this.setContentType(
|
|
126
|
+
this.setContentType("text/html").status(code).end(data);
|
|
128
127
|
}
|
|
129
128
|
/**
|
|
130
129
|
* @since 1.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":";;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuE,cAAwB,CAAA;AAAA,EAArG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA;AAAA;AAAA,EAKA,EAAG,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,EAAE,CAAS,EAAA;AAC3D,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,EAAE,CAAA,CAAA;AACxB,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAQ,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,OAAO,CAAS,EAAA;AACrE,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,OAAO,CAAA,CAAA;AAC7B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,SAAU,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,SAAS,CAAS,EAAA;AACzE,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,SAAS,CAAA,CAAA;AAC/B,IAAO,OAAA,IAAA,CAAK,QAA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AA;AAAA;AAAA,EAKO,eAAe,WAA6B,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,gBAAgB,WAAW,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AA/I4G,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAArG,IAAM,WAAN,GAAA","file":"ApiResponse.mjs","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport type { MimeType } from '../../utils/MimeType';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType('application/json').end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType('text/plain').end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., 'image/png').\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(type: Extract<MimeType, `image/${string}`>, data: string | Buffer | Uint8Array | Readable): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType('text/html').status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeType): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvent","httpCreateServer","error"],"mappings":";;;;;;;;;;;AAaY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AACN,EAAAA,aAAA,OAAQ,CAAA,GAAA,OAAA,CAAA;AACR,EAAAA,aAAA,SAAU,CAAA,GAAA,SAAA,CAAA;AACV,EAAAA,aAAA,sBAAuB,CAAA,GAAA,sBAAA,CAAA;AACvB,EAAAA,aAAA,8BAA+B,CAAA,GAAA,8BAAA,CAAA;AAC/B,EAAAA,aAAA,aAAc,CAAA,GAAA,aAAA,CAAA;AACd,EAAAA,aAAA,YAAa,CAAA,GAAA,YAAA,CAAA;AACb,EAAAA,aAAA,mBAAoB,CAAA,GAAA,mBAAA,CAAA;AACpB,EAAAA,aAAA,iBAAkB,CAAA,GAAA,iBAAA,CAAA;AAClB,EAAAA,aAAA,mBAAoB,CAAA,GAAA,mBAAA,CAAA;AATT,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA,EAAA;AA2BL,IAAM,OAAA,GAAN,MAAM,OAAA,SAAe,iBAAgC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCpD,YAAY,EAAE,IAAA,EAAM,GAAG,OAAQ,EAAA,GAAmB,EAAI,EAAA;AAC5D,IAAM,KAAA,EAAA,CAAA;AArCP;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CA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AC7C,MAAK,IAAA,CAAA,MAAA,CAAO,MAAM,CAAC,KAAA,KAAW,QAAQ,OAAQ,EAAA,GAAI,MAAO,CAAA,KAAK,CAAE,CAAA,CAAA;AAAA,KAChE,CAAA,CAAA;AAAA,GACF;AACD,CAAA,CAAA;AApG4D,MAAA,CAAA,OAAA,EAAA,QAAA,CAAA,CAAA;AAArD,IAAM,MAAN,GAAA","file":"Server.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { Server as HttpServer, createServer as httpCreateServer, type ServerOptions as HttpOptions } from 'node:http';\nimport type { ListenOptions } from 'node:net';\nimport { MediaParserStore } from '../MediaParserStore';\nimport { MiddlewareStore } from '../MiddlewareStore';\nimport type { Route } from '../Route';\nimport { RouteStore } from '../RouteStore';\nimport { ApiRequest } from '../api/ApiRequest';\nimport { ApiResponse } from '../api/ApiResponse';\nimport type { RouterBranch } from '../router/RouterBranch';\nimport { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvent {\n\tError = 'error',\n\tRequest = 'request',\n\tRouterBranchNotFound = 'routerBranchNotFound',\n\tRouterBranchMethodNotAllowed = 'routerBranchMethodNotAllowed',\n\tRouterFound = 'routerFound',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\nexport interface ServerEvents {\n\t[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];\n\t[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];\n\t[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends AsyncEventEmitter<ServerEvents> {\n\t/**\n\t * The routes this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly routes: RouteStore;\n\n\t/**\n\t * The middlewares this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly middlewares: MiddlewareStore;\n\n\t/**\n\t * The media parsers this server holds.\n\t * @since 1.3.0\n\t */\n\tpublic readonly mediaParsers: MediaParserStore;\n\n\t/**\n\t * The authentication system.\n\t * @since 1.0.0\n\t */\n\tpublic readonly auth: Auth | null;\n\n\t/**\n\t * The http.Server instance that manages the recieved HTTP requests.\n\t * @since 1.0.0\n\t */\n\tpublic readonly server: HttpServer;\n\n\t/**\n\t * The options for this server.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: AuthLessServerOptions;\n\n\t/**\n\t * @since 1.0.0\n\t * @param options The options for this server\n\t */\n\tpublic constructor({ auth, ...options }: ServerOptions = {}) {\n\t\tsuper();\n\n\t\tcontainer.server = this;\n\n\t\tthis.options = options;\n\t\tthis.server = httpCreateServer({\n\t\t\tIncomingMessage: ApiRequest,\n\t\t\tServerResponse: ApiResponse,\n\t\t\t...(options.server ?? {})\n\t\t});\n\t\tthis.routes = new RouteStore();\n\t\tthis.middlewares = new MiddlewareStore();\n\t\tthis.mediaParsers = new MediaParserStore();\n\t\tthis.auth = Auth.create(auth);\n\t\tthis.server.on('error', this.emit.bind(this, ServerEvent.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvent.Request));\n\t}\n\n\tpublic connect() {\n\t\tconst { server } = this;\n\t\tserver.listen({\n\t\t\tport: 4000,\n\t\t\t...(this.options.listenOptions ?? {})\n\t\t});\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tfunction listening() {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t}\n\n\t\t\tfunction error(error: Error) {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t}\n\n\t\t\tfunction close() {\n\t\t\t\tcleanup();\n\t\t\t\treject(new Error('Closed unexpectedly.'));\n\t\t\t}\n\n\t\t\tfunction cleanup() {\n\t\t\t\tserver.off('listening', listening);\n\t\t\t\tserver.off('error', error);\n\t\t\t\tserver.off('close', close);\n\t\t\t}\n\n\t\t\tserver.on('listening', listening);\n\t\t\tserver.on('error', error);\n\t\t\tserver.on('close', close);\n\t\t});\n\t}\n\n\tpublic disconnect() {\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? resolve() : reject(error)));\n\t\t});\n\t}\n}\n\n/**\n * RFC 1341 4: Defines a Content-Type's type, which follows the following structure:\n *\n * - `type` = `text` | `multipart` | `message` | `image` | `audio` | `video` | `application` | x-token\n * - `x-token` = The two characters \"X-\" followed, with no intervening white space, by any token\n * @since 1.3.0\n */\nexport type ContentTypeType = 'text' | 'multipart' | 'message' | 'image' | 'audio' | 'video' | 'application' | `X-${string}`;\n\n/**\n * RFC 1341 4: Defines a Content-Type's parameter, which follows the following structure:\n *\n * - `parameter` = `attribute` \"=\" `value`\n * - `attribute` = `token`\n * - `value` = `token` / `quoted-string`\n * - `token` = `1*<any CHAR except \"SPACE\", \"CTLs\", or \"tspecials\">`\n * - `tspecials` = `(` | `)` | `<` | `>` | `@` | `,` | `;` | `:` | `\\` | `\"` | `/` | `[` | `]` | `?` | `.` | `=`\n *\n * @note `tspecials` must be in quoted-string, to use within parameter values.\n * @note The definition of `tspecials` is the same as the RFC 822 definition of `specials` with the addition of the\n * three characters `/`, `?`, and `=`.\n * @since 1.3.0\n */\nexport type ContentTypeParameter = `; ${string}=${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field without parameters, which follows the following structure:\n * `type \"/\" subtype`.\n */\nexport type MimeTypeWithoutParameters = `${ContentTypeType}/${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field, which follows the following structure:\n * `type \"/\" subtype *[\";\" parameter]`.\n * @since 1.3.0\n */\nexport type MimeType = `${MimeTypeWithoutParameters}${'' | ContentTypeParameter}`;\n\n/**\n * The API options.\n * @since 1.0.0\n */\nexport interface ServerOptions {\n\t/**\n\t * The prefix for all routes, e.g. `v1/`.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tprefix?: string;\n\n\t/**\n\t * The origin header to be set on every request at 'Access-Control-Allow-Origin'.\n\t * @since 1.0.0\n\t * @default '*'\n\t */\n\torigin?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t * @default 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t * @default null\n\t */\n\tacceptedContentMimeTypes?: MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The HTTP server options.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tserver?: HttpOptions;\n\n\t/**\n\t * The HTTP listen options.\n\t * @since 1.0.0\n\t * @default { port: 4000 }\n\t */\n\tlistenOptions?: ListenOptions;\n\n\t/**\n\t * The auth options. If neither `auth` nor `auth.secret` are defined, auth-related routes and middlewares will be\n\t * automatically disabled.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tauth?: ServerOptionsAuth;\n\n\t/**\n\t * Whether the server should connect upon being when the plugin is loaded.\n\t * @since 3.2.0\n\t * @default true\n\t */\n\tautomaticallyConnect?: boolean;\n}\n\n/**\n * The {@link ServerOptions} without {@link ServerOptions.auth}.\n * @since 1.0.0\n */\nexport type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvent","httpCreateServer","error"],"mappings":";;;;;;;;;;;AAc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ent":["import { container } from '@sapphire/pieces';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { Server as HttpServer, createServer as httpCreateServer, type ServerOptions as HttpOptions } from 'node:http';\nimport type { ListenOptions } from 'node:net';\nimport type { MimeType } from '../../utils/MimeType';\nimport { MediaParserStore } from '../MediaParserStore';\nimport { MiddlewareStore } from '../MiddlewareStore';\nimport type { Route } from '../Route';\nimport { RouteStore } from '../RouteStore';\nimport { ApiRequest } from '../api/ApiRequest';\nimport { ApiResponse } from '../api/ApiResponse';\nimport type { RouterBranch } from '../router/RouterBranch';\nimport { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvent {\n\tError = 'error',\n\tRequest = 'request',\n\tRouterBranchNotFound = 'routerBranchNotFound',\n\tRouterBranchMethodNotAllowed = 'routerBranchMethodNotAllowed',\n\tRouterFound = 'routerFound',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\nexport interface ServerEvents {\n\t[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];\n\t[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];\n\t[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends AsyncEventEmitter<ServerEvents> {\n\t/**\n\t * The routes this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly routes: RouteStore;\n\n\t/**\n\t * The middlewares this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly middlewares: MiddlewareStore;\n\n\t/**\n\t * The media parsers this server holds.\n\t * @since 1.3.0\n\t */\n\tpublic readonly mediaParsers: MediaParserStore;\n\n\t/**\n\t * The authentication system.\n\t * @since 1.0.0\n\t */\n\tpublic readonly auth: Auth | null;\n\n\t/**\n\t * The http.Server instance that manages the recieved HTTP requests.\n\t * @since 1.0.0\n\t */\n\tpublic readonly server: HttpServer;\n\n\t/**\n\t * The options for this server.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: AuthLessServerOptions;\n\n\t/**\n\t * @since 1.0.0\n\t * @param options The options for this server\n\t */\n\tpublic constructor({ auth, ...options }: ServerOptions = {}) {\n\t\tsuper();\n\n\t\tcontainer.server = this;\n\n\t\tthis.options = options;\n\t\tthis.server = httpCreateServer({\n\t\t\tIncomingMessage: ApiRequest,\n\t\t\tServerResponse: ApiResponse,\n\t\t\t...(options.server ?? {})\n\t\t});\n\t\tthis.routes = new RouteStore();\n\t\tthis.middlewares = new MiddlewareStore();\n\t\tthis.mediaParsers = new MediaParserStore();\n\t\tthis.auth = Auth.create(auth);\n\t\tthis.server.on('error', this.emit.bind(this, ServerEvent.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvent.Request));\n\t}\n\n\tpublic connect() {\n\t\tconst { server } = this;\n\t\tserver.listen({\n\t\t\tport: 4000,\n\t\t\t...(this.options.listenOptions ?? {})\n\t\t});\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tfunction listening() {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t}\n\n\t\t\tfunction error(error: Error) {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t}\n\n\t\t\tfunction close() {\n\t\t\t\tcleanup();\n\t\t\t\treject(new Error('Closed unexpectedly.'));\n\t\t\t}\n\n\t\t\tfunction cleanup() {\n\t\t\t\tserver.off('listening', listening);\n\t\t\t\tserver.off('error', error);\n\t\t\t\tserver.off('close', close);\n\t\t\t}\n\n\t\t\tserver.on('listening', listening);\n\t\t\tserver.on('error', error);\n\t\t\tserver.on('close', close);\n\t\t});\n\t}\n\n\tpublic disconnect() {\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? resolve() : reject(error)));\n\t\t});\n\t}\n}\n\n/**\n * RFC 1341 4: Defines a Content-Type's type, which follows the following structure:\n *\n * - `type` = `text` | `multipart` | `message` | `image` | `audio` | `video` | `application` | x-token\n * - `x-token` = The two characters \"X-\" followed, with no intervening white space, by any token\n * @since 1.3.0\n */\nexport type ContentTypeType = 'text' | 'multipart' | 'message' | 'image' | 'audio' | 'video' | 'application' | `X-${string}`;\n\n/**\n * RFC 1341 4: Defines a Content-Type's parameter, which follows the following structure:\n *\n * - `parameter` = `attribute` \"=\" `value`\n * - `attribute` = `token`\n * - `value` = `token` / `quoted-string`\n * - `token` = `1*<any CHAR except \"SPACE\", \"CTLs\", or \"tspecials\">`\n * - `tspecials` = `(` | `)` | `<` | `>` | `@` | `,` | `;` | `:` | `\\` | `\"` | `/` | `[` | `]` | `?` | `.` | `=`\n *\n * @note `tspecials` must be in quoted-string, to use within parameter values.\n * @note The definition of `tspecials` is the same as the RFC 822 definition of `specials` with the addition of the\n * three characters `/`, `?`, and `=`.\n * @since 1.3.0\n */\nexport type ContentTypeParameter = `; ${string}=${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field without parameters, which follows the following structure:\n * `type \"/\" subtype`.\n * @since 7.0.0\n */\nexport type GenericMimeType = `${ContentTypeType}/${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field, which follows the following structure:\n * `type \"/\" subtype *[\";\" parameter]`.\n * @since 7.0.0\n */\nexport type GenericParametrizedMimeType = `${GenericMimeType}${'' | ContentTypeParameter}`;\n\n/**\n * The API options.\n * @since 1.0.0\n */\nexport interface ServerOptions {\n\t/**\n\t * The prefix for all routes, e.g. `v1/`.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tprefix?: string;\n\n\t/**\n\t * The origin header to be set on every request at 'Access-Control-Allow-Origin'.\n\t * @since 1.0.0\n\t * @default '*'\n\t */\n\torigin?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t * @default 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t * @default null\n\t */\n\tacceptedContentMimeTypes?: MimeType[] | null;\n\n\t/**\n\t * The HTTP server options.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tserver?: HttpOptions;\n\n\t/**\n\t * The HTTP listen options.\n\t * @since 1.0.0\n\t * @default { port: 4000 }\n\t */\n\tlistenOptions?: ListenOptions;\n\n\t/**\n\t * The auth options. If neither `auth` nor `auth.secret` are defined, auth-related routes and middlewares will be\n\t * automatically disabled.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tauth?: ServerOptionsAuth;\n\n\t/**\n\t * Whether the server should connect upon being when the plugin is loaded.\n\t * @since 3.2.0\n\t * @default true\n\t */\n\tautomaticallyConnect?: boolean;\n}\n\n/**\n * The {@link ServerOptions} without {@link ServerOptions.auth}.\n * @since 1.0.0\n */\nexport type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"MimeType.mjs"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { __name } from '../chunk-S573YWRP.mjs';
|
|
2
2
|
import { URLSearchParams } from 'url';
|
|
3
3
|
import { MediaParser } from '../lib/structures/MediaParser.mjs';
|
|
4
|
-
import { MimeTypes } from '../lib/utils/MimeTypes.mjs';
|
|
5
4
|
|
|
6
5
|
var _PluginMediaParser = class _PluginMediaParser extends MediaParser {
|
|
7
6
|
constructor(context) {
|
|
8
|
-
super(context, { name:
|
|
7
|
+
super(context, { name: "application/x-www-form-urlencoded" });
|
|
9
8
|
}
|
|
10
9
|
async run(request) {
|
|
11
10
|
const body = await this.readString(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mediaParsers/applicationFormUrlEncoded.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/mediaParsers/applicationFormUrlEncoded.ts"],"names":[],"mappings":";;;;AAIO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,mCAAA,EAAwD,CAAA,CAAA;AAAA,GAChF;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,MAAA,CAAO,WAAY,CAAA,IAAI,eAAgB,CAAA,IAAI,CAAE,CAAA,OAAA,EAAS,CAAA,CAAA;AAAA,GACzF;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationFormUrlEncoded.mjs","sourcesContent":["import { URLSearchParams } from 'url';\nimport { MediaParser } from '../lib/structures/MediaParser';\nimport type { MimeType } from '../lib/utils/MimeType';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: 'application/x-www-form-urlencoded' satisfies MimeType });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : Object.fromEntries(new URLSearchParams(body).entries());\n\t}\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __name } from '../chunk-S573YWRP.mjs';
|
|
2
2
|
import { MediaParser } from '../lib/structures/MediaParser.mjs';
|
|
3
|
-
import { MimeTypes } from '../lib/utils/MimeTypes.mjs';
|
|
4
3
|
|
|
5
4
|
var _PluginMediaParser = class _PluginMediaParser extends MediaParser {
|
|
6
5
|
constructor(context) {
|
|
7
|
-
super(context, { name:
|
|
6
|
+
super(context, { name: "application/json" });
|
|
8
7
|
}
|
|
9
8
|
async run(request) {
|
|
10
9
|
const body = await this.readString(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mediaParsers/applicationJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/mediaParsers/applicationJson.ts"],"names":[],"mappings":";;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,kBAAA,EAAuC,CAAA,CAAA;AAAA,GAC/D;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAA,OAAO,KAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAAA,GAClD;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationJson.mjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport type { MimeType } from '../lib/utils/MimeType';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: 'application/json' satisfies MimeType });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : JSON.parse(body);\n\t}\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __name } from '../chunk-S573YWRP.mjs';
|
|
2
2
|
import { MediaParser } from '../lib/structures/MediaParser.mjs';
|
|
3
|
-
import { MimeTypes } from '../lib/utils/MimeTypes.mjs';
|
|
4
3
|
|
|
5
4
|
var _PluginMediaParser = class _PluginMediaParser extends MediaParser {
|
|
6
5
|
constructor(context) {
|
|
7
|
-
super(context, { name:
|
|
6
|
+
super(context, { name: "text/plain" });
|
|
8
7
|
}
|
|
9
8
|
async run(request) {
|
|
10
9
|
const body = await this.readString(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mediaParsers/textPlain.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/mediaParsers/textPlain.ts"],"names":[],"mappings":";;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,YAAA,EAAiC,CAAA,CAAA;AAAA,GACzD;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAA;AAAA,GACnC;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"textPlain.mjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport type { MimeType } from '../lib/utils/MimeType';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: 'text/plain' satisfies MimeType });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : body;\n\t}\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.834b446",
|
|
4
4
|
"description": "Plugin for @sapphire/framework to expose a REST API",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
|
|
44
44
|
"build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
|
|
45
45
|
"build:rename-cjs-register": "tsx ../../scripts/rename-cjs-register.mts",
|
|
46
|
+
"sync-mime-types": "tsx scripts/sync-mime-types.mts",
|
|
46
47
|
"typecheck": "tsc -b src",
|
|
47
48
|
"docs": "typedoc-json-parser",
|
|
48
49
|
"prepack": "yarn build",
|
|
@@ -50,10 +51,10 @@
|
|
|
50
51
|
"check-update": "cliff-jumper --dry-run"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@types/ws": "^8.5.
|
|
54
|
-
"@vladfrangu/async_event_emitter": "2.4.
|
|
55
|
-
"tldts": "^6.1.
|
|
56
|
-
"undici": "^6.19.
|
|
54
|
+
"@types/ws": "^8.5.12",
|
|
55
|
+
"@vladfrangu/async_event_emitter": "2.4.5",
|
|
56
|
+
"tldts": "^6.1.39",
|
|
57
|
+
"undici": "^6.19.7"
|
|
57
58
|
},
|
|
58
59
|
"repository": {
|
|
59
60
|
"type": "git",
|
|
@@ -87,8 +88,8 @@
|
|
|
87
88
|
"@favware/cliff-jumper": "^4.0.3",
|
|
88
89
|
"@favware/rollup-type-bundler": "^3.3.0",
|
|
89
90
|
"concurrently": "^8.2.2",
|
|
90
|
-
"tsup": "^8.2.
|
|
91
|
-
"tsx": "^4.
|
|
91
|
+
"tsup": "^8.2.4",
|
|
92
|
+
"tsx": "^4.17.0",
|
|
92
93
|
"typedoc": "^0.25.13",
|
|
93
94
|
"typedoc-json-parser": "^10.0.0",
|
|
94
95
|
"typescript": "~5.4.5"
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/lib/utils/MimeTypes.ts
|
|
4
|
-
var MimeTypes = /* @__PURE__ */ ((MimeTypes2) => {
|
|
5
|
-
MimeTypes2["ApplicationFormUrlEncoded"] = "application/x-www-form-urlencoded";
|
|
6
|
-
MimeTypes2["ApplicationJson"] = "application/json";
|
|
7
|
-
MimeTypes2["AudioOgg"] = "audio/ogg";
|
|
8
|
-
MimeTypes2["AudioOpus"] = "audio/opus";
|
|
9
|
-
MimeTypes2["AudioWebm"] = "audio/webm";
|
|
10
|
-
MimeTypes2["ImageGif"] = "image/gif";
|
|
11
|
-
MimeTypes2["ImageJpg"] = "image/jpeg";
|
|
12
|
-
MimeTypes2["ImagePng"] = "image/png";
|
|
13
|
-
MimeTypes2["ImageWebp"] = "image/webp";
|
|
14
|
-
MimeTypes2["ImageXIcon"] = "image/x-icon";
|
|
15
|
-
MimeTypes2["TextPlain"] = "text/plain";
|
|
16
|
-
MimeTypes2["TextHtml"] = "text/html";
|
|
17
|
-
MimeTypes2["VideoMp4"] = "video/mp4";
|
|
18
|
-
MimeTypes2["VideoMpeg"] = "video/mpeg";
|
|
19
|
-
MimeTypes2["VideoOgg"] = "video/ogg";
|
|
20
|
-
MimeTypes2["VideoWebm"] = "video/webm";
|
|
21
|
-
return MimeTypes2;
|
|
22
|
-
})(MimeTypes || {});
|
|
23
|
-
|
|
24
|
-
exports.MimeTypes = MimeTypes;
|
|
25
|
-
//# sourceMappingURL=MimeTypes.cjs.map
|
|
26
|
-
//# sourceMappingURL=MimeTypes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/utils/MimeTypes.ts"],"names":["MimeTypes"],"mappings":";;;AAAY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACN,EAAAA,WAAA,2BAA4B,CAAA,GAAA,mCAAA,CAAA;AAC5B,EAAAA,WAAA,iBAAkB,CAAA,GAAA,kBAAA,CAAA;AAClB,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,YAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,YAAa,CAAA,GAAA,cAAA,CAAA;AACb,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AAhBD,EAAAA,OAAAA,UAAAA,CAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"MimeTypes.cjs","sourcesContent":["export enum MimeTypes {\n\tApplicationFormUrlEncoded = 'application/x-www-form-urlencoded',\n\tApplicationJson = 'application/json',\n\tAudioOgg = 'audio/ogg',\n\tAudioOpus = 'audio/opus',\n\tAudioWebm = 'audio/webm',\n\tImageGif = 'image/gif',\n\tImageJpg = 'image/jpeg',\n\tImagePng = 'image/png',\n\tImageWebp = 'image/webp',\n\tImageXIcon = 'image/x-icon',\n\tTextPlain = 'text/plain',\n\tTextHtml = 'text/html',\n\tVideoMp4 = 'video/mp4',\n\tVideoMpeg = 'video/mpeg',\n\tVideoOgg = 'video/ogg',\n\tVideoWebm = 'video/webm'\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import '../../chunk-S573YWRP.mjs';
|
|
2
|
-
|
|
3
|
-
// src/lib/utils/MimeTypes.ts
|
|
4
|
-
var MimeTypes = /* @__PURE__ */ ((MimeTypes2) => {
|
|
5
|
-
MimeTypes2["ApplicationFormUrlEncoded"] = "application/x-www-form-urlencoded";
|
|
6
|
-
MimeTypes2["ApplicationJson"] = "application/json";
|
|
7
|
-
MimeTypes2["AudioOgg"] = "audio/ogg";
|
|
8
|
-
MimeTypes2["AudioOpus"] = "audio/opus";
|
|
9
|
-
MimeTypes2["AudioWebm"] = "audio/webm";
|
|
10
|
-
MimeTypes2["ImageGif"] = "image/gif";
|
|
11
|
-
MimeTypes2["ImageJpg"] = "image/jpeg";
|
|
12
|
-
MimeTypes2["ImagePng"] = "image/png";
|
|
13
|
-
MimeTypes2["ImageWebp"] = "image/webp";
|
|
14
|
-
MimeTypes2["ImageXIcon"] = "image/x-icon";
|
|
15
|
-
MimeTypes2["TextPlain"] = "text/plain";
|
|
16
|
-
MimeTypes2["TextHtml"] = "text/html";
|
|
17
|
-
MimeTypes2["VideoMp4"] = "video/mp4";
|
|
18
|
-
MimeTypes2["VideoMpeg"] = "video/mpeg";
|
|
19
|
-
MimeTypes2["VideoOgg"] = "video/ogg";
|
|
20
|
-
MimeTypes2["VideoWebm"] = "video/webm";
|
|
21
|
-
return MimeTypes2;
|
|
22
|
-
})(MimeTypes || {});
|
|
23
|
-
|
|
24
|
-
export { MimeTypes };
|
|
25
|
-
//# sourceMappingURL=MimeTypes.mjs.map
|
|
26
|
-
//# sourceMappingURL=MimeTypes.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/utils/MimeTypes.ts"],"names":["MimeTypes"],"mappings":";;;AAAY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACN,EAAAA,WAAA,2BAA4B,CAAA,GAAA,mCAAA,CAAA;AAC5B,EAAAA,WAAA,iBAAkB,CAAA,GAAA,kBAAA,CAAA;AAClB,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,YAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,YAAa,CAAA,GAAA,cAAA,CAAA;AACb,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AAhBD,EAAAA,OAAAA,UAAAA,CAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"MimeTypes.mjs","sourcesContent":["export enum MimeTypes {\n\tApplicationFormUrlEncoded = 'application/x-www-form-urlencoded',\n\tApplicationJson = 'application/json',\n\tAudioOgg = 'audio/ogg',\n\tAudioOpus = 'audio/opus',\n\tAudioWebm = 'audio/webm',\n\tImageGif = 'image/gif',\n\tImageJpg = 'image/jpeg',\n\tImagePng = 'image/png',\n\tImageWebp = 'image/webp',\n\tImageXIcon = 'image/x-icon',\n\tTextPlain = 'text/plain',\n\tTextHtml = 'text/html',\n\tVideoMp4 = 'video/mp4',\n\tVideoMpeg = 'video/mpeg',\n\tVideoOgg = 'video/ogg',\n\tVideoWebm = 'video/webm'\n}\n"]}
|