@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
@@ -0,0 +1,71 @@
1
+ import { t as ErrorResponse } from "./schema-DKqL09oQ.mjs";
2
+ import { T as GetResponseOutput, a as App, c as ApplyAppPrefix, f as BaseRoutes, s as ApplyAppDataPrefix, v as GetAppRoutes, y as GetRequestParamsInput } from "./types-BvjPE9EM.mjs";
3
+
4
+ //#region src/client.d.ts
5
+ /**
6
+ * Type-safe client based on routes defined server-side.
7
+ */
8
+ interface AppClient<TRoutes extends BaseRoutes> {
9
+ fetch<TMethod extends keyof TRoutes, TRoute extends keyof TRoutes[TMethod]>(method: TMethod, route: TRoute, inputs: GetRequestParamsInput<TRoutes, TMethod, TRoute>): Promise<GetResponseOutput<TRoutes, TMethod, TRoute>>;
10
+ fetch<TRoute extends keyof TRoutes["ANY"]>(method: string, route: TRoute, inputs: GetRequestParamsInput<TRoutes, "ANY", TRoute>): Promise<GetResponseOutput<TRoutes, "ANY", TRoute>>;
11
+ }
12
+ /**
13
+ * Creates a type-safe client based on the server-side app. This is only useful
14
+ * if your frontend is in the same TypeScript project as your backend, and you
15
+ * can reference it's types in the frontend.
16
+ *
17
+ * If that's not the case, generate your client using the OpenAPI docs.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Server-side:
22
+ * import { createApp } from "@aklinker1/zeta";
23
+ *
24
+ * const app = createApp();
25
+ * export type App = typeof app;
26
+ *
27
+ * // Client-side:
28
+ * import type { App } from "../server";
29
+ * // ^^^^ MAKE SURE TO ONLY IMPORT THE TYPE HERE
30
+ *
31
+ * const client = createAppClient<App>();
32
+ * ```
33
+ */
34
+ declare function createAppClient<TApp extends App>(options?: CreateAppClientOptions): AppClient<GetClientRoutes<TApp>>;
35
+ /**
36
+ * Helper for converting an `App` to the routes it exposes.
37
+ */
38
+ type GetClientRoutes<TApp> = TApp extends App<infer AppData> ? ApplyAppDataPrefix<AppData>["routes"] : never;
39
+ /**
40
+ * Thrown by the client when the response is not OK. When an `HttpError` is
41
+ * thrown server-side, this is the error throw client-side.
42
+ */
43
+ declare class RequestError extends Error {
44
+ status: number;
45
+ response: ErrorResponse;
46
+ constructor(message: string, status: number, response: ErrorResponse, options?: ErrorOptions);
47
+ }
48
+ /**
49
+ * Helper for converting an `App` type to `AppClient`.
50
+ */
51
+ type GetAppClient<TApp extends App> = App extends {
52
+ prefix: string;
53
+ } ? GetAppClient<ApplyAppPrefix<TApp>> : AppClient<GetAppRoutes<TApp> extends BaseRoutes ? GetAppRoutes<TApp> : never>;
54
+ /**
55
+ * Configure the client's behavior.
56
+ */
57
+ type CreateAppClientOptions = {
58
+ fetch?: typeof fetch;
59
+ /**
60
+ * Base URL used when making requests.
61
+ * @default location.origin
62
+ */
63
+ baseUrl?: string;
64
+ /**
65
+ * List of headers to send on every request.
66
+ * @default {}
67
+ */
68
+ headers?: Record<string, string>;
69
+ };
70
+ //#endregion
71
+ export { AppClient, CreateAppClientOptions, GetAppClient, GetClientRoutes, RequestError, createAppClient };
@@ -0,0 +1,73 @@
1
+ import { n as smartSerialize, t as smartDeserialize } from "./serialization-0dai2wUm.mjs";
2
+ //#region src/client.ts
3
+ /**
4
+ * Creates a type-safe client based on the server-side app. This is only useful
5
+ * if your frontend is in the same TypeScript project as your backend, and you
6
+ * can reference it's types in the frontend.
7
+ *
8
+ * If that's not the case, generate your client using the OpenAPI docs.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Server-side:
13
+ * import { createApp } from "@aklinker1/zeta";
14
+ *
15
+ * const app = createApp();
16
+ * export type App = typeof app;
17
+ *
18
+ * // Client-side:
19
+ * import type { App } from "../server";
20
+ * // ^^^^ MAKE SURE TO ONLY IMPORT THE TYPE HERE
21
+ *
22
+ * const client = createAppClient<App>();
23
+ * ```
24
+ */
25
+ function createAppClient(options) {
26
+ const { baseUrl = location.origin, fetch = globalThis.fetch, headers = {} } = options ?? {};
27
+ const buildSearchParams = (query) => {
28
+ return new URLSearchParams(Object.entries(query).filter(([, value]) => value != null).map(([key, value]) => [key, String(value)])).toString();
29
+ };
30
+ const buildPath = (route, params) => {
31
+ return Object.entries(params).reduce((path, [key, value]) => path.replace(key === "**" ? key : new RegExp(`\\*{2}:${key}|:${key}`), encodeURIComponent(String(value))), route);
32
+ };
33
+ return { async fetch(method, route, inputs) {
34
+ const searchParams = inputs.query == null ? "" : `?${buildSearchParams(inputs.query).toString()}`;
35
+ const url = `${join(baseUrl, inputs.params == null ? route : buildPath(route, inputs.params))}${searchParams}`;
36
+ const init = {
37
+ body: void 0,
38
+ method: method.toUpperCase(),
39
+ headers: { ...headers }
40
+ };
41
+ const serializedBody = inputs.body == null ? void 0 : smartSerialize(inputs.body);
42
+ if (serializedBody) {
43
+ init.body = serializedBody.value;
44
+ if (serializedBody.contentType) init.headers["Content-Type"] = serializedBody.contentType;
45
+ }
46
+ try {
47
+ const res = await fetch(url, init);
48
+ const response = await smartDeserialize(res);
49
+ if (!res.ok) throw new RequestError(response?.message ?? "Unknown error", res.status, response);
50
+ return response;
51
+ } catch (err) {
52
+ throw Error("Fetch failed", { cause: err });
53
+ }
54
+ } };
55
+ }
56
+ /**
57
+ * Thrown by the client when the response is not OK. When an `HttpError` is
58
+ * thrown server-side, this is the error throw client-side.
59
+ */
60
+ var RequestError = class extends Error {
61
+ constructor(message, status, response, options) {
62
+ super(message, options);
63
+ this.status = status;
64
+ this.response = response;
65
+ this.name = "RequestError";
66
+ }
67
+ };
68
+ /** Join string together using `/` without double slashes. */
69
+ function join(...paths) {
70
+ return paths.map((path) => path.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
71
+ }
72
+ //#endregion
73
+ export { RequestError, createAppClient };
@@ -0,0 +1,317 @@
1
+ import { i as NoResponse, l as HttpStatus, s as ZetaSchema, t as ErrorResponse, u as getHttpStatusName } from "./schema-DKqL09oQ.mjs";
2
+ import { a as App, d as BasePrefix, i as AnyTransport, st as Transport, tt as SchemaAdapter, u as BasePath } from "./types-BvjPE9EM.mjs";
3
+ import { OpenAPI, OpenAPIV3_1 } from "openapi-types";
4
+
5
+ //#region src/app.d.ts
6
+ /**
7
+ * Create a server-side, Zeta application.
8
+ *
9
+ * Zeta provides simple support for serving applications using `Bun.serve` and
10
+ * `Deno.serve` by calling `app.listen(3000)`.
11
+ *
12
+ * If you need more customization, you can use the `build` method to create a
13
+ * `fetch` function and serve it however you like.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { createApp } from "@aklinker1/zeta";
18
+ *
19
+ * const app = createApp({ prefix: "/api" })
20
+ * .get("/health", () => "OK")
21
+ * .get("/users", () => ["user1", "user2"]);
22
+ *
23
+ * app.listen(3000);
24
+ *
25
+ * // Or serve the app yourself
26
+ * const fetch = app.build();
27
+ * Bun.serve({ fetch, ... });
28
+ * Deno.serve({ ... }, fetch);
29
+ * ```
30
+ *
31
+ * @param options Configure application behavior.
32
+ */
33
+ declare function createApp<TPrefix extends BasePrefix = "", TTransport extends AnyTransport = Transport>(options?: CreateAppOptions<TPrefix, TTransport>): App<{
34
+ ctx: {};
35
+ exported: false;
36
+ prefix: TPrefix;
37
+ routes: {};
38
+ transport: TTransport;
39
+ }>;
40
+ /**
41
+ * Configure how the app is created.
42
+ */
43
+ type CreateAppOptions<TPrefix extends BasePrefix = "", TTransport extends AnyTransport = Transport> = {
44
+ /**
45
+ * The origin to use when constructing URLs.
46
+ * @default "http://localhost"
47
+ */
48
+ origin?: string;
49
+ /**
50
+ * Add a prefix to the beginning of all routes in the app.
51
+ */
52
+ prefix?: TPrefix;
53
+ /**
54
+ * Tell Zeta which library you're using for validation. OpenAPI docs cannot
55
+ * be served without a schema adapter.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { zodSchemaAdapter } from "@aklinker1/zeta/adapters/zod-schema-adapter"
60
+ *
61
+ * const app = createApp({
62
+ * openApi: {
63
+ * schemaAdapter: zodSchemaAdapter,
64
+ * },
65
+ * });
66
+ * ```
67
+ */
68
+ schemaAdapter?: SchemaAdapter;
69
+ /**
70
+ * Tell Zeta how to serve your app over a port. By default, Zeta will detect
71
+ * if you're runtime is Bun or Deno, and use the appropriate transport.
72
+ *
73
+ * If you need to customize the transport, like adding an `idleTimeout` to
74
+ * bun, you can do so by passing options into the transport's factory function.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { createBunTransport } from "@aklinker1/zeta/transports/bun-transport"
79
+ *
80
+ * const app = createApp({
81
+ * transport: createBunTransport(),
82
+ * });
83
+ * ```
84
+ */
85
+ transport?: TTransport;
86
+ /**
87
+ * Where the OpenAPI JSON docs is hosted.
88
+ * @default "/openapi.json"
89
+ */
90
+ openApiRoute?: BasePath;
91
+ /**
92
+ * Where the Scalar UI is hosted.
93
+ * @default "/scalar"
94
+ */
95
+ scalarRoute?: BasePath; /** Configure how your application's OpenAPI docs are generated. */
96
+ openApi?: Partial<OpenAPIV3_1.Document> & {};
97
+ /**
98
+ * OpenAPI tags to apply to all routes in this app. Route-level tags will
99
+ * override these app-level tags.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const usersApp = createApp({
104
+ * prefix: "/users",
105
+ * tags: ["Users"],
106
+ * })
107
+ * .get("/", {}, () => [...]) // Will have ["Users"] tag
108
+ * .get("/:id", { tags: ["Admin"] }, () => {...}) // Will have ["Admin"] tag (overrides app-level)
109
+ * ```
110
+ */
111
+ tags?: string[];
112
+ /**
113
+ * OpenAPI security requirements to apply to all routes in this app.
114
+ * Route-level security will override these app-level security requirements.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const authApp = createApp({
119
+ * prefix: "/auth",
120
+ * security: [{ bearerAuth: [] }],
121
+ * })
122
+ * .get("/profile", {}, () => {...}) // Will require bearerAuth
123
+ * .get("/admin", { security: [{ adminKey: [] }] }, () => {...}) // Will require adminKey (overrides app-level)
124
+ * ```
125
+ */
126
+ security?: OpenAPI.Document["security"];
127
+ /**
128
+ * Configure [Scalar](https://scalar.com/) UI docs.
129
+ * @see https://github.com/scalar/scalar/blob/main/documentation/configuration.md#list-of-all-attributes
130
+ */
131
+ scalar?: any;
132
+ };
133
+ //#endregion
134
+ //#region src/errors.d.ts
135
+ /**
136
+ * Base class of all HTTP errors. You can throw this error or throw any of the
137
+ * subclasses. Zeta will automatically detect and handle these errors, setting
138
+ * the appropriate status code and message.
139
+ *
140
+ * Error responses will include the stacktrace during development. To hide the
141
+ * stacktrace in production, set the `NODE_ENV` environment variable to
142
+ * `production`.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * throw new HttpError(HttpStatus.BadRequest, "Bad request")
147
+ * // OR
148
+ * throw new BadRequestError()
149
+ * ```
150
+ */
151
+ declare class HttpError extends Error {
152
+ readonly status: HttpStatus;
153
+ readonly additionalInfo?: Record<string, any> | undefined;
154
+ constructor(status: HttpStatus, message: string, additionalInfo?: Record<string, any> | undefined, options?: ErrorOptions);
155
+ }
156
+ /** Shorthand for `new HttpError(HttpStatus.BadRequest, "Bad Request", ...)` */
157
+ declare class BadRequestHttpError extends HttpError {
158
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
159
+ }
160
+ /** Shorthand for `new HttpError(HttpStatus.Unauthorized, "Unauthorized", ...)` */
161
+ declare class UnauthorizedHttpError extends HttpError {
162
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
163
+ }
164
+ /** Shorthand for `new HttpError(HttpStatus.PaymentRequired, "Payment Required", ...)` */
165
+ declare class PaymentRequiredHttpError extends HttpError {
166
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
167
+ }
168
+ /** Shorthand for `new HttpError(HttpStatus.Forbidden, "Forbidden", ...)` */
169
+ declare class ForbiddenHttpError extends HttpError {
170
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
171
+ }
172
+ /** Shorthand for `new HttpError(HttpStatus.NotFound, "Not Found", ...)` */
173
+ declare class NotFoundHttpError extends HttpError {
174
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
175
+ }
176
+ /** Shorthand for `new HttpError(HttpStatus.MethodNotAllowed, "Method Not Allowed", ...)` */
177
+ declare class MethodNotAllowedHttpError extends HttpError {
178
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
179
+ }
180
+ /** Shorthand for `new HttpError(HttpStatus.NotAcceptable, "Not Acceptable", ...)` */
181
+ declare class NotAcceptableHttpError extends HttpError {
182
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
183
+ }
184
+ /** Shorthand for `new HttpError(HttpStatus.ProxyAuthenticationRequired, "Proxy Authentication Required", ...)` */
185
+ declare class ProxyAuthenticationRequiredHttpError extends HttpError {
186
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
187
+ }
188
+ /** Shorthand for `new HttpError(HttpStatus.RequestTimeout, "Request Timeout", ...)` */
189
+ declare class RequestTimeoutHttpError extends HttpError {
190
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
191
+ }
192
+ /** Shorthand for `new HttpError(HttpStatus.Conflict, "Conflict", ...)` */
193
+ declare class ConflictHttpError extends HttpError {
194
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
195
+ }
196
+ /** Shorthand for `new HttpError(HttpStatus.Gone, "Gone", ...)` */
197
+ declare class GoneHttpError extends HttpError {
198
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
199
+ }
200
+ /** Shorthand for `new HttpError(HttpStatus.LengthRequired, "Length Required", ...)` */
201
+ declare class LengthRequiredHttpError extends HttpError {
202
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
203
+ }
204
+ /** Shorthand for `new HttpError(HttpStatus.PreconditionFailed, "Precondition Failed", ...)` */
205
+ declare class PreconditionFailedHttpError extends HttpError {
206
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
207
+ }
208
+ /** Shorthand for `new HttpError(HttpStatus.ContentTooLarge, "Content Too Large", ...)` */
209
+ declare class ContentTooLargeHttpError extends HttpError {
210
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
211
+ }
212
+ /** Shorthand for `new HttpError(HttpStatus.UriTooLong, "URI Too Long", ...)` */
213
+ declare class UriTooLongHttpError extends HttpError {
214
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
215
+ }
216
+ /** Shorthand for `new HttpError(HttpStatus.UnsupportedMediaType, "Unsupported Media Type", ...)` */
217
+ declare class UnsupportedMediaTypeHttpError extends HttpError {
218
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
219
+ }
220
+ /** Shorthand for `new HttpError(HttpStatus.RangeNotSatisfiable, "Range Not Satisfiable", ...)` */
221
+ declare class RangeNotSatisfiableHttpError extends HttpError {
222
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
223
+ }
224
+ /** Shorthand for `new HttpError(HttpStatus.ExpectationFailed, "Expectation Failed", ...)` */
225
+ declare class ExpectationFailedHttpError extends HttpError {
226
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
227
+ }
228
+ /** Shorthand for `new HttpError(HttpStatus.ImATeapot, "I'm a Teapot", ...)` */
229
+ declare class ImATeapotHttpError extends HttpError {
230
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
231
+ }
232
+ /** Shorthand for `new HttpError(HttpStatus.MisdirectedRequest, "Misdirected Request", ...)` */
233
+ declare class MisdirectedRequestHttpError extends HttpError {
234
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
235
+ }
236
+ /** Shorthand for `new HttpError(HttpStatus.UnprocessableEntity, "Unprocessable Entity", ...)` */
237
+ declare class UnprocessableEntityHttpError extends HttpError {
238
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
239
+ }
240
+ /** Shorthand for `new HttpError(HttpStatus.Locked, "Locked", ...)` */
241
+ declare class LockedHttpError extends HttpError {
242
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
243
+ }
244
+ /** Shorthand for `new HttpError(HttpStatus.FailedDependency, "Failed Dependency", ...)` */
245
+ declare class FailedDependencyHttpError extends HttpError {
246
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
247
+ }
248
+ /** Shorthand for `new HttpError(HttpStatus.TooEarly, "Too Early", ...)` */
249
+ declare class TooEarlyHttpError extends HttpError {
250
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
251
+ }
252
+ /** Shorthand for `new HttpError(HttpStatus.UpgradeRequired, "Upgrade Required", ...)` */
253
+ declare class UpgradeRequiredHttpError extends HttpError {
254
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
255
+ }
256
+ /** Shorthand for `new HttpError(HttpStatus.PreconditionRequired, "Precondition Required", ...)` */
257
+ declare class PreconditionRequiredHttpError extends HttpError {
258
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
259
+ }
260
+ /** Shorthand for `new HttpError(HttpStatus.TooManyRequests, "Too Many Requests", ...)` */
261
+ declare class TooManyRequestsHttpError extends HttpError {
262
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
263
+ }
264
+ /** Shorthand for `new HttpError(HttpStatus.RequestHeaderFieldsTooLarge, "Request Header Fields Too Large", ...)` */
265
+ declare class RequestHeaderFieldsTooLargeHttpError extends HttpError {
266
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
267
+ }
268
+ /** Shorthand for `new HttpError(HttpStatus.UnavailableForLegalReasons, "Unavailable For Legal Reasons", ...)` */
269
+ declare class UnavailableForLegalReasonsHttpError extends HttpError {
270
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
271
+ }
272
+ /** Shorthand for `new HttpError(HttpStatus.InternalServerError, "Internal Server Error", ...)` */
273
+ declare class InternalServerErrorHttpError extends HttpError {
274
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
275
+ }
276
+ /** Shorthand for `new HttpError(HttpStatus.NotImplemented, "Not Implemented", ...)` */
277
+ declare class NotImplementedHttpError extends HttpError {
278
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
279
+ }
280
+ /** Shorthand for `new HttpError(HttpStatus.BadGateway, "Bad Gateway", ...)` */
281
+ declare class BadGatewayHttpError extends HttpError {
282
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
283
+ }
284
+ /** Shorthand for `new HttpError(HttpStatus.ServiceUnavailable, "Service Unavailable", ...)` */
285
+ declare class ServiceUnavailableHttpError extends HttpError {
286
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
287
+ }
288
+ /** Shorthand for `new HttpError(HttpStatus.GatewayTimeout, "Gateway Timeout", ...)` */
289
+ declare class GatewayTimeoutHttpError extends HttpError {
290
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
291
+ }
292
+ /** Shorthand for `new HttpError(HttpStatus.HttpVersionNotSupported, "HTTP Version Not Supported", ...)` */
293
+ declare class HttpVersionNotSupportedHttpError extends HttpError {
294
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
295
+ }
296
+ /** Shorthand for `new HttpError(HttpStatus.VariantAlsoNegotiates, "Variant Also Negotiates", ...)` */
297
+ declare class VariantAlsoNegotiatesHttpError extends HttpError {
298
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
299
+ }
300
+ /** Shorthand for `new HttpError(HttpStatus.InsufficientStorage, "Insufficient Storage", ...)` */
301
+ declare class InsufficientStorageHttpError extends HttpError {
302
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
303
+ }
304
+ /** Shorthand for `new HttpError(HttpStatus.LoopDetected, "Loop Detected", ...)` */
305
+ declare class LoopDetectedHttpError extends HttpError {
306
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
307
+ }
308
+ /** Shorthand for `new HttpError(HttpStatus.NotExtended, "Not Extended", ...)` */
309
+ declare class NotExtendedHttpError extends HttpError {
310
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
311
+ }
312
+ /** Shorthand for `new HttpError(HttpStatus.NetworkAuthenticationRequired, "Network Authentication Required", ...)` */
313
+ declare class NetworkAuthenticationRequiredHttpError extends HttpError {
314
+ constructor(message?: string, additionalInfo?: Record<string, any>, options?: ErrorOptions);
315
+ }
316
+ //#endregion
317
+ export { type App, BadGatewayHttpError, BadRequestHttpError, ConflictHttpError, ContentTooLargeHttpError, CreateAppOptions, ErrorResponse, ExpectationFailedHttpError, FailedDependencyHttpError, ForbiddenHttpError, GatewayTimeoutHttpError, GoneHttpError, HttpError, HttpStatus, HttpVersionNotSupportedHttpError, ImATeapotHttpError, InsufficientStorageHttpError, InternalServerErrorHttpError, LengthRequiredHttpError, LockedHttpError, LoopDetectedHttpError, MethodNotAllowedHttpError, MisdirectedRequestHttpError, NetworkAuthenticationRequiredHttpError, NoResponse, NotAcceptableHttpError, NotExtendedHttpError, NotFoundHttpError, NotImplementedHttpError, PaymentRequiredHttpError, PreconditionFailedHttpError, PreconditionRequiredHttpError, ProxyAuthenticationRequiredHttpError, RangeNotSatisfiableHttpError, RequestHeaderFieldsTooLargeHttpError, RequestTimeoutHttpError, ServiceUnavailableHttpError, TooEarlyHttpError, TooManyRequestsHttpError, UnauthorizedHttpError, UnavailableForLegalReasonsHttpError, UnprocessableEntityHttpError, UnsupportedMediaTypeHttpError, UpgradeRequiredHttpError, UriTooLongHttpError, VariantAlsoNegotiatesHttpError, type ZetaSchema, createApp, getHttpStatusName };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { A as RangeNotSatisfiableHttpError, B as UpgradeRequiredHttpError, C as NotExtendedHttpError, D as PreconditionFailedHttpError, E as PaymentRequiredHttpError, F as TooManyRequestsHttpError, H as VariantAlsoNegotiatesHttpError, I as UnauthorizedHttpError, L as UnavailableForLegalReasonsHttpError, M as RequestTimeoutHttpError, N as ServiceUnavailableHttpError, O as PreconditionRequiredHttpError, P as TooEarlyHttpError, R as UnprocessableEntityHttpError, S as NotAcceptableHttpError, T as NotImplementedHttpError, U as HttpStatus, V as UriTooLongHttpError, W as getHttpStatusName, _ as LockedHttpError, a as ContentTooLargeHttpError, b as MisdirectedRequestHttpError, c as ForbiddenHttpError, d as HttpError, f as HttpVersionNotSupportedHttpError, g as LengthRequiredHttpError, h as InternalServerErrorHttpError, i as ConflictHttpError, j as RequestHeaderFieldsTooLargeHttpError, k as ProxyAuthenticationRequiredHttpError, l as GatewayTimeoutHttpError, m as InsufficientStorageHttpError, n as BadGatewayHttpError, o as ExpectationFailedHttpError, p as ImATeapotHttpError, r as BadRequestHttpError, s as FailedDependencyHttpError, t as createApp, u as GoneHttpError, v as LoopDetectedHttpError, w as NotFoundHttpError, x as NetworkAuthenticationRequiredHttpError, y as MethodNotAllowedHttpError, z as UnsupportedMediaTypeHttpError } from "./app-Bc9Kn3KA.mjs";
2
+ import { ErrorResponse, NoResponse } from "./schema.mjs";
3
+ export { BadGatewayHttpError, BadRequestHttpError, ConflictHttpError, ContentTooLargeHttpError, ErrorResponse, ExpectationFailedHttpError, FailedDependencyHttpError, ForbiddenHttpError, GatewayTimeoutHttpError, GoneHttpError, HttpError, HttpStatus, HttpVersionNotSupportedHttpError, ImATeapotHttpError, InsufficientStorageHttpError, InternalServerErrorHttpError, LengthRequiredHttpError, LockedHttpError, LoopDetectedHttpError, MethodNotAllowedHttpError, MisdirectedRequestHttpError, NetworkAuthenticationRequiredHttpError, NoResponse, NotAcceptableHttpError, NotExtendedHttpError, NotFoundHttpError, NotImplementedHttpError, PaymentRequiredHttpError, PreconditionFailedHttpError, PreconditionRequiredHttpError, ProxyAuthenticationRequiredHttpError, RangeNotSatisfiableHttpError, RequestHeaderFieldsTooLargeHttpError, RequestTimeoutHttpError, ServiceUnavailableHttpError, TooEarlyHttpError, TooManyRequestsHttpError, UnauthorizedHttpError, UnavailableForLegalReasonsHttpError, UnprocessableEntityHttpError, UnsupportedMediaTypeHttpError, UpgradeRequiredHttpError, UriTooLongHttpError, VariantAlsoNegotiatesHttpError, createApp, getHttpStatusName };
@@ -0,0 +1,168 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ //#region src/status.d.ts
4
+ /**
5
+ * Enum containing all HTTP status codes.
6
+ */
7
+ declare enum HttpStatus {
8
+ Continue = 100,
9
+ SwitchingProtocols = 101,
10
+ ProcessingDeprecated = 102,
11
+ EarlyHints = 103,
12
+ Ok = 200,
13
+ Created = 201,
14
+ Accepted = 202,
15
+ NonAuthoritativeInformation = 203,
16
+ NoContent = 204,
17
+ ResetContent = 205,
18
+ PartialContent = 206,
19
+ MultiStatus = 207,
20
+ AlreadyReported = 208,
21
+ ImUsed = 226,
22
+ MultipleChoices = 300,
23
+ MovedPermanently = 301,
24
+ Found = 302,
25
+ SeeOther = 303,
26
+ NotModified = 304,
27
+ UseProxyDeprecated = 305,
28
+ Unused = 306,
29
+ TemporaryRedirect = 307,
30
+ PermanentRedirect = 308,
31
+ BadRequest = 400,
32
+ Unauthorized = 401,
33
+ PaymentRequired = 402,
34
+ Forbidden = 403,
35
+ NotFound = 404,
36
+ MethodNotAllowed = 405,
37
+ NotAcceptable = 406,
38
+ ProxyAuthenticationRequired = 407,
39
+ RequestTimeout = 408,
40
+ Conflict = 409,
41
+ Gone = 410,
42
+ LengthRequired = 411,
43
+ PreconditionFailed = 412,
44
+ ContentTooLarge = 413,
45
+ UriTooLong = 414,
46
+ UnsupportedMediaType = 415,
47
+ RangeNotSatisfiable = 416,
48
+ ExpectationFailed = 417,
49
+ ImATeapot = 418,
50
+ MisdirectedRequest = 421,
51
+ UnprocessableEntity = 422,
52
+ Locked = 423,
53
+ FailedDependency = 424,
54
+ TooEarly = 425,
55
+ UpgradeRequired = 426,
56
+ PreconditionRequired = 428,
57
+ TooManyRequests = 429,
58
+ RequestHeaderFieldsTooLarge = 431,
59
+ UnavailableForLegalReasons = 451,
60
+ InternalServerError = 500,
61
+ NotImplemented = 501,
62
+ BadGateway = 502,
63
+ ServiceUnavailable = 503,
64
+ GatewayTimeout = 504,
65
+ HttpVersionNotSupported = 505,
66
+ VariantAlsoNegotiates = 506,
67
+ InsufficientStorage = 507,
68
+ LoopDetected = 508,
69
+ NotExtended = 510,
70
+ NetworkAuthenticationRequired = 511
71
+ }
72
+ /**
73
+ * Returns the name of the HTTP status code (200 -> "OK").
74
+ * @param status The HTTP status code.
75
+ * @returns The name of the HTTP status code or `undefined` if the status code is not recognized.
76
+ */
77
+ declare function getHttpStatusName(status: number): string | undefined;
78
+ //#endregion
79
+ //#region src/schema.d.ts
80
+ type ZetaSchema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> & {
81
+ "~zeta": {
82
+ type: string;
83
+ meta: Record<string, any>;
84
+ };
85
+ toJsonSchema?(): any;
86
+ meta(meta?: Record<string, any>): ZetaSchema<Input, Output>;
87
+ };
88
+ /**
89
+ * A schema for an error response. Use when defining additional status codes
90
+ * that an operation might return with:
91
+ *
92
+ * ```ts
93
+ * import { ErrorResponse } from '@aklinker/zeta';
94
+ *
95
+ * app.get(
96
+ * "/api/item/:itemId",
97
+ * {
98
+ * responses: {
99
+ * 200: Item.optional(),
100
+ * 404: ErrorResponse,
101
+ * }
102
+ * },
103
+ * () => {
104
+ * // ...
105
+ * }
106
+ * );
107
+ * ```
108
+ */
109
+ declare const ErrorResponse: ZetaSchema<unknown, ErrorResponse>;
110
+ declare function isZetaSchema(schema: any): schema is ZetaSchema;
111
+ /**
112
+ * The actual type an error response conforms to.
113
+ */
114
+ type ErrorResponse = {
115
+ [additionalInfo: string]: any;
116
+ name: string;
117
+ message: string;
118
+ status: HttpStatus;
119
+ stack?: string[];
120
+ cause?: ErrorResponse;
121
+ };
122
+ declare const ErrorResponseJsonSchema: {
123
+ type: "object";
124
+ properties: {
125
+ status: {
126
+ type: "number";
127
+ description: string;
128
+ example: number;
129
+ };
130
+ name: {
131
+ type: "string";
132
+ description: string;
133
+ example: string;
134
+ };
135
+ message: {
136
+ type: "string";
137
+ description: string;
138
+ example: string;
139
+ };
140
+ };
141
+ required: string[];
142
+ };
143
+ /**
144
+ * A schema for when you want to not return a response. Use when defining
145
+ * additional status codes that an operation might return with:
146
+ *
147
+ * ```ts
148
+ * import { NoResponse } from '@aklinker/zeta';
149
+ *
150
+ * app.get(
151
+ * "/api/item/:itemId",
152
+ * {
153
+ * responses: {
154
+ * [HttpStatus.Accepted]: NoResponse,
155
+ * }
156
+ * },
157
+ * () => {
158
+ * // ...
159
+ * }
160
+ * );
161
+ * ```
162
+ */
163
+ declare const NoResponse: ZetaSchema<undefined | null | void, void>;
164
+ declare const FormDataBody: ZetaSchema<FormData>;
165
+ declare const UploadFileBody: ZetaSchema<File>;
166
+ declare const UploadFilesBody: ZetaSchema<FileList, File[]>;
167
+ //#endregion
168
+ export { UploadFileBody as a, isZetaSchema as c, NoResponse as i, HttpStatus as l, ErrorResponseJsonSchema as n, UploadFilesBody as o, FormDataBody as r, ZetaSchema as s, ErrorResponse as t, getHttpStatusName as u };
@@ -0,0 +1,2 @@
1
+ import { a as UploadFileBody, c as isZetaSchema, i as NoResponse, n as ErrorResponseJsonSchema, o as UploadFilesBody, r as FormDataBody, s as ZetaSchema, t as ErrorResponse } from "./schema-DKqL09oQ.mjs";
2
+ export { ErrorResponse, ErrorResponseJsonSchema, FormDataBody, NoResponse, UploadFileBody, UploadFilesBody, ZetaSchema, isZetaSchema };