@aklinker1/zeta 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/adapters/zod-schema-adapter.d.mts +17 -0
  2. package/dist/adapters/zod-schema-adapter.mjs +726 -0
  3. package/dist/app-Bc9Kn3KA.mjs +1225 -0
  4. package/dist/client.d.mts +71 -0
  5. package/dist/client.mjs +73 -0
  6. package/dist/index.d.mts +317 -0
  7. package/dist/index.mjs +3 -0
  8. package/dist/schema-DKqL09oQ.d.mts +168 -0
  9. package/dist/schema.d.mts +2 -0
  10. package/dist/schema.mjs +151 -0
  11. package/dist/serialization-0dai2wUm.mjs +56 -0
  12. package/dist/testing.d.mts +26 -0
  13. package/dist/testing.mjs +52 -0
  14. package/dist/transports/bun-transport.d.mts +47 -0
  15. package/dist/transports/bun-transport.mjs +58 -0
  16. package/dist/transports/deno-transport.d.mts +48 -0
  17. package/dist/transports/deno-transport.mjs +57 -0
  18. package/dist/transports/fetch-transport.d.mts +6 -0
  19. package/dist/transports/fetch-transport.mjs +25 -0
  20. package/dist/types-BvjPE9EM.d.mts +712 -0
  21. package/dist/types.d.mts +2 -0
  22. package/dist/types.mjs +1 -0
  23. package/package.json +51 -19
  24. package/src/adapters/zod-schema-adapter.ts +0 -29
  25. package/src/app.ts +0 -479
  26. package/src/client.ts +0 -184
  27. package/src/errors.ts +0 -529
  28. package/src/index.ts +0 -5
  29. package/src/internal/compile-fetch-function.ts +0 -166
  30. package/src/internal/compile-route-handler.ts +0 -194
  31. package/src/internal/context.ts +0 -65
  32. package/src/internal/serialization.ts +0 -91
  33. package/src/internal/utils.ts +0 -191
  34. package/src/meta.ts +0 -14
  35. package/src/open-api.ts +0 -273
  36. package/src/schema.ts +0 -271
  37. package/src/status.ts +0 -143
  38. package/src/testing.ts +0 -62
  39. package/src/transports/bun-transport.ts +0 -17
  40. package/src/transports/deno-transport.ts +0 -13
  41. package/src/types.ts +0 -1102
package/src/meta.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
- import type { SchemaAdapter } from "./types";
3
- import { isZetaSchema, type ZetaSchema } from "./schema";
4
-
5
- /** Get metadata for either a ZetaSchema or a StandardSchemaV1. */
6
- export function getMeta(
7
- adapter: SchemaAdapter | undefined,
8
- schema: StandardSchemaV1 | ZetaSchema,
9
- ): Record<string, any> {
10
- if (isZetaSchema(schema)) return schema["~zeta"].meta;
11
-
12
- if (!adapter) return {};
13
- return adapter.getMeta(schema) ?? {};
14
- }
package/src/open-api.ts DELETED
@@ -1,273 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
- import type { OpenAPI } from "openapi-types";
3
- import { titleCase } from "scule";
4
- import type { CreateAppOptions } from "./app";
5
- import { getMeta } from "./meta";
6
- import {
7
- ErrorResponseJsonSchema,
8
- isZetaSchema,
9
- type ZetaSchema,
10
- } from "./schema";
11
- import { getHttpStatusName } from "./status";
12
- import type { App, BasePath, SchemaAdapter } from "./types";
13
-
14
- export function buildOpenApiDocs(
15
- options: CreateAppOptions<any> | undefined,
16
- app: App,
17
- ): { type: "success"; spec: any } | { type: "error"; error: unknown } {
18
- try {
19
- if (!options?.schemaAdapter)
20
- return { type: "error", error: "OpenAPI docs require a schema adapter" };
21
- const adapter = options.schemaAdapter;
22
-
23
- const userDoc = options.openApi ?? {};
24
- const docs: OpenAPI.Document = {
25
- openapi: "3.1.0",
26
- ...userDoc,
27
- info: {
28
- title: "Zeta Application",
29
- version: "1.0.0",
30
- ...userDoc.info,
31
- },
32
- paths: {},
33
- components: {
34
- ...userDoc.components,
35
- schemas: {
36
- ...userDoc.components?.schemas,
37
- ErrorResponse: ErrorResponseJsonSchema,
38
- },
39
- },
40
- };
41
- for (const [method, methodEntry] of Object.entries(app["~zeta"].routes)) {
42
- for (const [path, routerData] of Object.entries(methodEntry)) {
43
- const openApiPath =
44
- path
45
- // Replace parameters with OpenAPI format
46
- .replace(/\/:([^/]+)/g, "/{$1}")
47
- // Remove trailing slash
48
- .replace(/\/$/, "") ||
49
- // Convert "" -> "/"
50
- "/";
51
- const { headers, params, query, body, responses, ...openApiOperation } =
52
- routerData.def ?? {};
53
- docs.paths ??= {};
54
- docs.paths[openApiPath] ??= {};
55
-
56
- (docs.paths[openApiPath] as any)[method.toLowerCase()] = {
57
- ...openApiOperation,
58
- summary:
59
- openApiOperation.summary ??
60
- (openApiOperation.operationId
61
- ? titleCase(openApiOperation.operationId)
62
- : undefined),
63
- requestBody: body
64
- ? {
65
- content: {
66
- [getMeta(adapter, body)?.contentType ?? "application/json"]: {
67
- schema: isZetaSchema(body)
68
- ? body.toJsonSchema?.()
69
- : adapter.toJsonSchema(body),
70
- },
71
- },
72
- }
73
- : undefined,
74
- parameters: [
75
- ...mapParameters(adapter, params, "path"),
76
- ...mapParameters(adapter, query, "query"),
77
- ...mapParameters(adapter, headers, "header"),
78
- ] as OpenAPI.Parameters,
79
- responses: {
80
- ...(!responses
81
- ? {}
82
- : "~standard" in responses
83
- ? {
84
- 200: buildResponse(200, responses, adapter),
85
- }
86
- : Object.fromEntries(
87
- Object.entries(responses).map(([status, response]) => [
88
- status,
89
- buildResponse(Number(status), response, adapter),
90
- ]),
91
- )),
92
- ...((params || query || headers || body) && {
93
- 400: {
94
- description: "Bad Request",
95
- content: {
96
- "application/json": {
97
- schema: {
98
- $ref: "#/components/schemas/ErrorResponse",
99
- },
100
- },
101
- },
102
- },
103
- }),
104
- },
105
- } as OpenAPI.Operation;
106
- }
107
- }
108
-
109
- return { type: "success", spec: optimizeSpec(docs) };
110
- } catch (error) {
111
- return { type: "error", error };
112
- }
113
- }
114
-
115
- export function buildScalarHtml(
116
- jsonRoute: BasePath,
117
- options: CreateAppOptions<any> | undefined,
118
- ): string {
119
- const scalarConfig = {
120
- // Aaron's preferences
121
- defaultOpenAllTags: true,
122
-
123
- // User options
124
- ...options?.scalar,
125
-
126
- // Required config
127
- url: jsonRoute,
128
- };
129
- return `<!doctype html>
130
- <html>
131
- <head>
132
- <title>API Reference</title>
133
- <meta charset="utf-8" />
134
- <meta name="viewport" content="width=device-width, initial-scale=1" />
135
- </head>
136
- <body>
137
- <div id="app"></div>
138
- <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
139
- <script>
140
- const config = ${JSON.stringify(scalarConfig)};
141
- if (${process.env.NODE_ENV !== "production"}) {
142
- config.servers ??= [];
143
- config.servers.unshift({ url: location.origin })
144
- }
145
- Scalar.createApiReference('#app', config)
146
- </script>
147
- </body>
148
- </html>
149
- `;
150
- }
151
-
152
- function mapParameters(
153
- adapter: SchemaAdapter,
154
- schema: StandardSchemaV1 | undefined,
155
- in_: "query" | "path" | "header",
156
- ): OpenAPI.Parameters {
157
- if (!schema) return [];
158
-
159
- const openApiSchema = adapter.toJsonSchema(schema);
160
- if (openApiSchema.type !== "object")
161
- throw Error(
162
- `Param in ${in_} must have { "type": "object", ... }, but got ${JSON.stringify(openApiSchema, null, 2)}`,
163
- );
164
-
165
- return Object.entries(openApiSchema.properties).map(
166
- ([name, def]: [string, any]) => ({
167
- name,
168
- in: in_,
169
- description: def.description,
170
- schema: def,
171
- required: !!openApiSchema.required?.includes(name),
172
- }),
173
- );
174
- }
175
-
176
- function buildResponse(
177
- status: number,
178
- schema: StandardSchemaV1 | ZetaSchema,
179
- adapter: SchemaAdapter,
180
- ): NonNullable<OpenAPI.Operation["responses"]>[string] {
181
- const meta = getMeta(adapter, schema);
182
-
183
- if (isZetaSchema(schema)) {
184
- const description =
185
- meta?.responseDescription ?? getHttpStatusName(status) ?? "";
186
-
187
- if (schema["~zeta"].type === "NoResponse") {
188
- return {
189
- description,
190
- };
191
- }
192
-
193
- if (schema["~zeta"].type === "ErrorResponse") {
194
- return {
195
- description,
196
- content: {
197
- "application/json": {
198
- schema: {
199
- $ref: "#/components/schemas/ErrorResponse",
200
- },
201
- },
202
- },
203
- };
204
- }
205
- }
206
-
207
- return {
208
- description: meta?.responseDescription ?? getHttpStatusName(status),
209
- content: {
210
- [meta?.contentType ?? "application/json"]: {
211
- schema: adapter.toJsonSchema(schema),
212
- },
213
- },
214
- };
215
- }
216
-
217
- function optimizeSpec(spec: OpenAPI.Document): OpenAPI.Document {
218
- const optimized = structuredClone(spec);
219
-
220
- // Optimizations
221
- addModelRefs(optimized);
222
- sortComponentSchemas(optimized);
223
-
224
- return optimized;
225
- }
226
-
227
- /**
228
- * Look for `ref` properties from schema metadata and move those models to
229
- * `components.schemas`.
230
- */
231
- function addModelRefs(spec: any): void {
232
- const recurse = (obj: any): void => {
233
- if (obj == null) return;
234
- if (typeof obj !== "object") return;
235
-
236
- // Recursively update array items
237
- if (Array.isArray(obj)) {
238
- for (let i = 0, il = obj.length; i < il; i++) recurse(obj[i]);
239
- return;
240
- }
241
-
242
- // Recursively update object properties
243
- const values = Object.values(obj);
244
- for (let i = 0, il = values.length; i < il; i++) recurse(values[i]);
245
-
246
- // Move model if it includes a ref
247
- if (typeof obj.ref === "string") {
248
- const ref = obj.ref;
249
- spec.components ??= {};
250
- spec.components.schemas ??= {};
251
- spec.components.schemas[ref] = {
252
- ...structuredClone(obj),
253
- // Remove any zeta-only properties OpenAPI doesn't support
254
- ref: undefined,
255
- };
256
- for (const key of Object.keys(obj)) delete obj[key];
257
- obj.$ref = `#/components/schemas/${ref}`;
258
- }
259
- };
260
-
261
- // Process the "paths" object
262
- recurse(spec.paths);
263
- }
264
-
265
- function sortComponentSchemas(spec: any): void {
266
- if (!spec?.components?.schemas) return;
267
-
268
- spec.components.schemas = Object.fromEntries(
269
- Object.entries(spec.components.schemas).sort((a, b) =>
270
- a[0].toLowerCase().localeCompare(b[0].toLowerCase()),
271
- ),
272
- );
273
- }
package/src/schema.ts DELETED
@@ -1,271 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
- import type { HttpStatus } from "./status";
3
-
4
- export type ZetaSchema<Input = unknown, Output = Input> = StandardSchemaV1<
5
- Input,
6
- Output
7
- > & {
8
- "~zeta": {
9
- type: string;
10
- meta: Record<string, any>;
11
- };
12
- toJsonSchema?(): any;
13
- meta(meta?: Record<string, any>): ZetaSchema<Input, Output>;
14
- };
15
-
16
- function createZetaSchema<Input = unknown, Output = Input>(
17
- name: string,
18
- validate: (value: unknown) => StandardSchemaV1.Result<Output>,
19
- toJsonSchema?: () => any,
20
- meta: Record<string, string> = {},
21
- ): ZetaSchema<Input, Output> {
22
- const parentMeta = meta;
23
- return {
24
- "~zeta": {
25
- type: name,
26
- meta,
27
- },
28
- "~standard": {
29
- vendor: "@aklinker/zeta",
30
- version: 1,
31
- validate,
32
- },
33
- meta(meta) {
34
- return createZetaSchema(name, validate, undefined, {
35
- ...parentMeta,
36
- ...meta,
37
- });
38
- },
39
- toJsonSchema,
40
- };
41
- }
42
-
43
- /**
44
- * A schema for an error response. Use when defining additional status codes
45
- * that an operation might return with:
46
- *
47
- * ```ts
48
- * import { ErrorResponse } from '@aklinker/zeta';
49
- *
50
- * app.get(
51
- * "/api/item/:itemId",
52
- * {
53
- * responses: {
54
- * 200: Item.optional(),
55
- * 404: ErrorResponse,
56
- * }
57
- * },
58
- * () => {
59
- * // ...
60
- * }
61
- * );
62
- * ```
63
- */
64
- export const ErrorResponse: ZetaSchema<unknown, ErrorResponse> =
65
- createZetaSchema<unknown, ErrorResponse>(
66
- "ErrorResponse",
67
- (value: unknown): StandardSchemaV1.Result<ErrorResponse> => {
68
- if (value == null)
69
- return {
70
- issues: [{ message: `Expected an object, received ${value}` }],
71
- };
72
-
73
- if (typeof value !== "object")
74
- return {
75
- issues: [{ message: `Expected an object, received ${typeof value}` }],
76
- };
77
-
78
- const issues: StandardSchemaV1.Issue[] = [];
79
- if (typeof (value as any).name !== "string") {
80
- issues.push({
81
- message: `Expected a string, received ${typeof (value as any).name}`,
82
- path: ["name"],
83
- });
84
- }
85
- if (typeof (value as any).message !== "string") {
86
- issues.push({
87
- message: `Expected a string, received ${typeof (value as any).message}`,
88
- path: ["message"],
89
- });
90
- }
91
- if (typeof (value as any).status !== "number") {
92
- issues.push({
93
- message: `Expected a number, received ${typeof (value as any).status}`,
94
- path: ["status"],
95
- });
96
- }
97
- if (issues.length > 0) return { issues };
98
-
99
- return { value: value as ErrorResponse };
100
- },
101
- );
102
-
103
- export function isZetaSchema(schema: any): schema is ZetaSchema {
104
- return schema?.["~standard"]?.vendor === "@aklinker/zeta";
105
- }
106
-
107
- /**
108
- * The actual type an error response conforms to.
109
- */
110
- export type ErrorResponse = {
111
- [additionalInfo: string]: any;
112
- name: string;
113
- message: string;
114
- status: HttpStatus;
115
- stack?: string[];
116
- cause?: ErrorResponse;
117
- };
118
-
119
- export const ErrorResponseJsonSchema = {
120
- type: "object" as const,
121
- properties: {
122
- status: {
123
- type: "number" as const,
124
- description: "HTTP status code",
125
- example: 400,
126
- },
127
- name: {
128
- type: "string" as const,
129
- description: "The error's name",
130
- example: "Bad Request",
131
- },
132
- message: {
133
- type: "string" as const,
134
- description: "User-facing error message",
135
- example: "Property 'name' is required",
136
- },
137
- },
138
- required: ["status", "name", "message"],
139
- };
140
-
141
- /**
142
- * A schema for when you want to not return a response. Use when defining
143
- * additional status codes that an operation might return with:
144
- *
145
- * ```ts
146
- * import { NoResponse } from '@aklinker/zeta';
147
- *
148
- * app.get(
149
- * "/api/item/:itemId",
150
- * {
151
- * responses: {
152
- * [HttpStatus.Accepted]: NoResponse,
153
- * }
154
- * },
155
- * () => {
156
- * // ...
157
- * }
158
- * );
159
- * ```
160
- */
161
- export const NoResponse: ZetaSchema<undefined | null | void, void> =
162
- createZetaSchema<undefined | null | void, void>(
163
- "NoResponse",
164
- (value: unknown): StandardSchemaV1.Result<void> => {
165
- return value != null
166
- ? {
167
- issues: [
168
- { message: `Expected undefined or null, got ${typeof value}` },
169
- ],
170
- }
171
- : { value: undefined };
172
- },
173
- );
174
-
175
- export const FormDataBody: ZetaSchema<FormData> = createZetaSchema<FormData>(
176
- "FormDataBody",
177
- (value: unknown): StandardSchemaV1.Result<FormData> => {
178
- return value instanceof FormData
179
- ? { value }
180
- : {
181
- issues: [{ message: `Expected FormData, got ${typeof value}` }],
182
- };
183
- },
184
- () => ({
185
- type: "object",
186
- additionalProperties: true,
187
- }),
188
- {
189
- contentType: "multipart/form-data",
190
- },
191
- );
192
-
193
- export const UploadFileBody: ZetaSchema<File> = createZetaSchema<File>(
194
- "UploadFileBody",
195
- (value: unknown): StandardSchemaV1.Result<File> => {
196
- if (!(value instanceof FormData)) {
197
- return {
198
- issues: [{ message: `Expected FormData, got ${typeof value}` }],
199
- };
200
- }
201
-
202
- const file = value.get("file");
203
- if (!(file instanceof File)) {
204
- return {
205
- issues: [{ message: `Expected File, got ${typeof file}` }],
206
- };
207
- }
208
-
209
- return { value: file };
210
- },
211
- () => ({
212
- type: "object",
213
- properties: {
214
- file: {
215
- type: "string",
216
- format: "binary",
217
- },
218
- },
219
- }),
220
- {
221
- contentType: "multipart/form-data",
222
- },
223
- );
224
-
225
- export const UploadFilesBody: ZetaSchema<FileList, File[]> = createZetaSchema<
226
- FileList,
227
- File[]
228
- >(
229
- "UploadFilesBody",
230
- (value): StandardSchemaV1.Result<File[]> => {
231
- if (!(value instanceof FormData)) {
232
- return {
233
- issues: [{ message: `Expected FormData, got ${typeof value}` }],
234
- };
235
- }
236
-
237
- const files = value.getAll("files");
238
- if (!Array.isArray(files)) {
239
- return {
240
- issues: [{ message: `Expected array of Files, got ${typeof files}` }],
241
- };
242
- }
243
-
244
- const issues: string[] = [];
245
- for (const file of files) {
246
- if (!(file instanceof File)) {
247
- issues.push(`Expected File, got ${typeof file}`);
248
- }
249
- }
250
- if (issues.length > 0) {
251
- return { issues: issues.map((message) => ({ message })) };
252
- }
253
-
254
- return { value: files as File[] };
255
- },
256
- () => ({
257
- type: "object",
258
- properties: {
259
- files: {
260
- type: "array",
261
- items: {
262
- type: "string",
263
- format: "binary",
264
- },
265
- },
266
- },
267
- }),
268
- {
269
- contentType: "multipart/form-data",
270
- },
271
- );
package/src/status.ts DELETED
@@ -1,143 +0,0 @@
1
- /**
2
- * Enum containing all HTTP status codes.
3
- */
4
- export enum HttpStatus {
5
- Continue = 100,
6
- SwitchingProtocols = 101,
7
- ProcessingDeprecated = 102,
8
- EarlyHints = 103,
9
- Ok = 200,
10
- Created = 201,
11
- Accepted = 202,
12
- NonAuthoritativeInformation = 203,
13
- NoContent = 204,
14
- ResetContent = 205,
15
- PartialContent = 206,
16
- MultiStatus = 207,
17
- AlreadyReported = 208,
18
- ImUsed = 226,
19
- MultipleChoices = 300,
20
- MovedPermanently = 301,
21
- Found = 302,
22
- SeeOther = 303,
23
- NotModified = 304,
24
- UseProxyDeprecated = 305,
25
- Unused = 306,
26
- TemporaryRedirect = 307,
27
- PermanentRedirect = 308,
28
- BadRequest = 400,
29
- Unauthorized = 401,
30
- PaymentRequired = 402,
31
- Forbidden = 403,
32
- NotFound = 404,
33
- MethodNotAllowed = 405,
34
- NotAcceptable = 406,
35
- ProxyAuthenticationRequired = 407,
36
- RequestTimeout = 408,
37
- Conflict = 409,
38
- Gone = 410,
39
- LengthRequired = 411,
40
- PreconditionFailed = 412,
41
- ContentTooLarge = 413,
42
- UriTooLong = 414,
43
- UnsupportedMediaType = 415,
44
- RangeNotSatisfiable = 416,
45
- ExpectationFailed = 417,
46
- ImATeapot = 418,
47
- MisdirectedRequest = 421,
48
- UnprocessableEntity = 422,
49
- Locked = 423,
50
- FailedDependency = 424,
51
- TooEarly = 425,
52
- UpgradeRequired = 426,
53
- PreconditionRequired = 428,
54
- TooManyRequests = 429,
55
- RequestHeaderFieldsTooLarge = 431,
56
- UnavailableForLegalReasons = 451,
57
- InternalServerError = 500,
58
- NotImplemented = 501,
59
- BadGateway = 502,
60
- ServiceUnavailable = 503,
61
- GatewayTimeout = 504,
62
- HttpVersionNotSupported = 505,
63
- VariantAlsoNegotiates = 506,
64
- InsufficientStorage = 507,
65
- LoopDetected = 508,
66
- NotExtended = 510,
67
- NetworkAuthenticationRequired = 511,
68
- }
69
-
70
- const STATUS_NAME_MAP: Record<HttpStatus, string> = {
71
- [HttpStatus.Continue]: "Continue",
72
- [HttpStatus.SwitchingProtocols]: "Switching Protocols",
73
- [HttpStatus.ProcessingDeprecated]: "Processing",
74
- [HttpStatus.EarlyHints]: "Early Hints",
75
- [HttpStatus.Ok]: "OK",
76
- [HttpStatus.Created]: "Created",
77
- [HttpStatus.Accepted]: "Accepted",
78
- [HttpStatus.NonAuthoritativeInformation]: "Non-Authoritative Information",
79
- [HttpStatus.NoContent]: "No Content",
80
- [HttpStatus.ResetContent]: "Reset Content",
81
- [HttpStatus.PartialContent]: "Partial Content",
82
- [HttpStatus.MultiStatus]: "Multi-Status",
83
- [HttpStatus.AlreadyReported]: "Already Reported",
84
- [HttpStatus.ImUsed]: "IM Used",
85
- [HttpStatus.MultipleChoices]: "Multiple Choices",
86
- [HttpStatus.MovedPermanently]: "Moved Permanently",
87
- [HttpStatus.Found]: "Found",
88
- [HttpStatus.SeeOther]: "See Other",
89
- [HttpStatus.NotModified]: "Not Modified",
90
- [HttpStatus.UseProxyDeprecated]: "Use Proxy",
91
- [HttpStatus.Unused]: "Unused",
92
- [HttpStatus.TemporaryRedirect]: "Temporary Redirect",
93
- [HttpStatus.PermanentRedirect]: "Permanent Redirect",
94
- [HttpStatus.BadRequest]: "Bad Request",
95
- [HttpStatus.Unauthorized]: "Unauthorized",
96
- [HttpStatus.PaymentRequired]: "Payment Required",
97
- [HttpStatus.Forbidden]: "Forbidden",
98
- [HttpStatus.NotFound]: "Not Found",
99
- [HttpStatus.MethodNotAllowed]: "Method Not Allowed",
100
- [HttpStatus.NotAcceptable]: "Not Acceptable",
101
- [HttpStatus.ProxyAuthenticationRequired]: "Proxy Authentication Required",
102
- [HttpStatus.RequestTimeout]: "Request Timeout",
103
- [HttpStatus.Conflict]: "Conflict",
104
- [HttpStatus.Gone]: "Gone",
105
- [HttpStatus.LengthRequired]: "Length Required",
106
- [HttpStatus.PreconditionFailed]: "Precondition Failed",
107
- [HttpStatus.ContentTooLarge]: "Content Too Large",
108
- [HttpStatus.UriTooLong]: "URI Too Long",
109
- [HttpStatus.UnsupportedMediaType]: "Unsupported Media Type",
110
- [HttpStatus.RangeNotSatisfiable]: "Range Not Satisfiable",
111
- [HttpStatus.ExpectationFailed]: "Expectation Failed",
112
- [HttpStatus.ImATeapot]: "I'm a Teapot",
113
- [HttpStatus.MisdirectedRequest]: "Misdirected Request",
114
- [HttpStatus.UnprocessableEntity]: "Unprocessable Entity",
115
- [HttpStatus.Locked]: "Locked",
116
- [HttpStatus.FailedDependency]: "Failed Dependency",
117
- [HttpStatus.TooEarly]: "Too Early",
118
- [HttpStatus.UpgradeRequired]: "Upgrade Required",
119
- [HttpStatus.PreconditionRequired]: "Precondition Required",
120
- [HttpStatus.TooManyRequests]: "Too Many Requests",
121
- [HttpStatus.RequestHeaderFieldsTooLarge]: "Request Header Fields Too Large",
122
- [HttpStatus.UnavailableForLegalReasons]: "Unavailable For Legal Reasons",
123
- [HttpStatus.InternalServerError]: "Internal Server Error",
124
- [HttpStatus.NotImplemented]: "Not Implemented",
125
- [HttpStatus.BadGateway]: "Bad Gateway",
126
- [HttpStatus.ServiceUnavailable]: "Service Unavailable",
127
- [HttpStatus.GatewayTimeout]: "Gateway Timeout",
128
- [HttpStatus.HttpVersionNotSupported]: "HTTP Version Not Supported",
129
- [HttpStatus.VariantAlsoNegotiates]: "Variant Also Negotiates",
130
- [HttpStatus.InsufficientStorage]: "Insufficient Storage",
131
- [HttpStatus.LoopDetected]: "Loop Detected",
132
- [HttpStatus.NotExtended]: "Not Extended",
133
- [HttpStatus.NetworkAuthenticationRequired]: "Network Authentication Required",
134
- };
135
-
136
- /**
137
- * Returns the name of the HTTP status code (200 -> "OK").
138
- * @param status The HTTP status code.
139
- * @returns The name of the HTTP status code or `undefined` if the status code is not recognized.
140
- */
141
- export function getHttpStatusName(status: number): string | undefined {
142
- return STATUS_NAME_MAP[status as HttpStatus];
143
- }