@ozanarslan/corpus 0.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.
@@ -0,0 +1,758 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /// <reference types="node" />
4
+
5
+ export type ValueOf<T> = T[keyof T];
6
+ /** Just some common headers. */
7
+ export declare const CommonHeaders: {
8
+ /** Controls caching mechanisms for requests and responses */
9
+ readonly CacheControl: "Cache-Control";
10
+ /** Specifies the media type of the resource or data */
11
+ readonly ContentType: "Content-Type";
12
+ /** Indicates the size of the entity-body in bytes */
13
+ readonly ContentLength: "Content-Length";
14
+ /** Specifies the character encodings that are acceptable */
15
+ readonly AcceptEncoding: "Accept-Encoding";
16
+ /** Informs the server about the types of data that can be sent back */
17
+ readonly Accept: "Accept";
18
+ /** Contains the credentials to authenticate with the server */
19
+ readonly Authorization: "Authorization";
20
+ /** The user agent string of the client software */
21
+ readonly UserAgent: "User-Agent";
22
+ /** The domain name of the server and port number */
23
+ readonly Host: "Host";
24
+ /** The address of the previous web page from which the current request originated */
25
+ readonly Referer: "Referer";
26
+ /** Indicates whether the connection should be kept alive */
27
+ readonly Connection: "Connection";
28
+ /** Used to specify directives that must be obeyed by caching mechanisms */
29
+ readonly Pragma: "Pragma";
30
+ /** The date and time at which the message was sent */
31
+ readonly Date: "Date";
32
+ /** Makes the request conditional based on the ETag of the resource */
33
+ readonly IfNoneMatch: "If-None-Match";
34
+ /** Makes the request conditional based on the last modification date */
35
+ readonly IfModifiedSince: "If-Modified-Since";
36
+ /** An identifier for a specific version of a resource */
37
+ readonly ETag: "ETag";
38
+ /** The date and time after which the response is considered stale */
39
+ readonly Expires: "Expires";
40
+ /** The last modification date of the resource */
41
+ readonly LastModified: "Last-Modified";
42
+ /** Indicates the URL to redirect a page to */
43
+ readonly Location: "Location";
44
+ /** Defines the authentication method that should be used */
45
+ readonly WWWAuthenticate: "WWW-Authenticate";
46
+ /** Allows the server to indicate its origin */
47
+ readonly AccessControlAllowOrigin: "Access-Control-Allow-Origin";
48
+ /** Determines how long the results of a preflight request can be cached */
49
+ readonly AccessControlMaxAge: "Access-Control-Max-Age";
50
+ /** Indicates whether the response can be shared with resources with credentials */
51
+ readonly AccessControlAllowCredentials: "Access-Control-Allow-Credentials";
52
+ readonly AccessControlRequestMethod: "Access-Control-Request-Method";
53
+ readonly SetCookie: "Set-Cookie";
54
+ readonly Cookie: "Cookie";
55
+ };
56
+ export type CommonHeaders = ValueOf<typeof CommonHeaders>;
57
+ /** Commonly used HTTP verbs. */
58
+ export declare const Method: {
59
+ readonly GET: "GET";
60
+ readonly POST: "POST";
61
+ readonly PUT: "PUT";
62
+ readonly PATCH: "PATCH";
63
+ readonly DELETE: "DELETE";
64
+ readonly HEAD: "HEAD";
65
+ readonly OPTIONS: "OPTIONS";
66
+ readonly CONNECT: "CONNECT";
67
+ readonly TRACE: "TRACE";
68
+ };
69
+ export type Method = ValueOf<typeof Method>;
70
+ /** Commonly used HTTP status codes. */
71
+ export declare const Status: {
72
+ /** --- 1xx Informational --- */
73
+ /** Continue: Request received, please continue */
74
+ readonly CONTINUE: 100;
75
+ /** Switching Protocols: Protocol change request approved */
76
+ readonly SWITCHING_PROTOCOLS: 101;
77
+ /** Processing (WebDAV) */
78
+ readonly PROCESSING: 102;
79
+ /** Early Hints */
80
+ readonly EARLY_HINTS: 103;
81
+ /** --- 2xx Success --- */
82
+ /** OK: Request succeeded */
83
+ readonly OK: 200;
84
+ /** Created: Resource created */
85
+ readonly CREATED: 201;
86
+ /** Accepted: Request accepted but not completed */
87
+ readonly ACCEPTED: 202;
88
+ /** Non-Authoritative Information */
89
+ readonly NON_AUTHORITATIVE_INFORMATION: 203;
90
+ /** No Content: Request succeeded, no body returned */
91
+ readonly NO_CONTENT: 204;
92
+ /** Reset Content: Clear form or view */
93
+ readonly RESET_CONTENT: 205;
94
+ /** Partial Content: Partial GET successful (e.g. range requests) */
95
+ readonly PARTIAL_CONTENT: 206;
96
+ /** Multi-Status (WebDAV) */
97
+ readonly MULTI_STATUS: 207;
98
+ /** Already Reported (WebDAV) */
99
+ readonly ALREADY_REPORTED: 208;
100
+ /** IM Used (HTTP Delta encoding) */
101
+ readonly IM_USED: 226;
102
+ /** --- 3xx Redirection --- */
103
+ /** Multiple Choices */
104
+ readonly MULTIPLE_CHOICES: 300;
105
+ /** Moved Permanently: Resource moved to a new URL */
106
+ readonly MOVED_PERMANENTLY: 301;
107
+ /** Found: Resource temporarily under different URI */
108
+ readonly FOUND: 302;
109
+ /** See Other: Redirect to another URI using GET */
110
+ readonly SEE_OTHER: 303;
111
+ /** Not Modified: Cached version is still valid */
112
+ readonly NOT_MODIFIED: 304;
113
+ /** Use Proxy: Deprecated */
114
+ readonly USE_PROXY: 305;
115
+ /** Temporary Redirect: Resource temporarily at another URI */
116
+ readonly TEMPORARY_REDIRECT: 307;
117
+ /** Permanent Redirect: Resource permanently at another URI */
118
+ readonly PERMANENT_REDIRECT: 308;
119
+ /** --- 4xx Client Errors --- */
120
+ /** Bad Request: Malformed request */
121
+ readonly BAD_REQUEST: 400;
122
+ /** Unauthorized: Missing or invalid auth credentials */
123
+ readonly UNAUTHORIZED: 401;
124
+ /** Payment Required: Reserved for future use */
125
+ readonly PAYMENT_REQUIRED: 402;
126
+ /** Forbidden: Authenticated but no permission */
127
+ readonly FORBIDDEN: 403;
128
+ /** Not Found: Resource does not exist */
129
+ readonly NOT_FOUND: 404;
130
+ /** Method Not Allowed: HTTP method not allowed */
131
+ readonly METHOD_NOT_ALLOWED: 405;
132
+ /** Not Acceptable: Response not acceptable by client */
133
+ readonly NOT_ACCEPTABLE: 406;
134
+ /** Proxy Authentication Required */
135
+ readonly PROXY_AUTHENTICATION_REQUIRED: 407;
136
+ /** Request Timeout: Server timeout waiting for client */
137
+ readonly REQUEST_TIMEOUT: 408;
138
+ /** Conflict: Request conflict (e.g. duplicate resource) */
139
+ readonly CONFLICT: 409;
140
+ /** Gone: Resource is no longer available */
141
+ readonly GONE: 410;
142
+ /** Length Required: Missing Content-Length header */
143
+ readonly LENGTH_REQUIRED: 411;
144
+ /** Precondition Failed */
145
+ readonly PRECONDITION_FAILED: 412;
146
+ /** Payload Too Large */
147
+ readonly PAYLOAD_TOO_LARGE: 413;
148
+ /** URI Too Long */
149
+ readonly URI_TOO_LONG: 414;
150
+ /** Unsupported Media Type */
151
+ readonly UNSUPPORTED_MEDIA_TYPE: 415;
152
+ /** Range Not Satisfiable */
153
+ readonly RANGE_NOT_SATISFIABLE: 416;
154
+ /** Expectation Failed */
155
+ readonly EXPECTATION_FAILED: 417;
156
+ /** I'm a teapot: Joke response for coffee machines */
157
+ readonly IM_A_TEAPOT: 418;
158
+ /** Misdirected Request: Sent to the wrong server */
159
+ readonly MISDIRECTED_REQUEST: 421;
160
+ /** Unprocessable Entity (WebDAV) */
161
+ readonly UNPROCESSABLE_ENTITY: 422;
162
+ /** Locked (WebDAV) */
163
+ readonly LOCKED: 423;
164
+ /** Failed Dependency (WebDAV) */
165
+ readonly FAILED_DEPENDENCY: 424;
166
+ /** Too Early: Request might be replayed */
167
+ readonly TOO_EARLY: 425;
168
+ /** Upgrade Required */
169
+ readonly UPGRADE_REQUIRED: 426;
170
+ /** Precondition Required */
171
+ readonly PRECONDITION_REQUIRED: 428;
172
+ /** Too Many Requests: Rate limiting */
173
+ readonly TOO_MANY_REQUESTS: 429;
174
+ /** Request Header Fields Too Large */
175
+ readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
176
+ /** Unavailable For Legal Reasons */
177
+ readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
178
+ /** --- 5xx Server Errors --- */
179
+ /** Internal Server Error: Unhandled server error */
180
+ readonly INTERNAL_SERVER_ERROR: 500;
181
+ /** Not Implemented: Endpoint/method not implemented */
182
+ readonly NOT_IMPLEMENTED: 501;
183
+ /** Bad Gateway: Invalid response from upstream server */
184
+ readonly BAD_GATEWAY: 502;
185
+ /** Service Unavailable: Server temporarily overloaded/down */
186
+ readonly SERVICE_UNAVAILABLE: 503;
187
+ /** Gateway Timeout: No response from upstream server */
188
+ readonly GATEWAY_TIMEOUT: 504;
189
+ /** HTTP Version Not Supported */
190
+ readonly HTTP_VERSION_NOT_SUPPORTED: 505;
191
+ /** Variant Also Negotiates */
192
+ readonly VARIANT_ALSO_NEGOTIATES: 506;
193
+ /** Insufficient Storage (WebDAV) */
194
+ readonly INSUFFICIENT_STORAGE: 507;
195
+ /** Loop Detected (WebDAV) */
196
+ readonly LOOP_DETECTED: 508;
197
+ /** Not Extended */
198
+ readonly NOT_EXTENDED: 510;
199
+ /** Network Authentication Required */
200
+ readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
201
+ };
202
+ export type Status = ValueOf<typeof Status> | number;
203
+ export type ConfigValueParser<T> = (value: string) => T;
204
+ export interface DatabaseClientInterface {
205
+ }
206
+ export interface ContextDataInterface {
207
+ }
208
+ export interface Env {
209
+ }
210
+ export type OrString<T> = T | (string & {});
211
+ export type ConfigEnvKey = OrString<keyof Env>;
212
+ export declare class Config {
213
+ static get env(): NodeJS.ProcessEnv;
214
+ static cwd(): string;
215
+ static resolvePath(...paths: string[]): string;
216
+ static get<T = string>(key: ConfigEnvKey, opts?: {
217
+ parser?: ConfigValueParser<T>;
218
+ fallback?: T;
219
+ }): T;
220
+ static set(key: string, value: string): void;
221
+ }
222
+ export type HttpHeaderKey = OrString<CommonHeaders>;
223
+ export type CorsOptions = {
224
+ allowedOrigins?: string[];
225
+ allowedMethods?: string[];
226
+ allowedHeaders?: HttpHeaderKey[];
227
+ credentials?: boolean;
228
+ };
229
+ export type CookieOptions = {
230
+ name: string;
231
+ value: string;
232
+ domain?: string;
233
+ /** Defaults to '/'. */
234
+ path?: string;
235
+ expires?: number | Date;
236
+ secure?: boolean;
237
+ /** Defaults to `lax`. */
238
+ sameSite?: "strict" | "lax" | "none";
239
+ httpOnly?: boolean;
240
+ partitioned?: boolean;
241
+ maxAge?: number;
242
+ };
243
+ export interface CookiesInterface {
244
+ set(opts: CookieOptions): void;
245
+ get(name: string): string | null;
246
+ has(name: string): boolean;
247
+ delete(opts: Pick<CookieOptions, "name" | "domain" | "path">): void;
248
+ entries(): IterableIterator<[
249
+ string,
250
+ string
251
+ ]>;
252
+ values(): Array<string>;
253
+ keys(): Array<string>;
254
+ decodeValue(cookieString: string): string | null;
255
+ createHeader(opts: CookieOptions): string;
256
+ toSetCookieHeaders(): string[];
257
+ }
258
+ export type HttpHeadersInit = Headers | HttpHeadersInterface | [
259
+ string,
260
+ string
261
+ ][] | (Record<string, string> & Partial<Record<HttpHeaderKey, string>>);
262
+ interface HttpHeadersInterface extends Headers {
263
+ append(name: HttpHeaderKey, value: string): void;
264
+ set(name: HttpHeaderKey, value: string): void;
265
+ combine(source: HttpHeadersInterface, target: HttpHeadersInterface): HttpHeadersInterface;
266
+ innerCombine(source: HttpHeadersInterface): HttpHeadersInterface;
267
+ setMany(init: HttpHeadersInit): void;
268
+ }
269
+ export type HttpResponseBody<R = unknown> = R | BodyInit | null | undefined;
270
+ export type CookiesInit = CookiesInterface | [
271
+ string,
272
+ string
273
+ ][] | Record<string, string>;
274
+ export type HttpResponseInit = {
275
+ cookies?: CookiesInit;
276
+ headers?: HttpHeadersInit;
277
+ status?: Status;
278
+ statusText?: string;
279
+ };
280
+ interface HttpResponseInterface<R = unknown> {
281
+ readonly body?: HttpResponseBody<R>;
282
+ readonly init?: HttpResponseInit;
283
+ headers: HttpHeadersInterface;
284
+ status: Status;
285
+ statusText: string;
286
+ cookies: CookiesInterface;
287
+ get response(): Response;
288
+ }
289
+ export type MaybePromise<T> = Promise<T> | T;
290
+ export type ErrorHandler<R = unknown> = (err: Error) => MaybePromise<HttpResponseInterface<R>>;
291
+ export type HttpRequestInfo = Request | string | HttpRequestInterface;
292
+ export type HttpRequestInit = Omit<RequestInit, "headers" | "method"> & {
293
+ headers?: HttpHeadersInit;
294
+ method?: Method;
295
+ };
296
+ interface HttpRequestInterface extends Request {
297
+ readonly input: HttpRequestInfo;
298
+ readonly init?: HttpRequestInit;
299
+ readonly cookies: CookiesInterface;
300
+ get headers(): HttpHeadersInterface;
301
+ get isPreflight(): boolean;
302
+ get urlObject(): URL;
303
+ }
304
+ export type RequestHandler<R = unknown> = (req: HttpRequestInterface) => MaybePromise<HttpResponseInterface<R>>;
305
+ export type ServeOptions = {
306
+ port: number;
307
+ hostname?: "0.0.0.0" | "127.0.0.1" | "localhost" | (string & {}) | undefined;
308
+ fetch: (request: Request) => Promise<Response>;
309
+ };
310
+ export interface ServerInterface {
311
+ serve(options: ServeOptions): void;
312
+ listen(port: ServeOptions["port"], hostname: ServeOptions["hostname"]): Promise<void>;
313
+ exit(): Promise<void>;
314
+ handle(request: Request): Promise<Response>;
315
+ setGlobalPrefix(value: string): void;
316
+ setCors(cors: CorsOptions): void;
317
+ setOnError(handler: ErrorHandler): void;
318
+ setOnNotFound(handler: RequestHandler): void;
319
+ setOnBeforeListen(handler: () => MaybePromise<void>): void;
320
+ setOnBeforeExit(handler: () => MaybePromise<void>): void;
321
+ setOnAfterResponse(handler: (res: HttpResponseInterface) => MaybePromise<HttpResponseInterface>): void;
322
+ }
323
+ export interface CorsInterface {
324
+ readonly opts: CorsOptions;
325
+ getCorsHeaders(req: HttpRequestInterface, res: HttpResponseInterface): HttpHeadersInterface;
326
+ apply(req: HttpRequestInterface, res: HttpResponseInterface): void;
327
+ }
328
+ declare abstract class ServerAbstract implements ServerInterface {
329
+ constructor();
330
+ abstract serve(options: ServeOptions): void;
331
+ abstract exit(): Promise<void>;
332
+ protected cors: CorsInterface | undefined;
333
+ protected handleBeforeListen: (() => MaybePromise<void>) | undefined;
334
+ protected handleBeforeExit: (() => MaybePromise<void>) | undefined;
335
+ protected handleAfterResponse: ((res: HttpResponseInterface) => MaybePromise<HttpResponseInterface>) | undefined;
336
+ setGlobalPrefix(value: string): void;
337
+ setCors(cors: CorsOptions): void;
338
+ setOnError(handler: ErrorHandler): void;
339
+ setOnNotFound(handler: RequestHandler): void;
340
+ setOnBeforeListen(handler: () => MaybePromise<void>): void;
341
+ setOnBeforeExit(handler: () => MaybePromise<void>): void;
342
+ setOnAfterResponse(handler: (res: HttpResponseInterface) => MaybePromise<HttpResponseInterface>): void;
343
+ listen(port: ServeOptions["port"], hostname?: ServeOptions["hostname"]): Promise<void>;
344
+ handle(request: Request): Promise<Response>;
345
+ private prepare;
346
+ private handleError;
347
+ private handleNotFound;
348
+ private handleMethodNotAllowed;
349
+ private handlePreflight;
350
+ private handleRoute;
351
+ private getResponse;
352
+ }
353
+ /**
354
+ * Server is the entrypoint to the app. It must be initialized before registering routes and middlewares.
355
+ * ".listen()" to start listening.
356
+ */
357
+ export declare class Server extends ServerAbstract implements ServerInterface {
358
+ constructor();
359
+ serve(options: ServeOptions): void;
360
+ exit(): Promise<void>;
361
+ private instance;
362
+ private getInstance;
363
+ }
364
+ declare abstract class CookiesAbstract implements CookiesInterface {
365
+ abstract set(opts: CookieOptions): void;
366
+ abstract get(name: string): string | null;
367
+ abstract has(name: string): boolean;
368
+ abstract delete(opts: Pick<CookieOptions, "name" | "domain" | "path">): void;
369
+ abstract entries(): IterableIterator<[
370
+ string,
371
+ string
372
+ ]>;
373
+ abstract values(): Array<string>;
374
+ abstract keys(): Array<string>;
375
+ abstract toSetCookieHeaders(): Array<string>;
376
+ applyInit(init: CookiesInit): void;
377
+ decodeValue(cookieString: string): string | null;
378
+ createHeader(opts: CookieOptions): string;
379
+ }
380
+ /** Simple cookie map/jar to collect and manipulate cookies. */
381
+ export declare class Cookies extends CookiesAbstract implements CookiesInterface {
382
+ constructor(init?: CookiesInit);
383
+ private instance;
384
+ private getInstance;
385
+ set(opts: CookieOptions): void;
386
+ get(name: string): string | null;
387
+ has(name: string): boolean;
388
+ delete(opts: Pick<CookieOptions, "name" | "path" | "domain">): void;
389
+ entries(): IterableIterator<[
390
+ string,
391
+ string
392
+ ]>;
393
+ values(): Array<string>;
394
+ keys(): Array<string>;
395
+ toSetCookieHeaders(): Array<string>;
396
+ }
397
+ /** Headers is extended to include helpers and intellisense for common header names. */
398
+ declare class HttpHeaders extends Headers implements HttpHeadersInterface {
399
+ constructor(init?: HttpHeadersInit);
400
+ append(name: HttpHeaderKey, value: string): void;
401
+ set(name: HttpHeaderKey, value: string): void;
402
+ get(name: string): string | null;
403
+ has(name: string): boolean;
404
+ combine(source: HttpHeadersInterface, target: HttpHeadersInterface): HttpHeadersInterface;
405
+ innerCombine(source: HttpHeadersInterface): HttpHeadersInterface;
406
+ setMany(init: HttpHeadersInit): void;
407
+ static findHeaderInInit(init: HttpHeadersInit, name: HttpHeaderKey): string | null;
408
+ }
409
+ interface HttpErrorInterface extends Error {
410
+ message: string;
411
+ status: Status;
412
+ data?: unknown;
413
+ }
414
+ declare class HttpError extends Error implements HttpErrorInterface {
415
+ message: string;
416
+ status: Status;
417
+ data?: unknown | undefined;
418
+ constructor(message: string, status: Status, data?: unknown | undefined);
419
+ static isStatusOf(err: unknown, status: Status): boolean;
420
+ static internalServerError(msg?: string): HttpError;
421
+ static badRequest(msg?: string): HttpError;
422
+ static notFound(msg?: string): HttpError;
423
+ static methodNotAllowed(msg?: string): HttpError;
424
+ static unprocessableEntity(msg?: string): HttpError;
425
+ }
426
+ /** HttpRequest includes a cookie jar, better headers, and some utilities. */
427
+ declare class HttpRequest extends Request implements HttpRequestInterface {
428
+ readonly input: HttpRequestInfo;
429
+ readonly init?: HttpRequestInit | undefined;
430
+ constructor(input: HttpRequestInfo, init?: HttpRequestInit | undefined);
431
+ get urlObject(): URL;
432
+ get headers(): HttpHeadersInterface;
433
+ /** Gets cookie header and collects cookies for the jar */
434
+ get cookies(): CookiesInterface;
435
+ get isPreflight(): boolean;
436
+ }
437
+ /**
438
+ * This is NOT the default response. It provides {@link HttpResponse.response}
439
+ * getter to access web Response with all mutations applied during the
440
+ * handling of the request, JSON body will be handled and cookies will be
441
+ * applied to response headers.
442
+ * */
443
+ declare class HttpResponse<R = unknown> implements HttpResponseInterface<R> {
444
+ readonly body?: HttpResponseBody<R>;
445
+ readonly init?: HttpResponseInit | undefined;
446
+ constructor(body?: HttpResponseBody<R>, init?: HttpResponseInit | undefined);
447
+ headers: HttpHeadersInterface;
448
+ status: Status;
449
+ statusText: string;
450
+ cookies: CookiesInterface;
451
+ get response(): Response;
452
+ private getCookies;
453
+ private getHeaders;
454
+ private getStatus;
455
+ private setContentType;
456
+ private getBody;
457
+ private getDefaultStatusText;
458
+ static redirect(url: string | URL, init?: HttpResponseInit): HttpResponseInterface;
459
+ static permanentRedirect(url: string | URL, init?: Omit<HttpResponseInit, "status">): HttpResponseInterface;
460
+ static temporaryRedirect(url: string | URL, init?: Omit<HttpResponseInit, "status">): HttpResponseInterface;
461
+ static seeOther(url: string | URL, init?: Omit<HttpResponseInit, "status">): HttpResponseInterface;
462
+ }
463
+ export interface ContextInterface<R = unknown, B = unknown, S = unknown, P = unknown> {
464
+ readonly req: HttpRequestInterface;
465
+ readonly url: URL;
466
+ readonly headers: HttpHeadersInterface;
467
+ readonly cookies: CookiesInterface;
468
+ body: B;
469
+ search: S;
470
+ params: P;
471
+ res: HttpResponseInterface<R>;
472
+ data: ContextDataInterface;
473
+ }
474
+ export type RouteHandler<R = unknown, B = unknown, S = unknown, P = unknown> = (context: ContextInterface<R, B, S, P>) => MaybePromise<R>;
475
+ export type RouteId = `[${string}:${string}]`;
476
+ declare const RouteVariant: {
477
+ readonly static: "static";
478
+ readonly dynamic: "dynamic";
479
+ };
480
+ export type RouteVariant = ValueOf<typeof RouteVariant>;
481
+ export interface RouteInterface<Path extends string = string, R = unknown, B = unknown, S = unknown, P = unknown> {
482
+ id: RouteId;
483
+ variant: RouteVariant;
484
+ method: Method;
485
+ endpoint: Path;
486
+ pattern: RegExp;
487
+ handler: RouteHandler<R, B, S, P>;
488
+ }
489
+ export type RouteDefinition<Path extends string = string> = {
490
+ method: Method;
491
+ path: Path;
492
+ } | Path;
493
+ declare abstract class RouteAbstract<Path extends string = string, R = unknown, B = unknown, S = unknown, P = unknown> implements RouteInterface<Path, R, B, S, P> {
494
+ abstract variant: RouteVariant;
495
+ abstract endpoint: Path;
496
+ abstract method: Method;
497
+ abstract pattern: RegExp;
498
+ abstract id: RouteId;
499
+ abstract handler: RouteHandler<R, B, S, P>;
500
+ resolveEndpoint(definition: RouteDefinition<Path>, variant: RouteVariant): Path;
501
+ resolveMethod(definition: RouteDefinition<Path>): Method;
502
+ resolvePattern(endpoint: Path): RegExp;
503
+ resolveId(method: Method, endpoint: Path): RouteId;
504
+ }
505
+ /** From https://github.com/standard-schema/standard-schema */
506
+ /** The Standard Typed interface. This is a base type extended by other specs. */
507
+ export interface StandardTypedV1<Input = unknown, Output = Input> {
508
+ /** The Standard properties. */
509
+ readonly "~standard": StandardTypedV1.Props<Input, Output>;
510
+ }
511
+ declare namespace StandardTypedV1 {
512
+ /** The Standard Typed properties interface. */
513
+ interface Props<Input = unknown, Output = Input> {
514
+ /** The version number of the standard. */
515
+ readonly version: 1;
516
+ /** The vendor name of the schema library. */
517
+ readonly vendor: string;
518
+ /** Inferred types associated with the schema. */
519
+ readonly types?: Types<Input, Output> | undefined;
520
+ }
521
+ /** The Standard Typed types interface. */
522
+ interface Types<Input = unknown, Output = Input> {
523
+ /** The input type of the schema. */
524
+ readonly input: Input;
525
+ /** The output type of the schema. */
526
+ readonly output: Output;
527
+ }
528
+ /** Infers the input type of a Standard Typed. */
529
+ type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
530
+ /** Infers the output type of a Standard Typed. */
531
+ type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
532
+ }
533
+ /** The Standard Schema interface. */
534
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
535
+ /** The Standard Schema properties. */
536
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
537
+ }
538
+ declare namespace StandardSchemaV1 {
539
+ /** The Standard Schema properties interface. */
540
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
541
+ /** Validates unknown input values. */
542
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
543
+ }
544
+ /** The result interface of the validate function. */
545
+ type Result<Output> = SuccessResult<Output> | FailureResult;
546
+ /** The result interface if validation succeeds. */
547
+ interface SuccessResult<Output> {
548
+ /** The typed output value. */
549
+ readonly value: Output;
550
+ /** A falsy value for `issues` indicates success. */
551
+ readonly issues?: undefined;
552
+ }
553
+ interface Options {
554
+ /** Explicit support for additional vendor-specific parameters, if needed. */
555
+ readonly libraryOptions?: Record<string, unknown> | undefined;
556
+ }
557
+ /** The result interface if validation fails. */
558
+ interface FailureResult {
559
+ /** The issues of failed validation. */
560
+ readonly issues: ReadonlyArray<Issue>;
561
+ }
562
+ /** The issue interface of the failure output. */
563
+ interface Issue {
564
+ /** The error message of the issue. */
565
+ readonly message: string;
566
+ /** The path of the issue, if any. */
567
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
568
+ }
569
+ /** The path segment interface of the issue. */
570
+ interface PathSegment {
571
+ /** The key representing a path segment. */
572
+ readonly key: PropertyKey;
573
+ }
574
+ /** The Standard types interface. */
575
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
576
+ }
577
+ /** Infers the input type of a Standard. */
578
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
579
+ /** Infers the output type of a Standard. */
580
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
581
+ /** ArkType-specific properties that extend the standard schema with JSON Schema support. */
582
+ interface ArkTypeProps<Input = unknown, Output = Input> extends Props<Input, Output>, StandardJSONSchemaV1.Props<Input, Output> {
583
+ vendor: "arktype";
584
+ }
585
+ }
586
+ /** The Standard JSON Schema interface. */
587
+ export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
588
+ /** The Standard JSON Schema properties. */
589
+ readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
590
+ }
591
+ declare namespace StandardJSONSchemaV1 {
592
+ /** The Standard JSON Schema properties interface. */
593
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
594
+ /** Methods for generating the input/output JSON Schema. */
595
+ readonly jsonSchema: StandardJSONSchemaV1.Converter;
596
+ }
597
+ /** The Standard JSON Schema converter interface. */
598
+ interface Converter {
599
+ /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
600
+ readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
601
+ /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
602
+ readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
603
+ }
604
+ /**
605
+ * The target version of the generated JSON Schema.
606
+ *
607
+ * It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
608
+ *
609
+ * The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
610
+ */
611
+ type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
612
+ /** The options for the input/output methods. */
613
+ interface Options {
614
+ /** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
615
+ readonly target: Target;
616
+ /** Explicit support for additional vendor-specific parameters, if needed. */
617
+ readonly libraryOptions?: Record<string, unknown> | undefined;
618
+ }
619
+ /** The Standard types interface. */
620
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
621
+ }
622
+ /** Infers the input type of a Standard. */
623
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
624
+ /** Infers the output type of a Standard. */
625
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
626
+ }
627
+ export interface Schema<T = unknown> extends StandardSchemaV1<unknown, T> {
628
+ }
629
+ export type RouteModel<R = unknown, B = unknown, S = unknown, P = unknown> = {
630
+ response?: Schema<R>;
631
+ body?: Schema<B>;
632
+ search?: Schema<S>;
633
+ params?: Schema<P>;
634
+ };
635
+ /**
636
+ * The object to define an endpoint. Can be instantiated with "new" or inside a controller
637
+ * with {@link ControllerAbstract.route}. The callback recieves the {@link Context} and can
638
+ * return {@link HttpResponse} or any data. Route instantiation automatically registers
639
+ * to the router.
640
+ * */
641
+ export declare class Route<Path extends string = string, R = unknown, B = unknown, S = unknown, P = unknown> extends RouteAbstract<Path, R, B, S, P> implements RouteInterface<Path, R, B, S, P> {
642
+ protected readonly definition: RouteDefinition<Path>;
643
+ readonly handler: RouteHandler<R, B, S, P>;
644
+ constructor(definition: RouteDefinition<Path>, handler: RouteHandler<R, B, S, P>, model?: RouteModel<R, B, S, P>);
645
+ variant: RouteVariant;
646
+ endpoint: Path;
647
+ method: Method;
648
+ pattern: RegExp;
649
+ id: RouteId;
650
+ static makeRouteId(method: string, endpoint: string): RouteId;
651
+ }
652
+ /**
653
+ * The object to define a route that serves a static file. Can be instantiated with "new" or inside a controller
654
+ * with {@link ControllerAbstract.staticRoute}. The callback recieves the {@link Context} and can
655
+ * return {@link HttpResponse} or any data. Route instantiation automatically registers
656
+ * to the router.
657
+ * */
658
+ export declare class StaticRoute<Path extends string = string> extends RouteAbstract<Path, HttpResponseInterface<string>> implements RouteInterface<Path, HttpResponseInterface<string>> {
659
+ private filePath;
660
+ constructor(path: Path, filePath: string, extension?: OrString<"html" | "css" | "js" | "ts">);
661
+ extension: string;
662
+ id: RouteId;
663
+ variant: RouteVariant;
664
+ method: Method;
665
+ endpoint: Path;
666
+ pattern: RegExp;
667
+ handler: RouteHandler<HttpResponseInterface<string>>;
668
+ private handleHtml;
669
+ private handleCss;
670
+ private handleJs;
671
+ private handleTs;
672
+ private handleFile;
673
+ private getFileName;
674
+ private getContent;
675
+ private toResponse;
676
+ private mimeTypes;
677
+ }
678
+ export interface ControllerInterface {
679
+ routeIds: Set<RouteId>;
680
+ }
681
+ export type MiddlewareHandler = (context: ContextInterface) => MaybePromise<void>;
682
+ export type ControllerOptions = {
683
+ prefix?: string;
684
+ beforeEach?: MiddlewareHandler;
685
+ };
686
+ /** Extend this class to create your own controllers. */
687
+ declare abstract class ControllerAbstract implements ControllerInterface {
688
+ constructor(opts?: ControllerOptions);
689
+ routeIds: Set<RouteId>;
690
+ protected prefix?: string;
691
+ protected beforeEach?: MiddlewareHandler;
692
+ protected route<Path extends string = string, B = unknown, R = unknown, S = unknown, P = unknown>(definition: RouteDefinition<Path>, handler: RouteHandler<B, R, S, P>, schemas?: RouteModel<B, R, S, P>): RouteInterface<Path, B, R, S, P>;
693
+ protected staticRoute<Path extends string = string>(path: Path, filePath: string, extension?: OrString<"html" | "css" | "js" | "ts">): RouteInterface<Path, HttpResponseInterface<string>>;
694
+ }
695
+ export type AnyRoute = RouteInterface<string, any, any, any, any>;
696
+ export type MiddlewareUseOn = Array<AnyRoute | ControllerInterface> | AnyRoute | ControllerInterface | "*";
697
+ export interface MiddlewareInterface {
698
+ useOn: MiddlewareUseOn;
699
+ handler: MiddlewareHandler;
700
+ }
701
+ export type MiddlewareOptions = {
702
+ useOn: MiddlewareUseOn;
703
+ handler: MiddlewareHandler;
704
+ };
705
+ /**
706
+ * Simple middleware that runs before the Route "callback" parameters.
707
+ * Manipulates context.
708
+ * */
709
+ export declare class Middleware implements MiddlewareInterface {
710
+ constructor(opts: MiddlewareOptions);
711
+ useOn: MiddlewareUseOn;
712
+ handler: MiddlewareHandler;
713
+ }
714
+ export type InferSchema<T extends Schema> = StandardSchemaV1.InferOutput<T>;
715
+ export type Prettify<T> = {
716
+ [K in keyof T]: T[K];
717
+ } & {};
718
+ /** If you prefer to put all schemas into a single object, this will be helpful */
719
+ export type InferModel<T extends Record<string, any>> = {
720
+ [K in keyof T]: T[K] extends RouteModel<any, any, any, any> ? Prettify<(T[K]["body"] extends Schema ? {
721
+ body: InferSchema<T[K]["body"]>;
722
+ } : {}) & (T[K]["response"] extends Schema ? {
723
+ response: InferSchema<T[K]["response"]>;
724
+ } : {}) & (T[K]["params"] extends Schema ? {
725
+ params: InferSchema<T[K]["params"]>;
726
+ } : {}) & (T[K]["search"] extends Schema ? {
727
+ search: InferSchema<T[K]["search"]>;
728
+ } : {})> : T[K] extends Schema ? InferSchema<T[K]> : never;
729
+ };
730
+ export interface RepositoryInterface {
731
+ readonly db: DatabaseClientInterface;
732
+ }
733
+ /** Abstract class for repository implementations */
734
+ declare abstract class RepositoryAbstract implements RepositoryInterface {
735
+ readonly db: DatabaseClientInterface;
736
+ constructor(db: DatabaseClientInterface);
737
+ }
738
+
739
+ declare namespace C {
740
+ export { CommonHeaders, Config, ControllerAbstract as Controller, ControllerInterface, Cookies, CookiesInterface, CorsOptions, HttpError as Error, HttpErrorInterface as ErrorInterface, HttpHeaders as Headers, HttpHeadersInterface as HeadersInterface, HttpRequest as Request, HttpRequestInterface as RequestInterface, HttpResponse as Response, HttpResponseInterface as ResponseInterface, InferModel, InferSchema, Method, Middleware, MiddlewareHandler, MiddlewareInterface, MiddlewareUseOn, RepositoryAbstract as Repository, Route, RouteInterface, Schema, Server, StaticRoute, Status };
741
+ }
742
+
743
+ export {
744
+ C,
745
+ C as default,
746
+ ControllerAbstract as Controller,
747
+ HttpError as Error,
748
+ HttpErrorInterface as ErrorInterface,
749
+ HttpHeaders as Headers,
750
+ HttpHeadersInterface as HeadersInterface,
751
+ HttpRequest as Request,
752
+ HttpRequestInterface as RequestInterface,
753
+ HttpResponse as Response,
754
+ HttpResponseInterface as ResponseInterface,
755
+ RepositoryAbstract as Repository,
756
+ };
757
+
758
+ export {};