alepha 0.11.4 → 0.11.5

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/server.d.ts CHANGED
@@ -1 +1,849 @@
1
- export * from '@alepha/server';
1
+ import * as _alepha_core11 from "alepha";
2
+ import { Alepha, AlephaError, Async, Descriptor, FileLike, KIND, Static, StreamLike, TArray, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
3
+ import * as _alepha_logger3 from "alepha/logger";
4
+ import { Readable } from "node:stream";
5
+ import { ReadableStream } from "node:stream/web";
6
+ import { Route, RouterProvider } from "alepha/router";
7
+ import * as _alepha_cache0 from "alepha/cache";
8
+ import { IncomingMessage, ServerResponse as ServerResponse$1 } from "node:http";
9
+ import { DateTimeProvider, DurationLike } from "alepha/datetime";
10
+ import * as typebox0 from "typebox";
11
+ import * as http0 from "http";
12
+
13
+ //#region src/constants/routeMethods.d.ts
14
+ declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
15
+ type RouteMethod = (typeof routeMethods)[number];
16
+ //#endregion
17
+ //#region src/helpers/ServerReply.d.ts
18
+ /**
19
+ * Helper for building server replies.
20
+ */
21
+ declare class ServerReply {
22
+ headers: Record<string, string> & {
23
+ "set-cookie"?: string[];
24
+ };
25
+ status?: number;
26
+ body?: any;
27
+ /**
28
+ * Redirect to a given URL with optional status code (default 302).
29
+ */
30
+ redirect(url: string, status?: number): void;
31
+ /**
32
+ * Set the response status code.
33
+ */
34
+ setStatus(status: number): this;
35
+ /**
36
+ * Set a response header.
37
+ */
38
+ setHeader(name: string, value: string): this;
39
+ /**
40
+ * Set the response body.
41
+ */
42
+ setBody(body: any): this;
43
+ }
44
+ //#endregion
45
+ //#region src/services/UserAgentParser.d.ts
46
+ interface UserAgentInfo {
47
+ os: "Windows" | "Android" | "Ubuntu" | "MacOS" | "iOS" | "Linux" | "FreeBSD" | "OpenBSD" | "ChromeOS" | "BlackBerry" | "Symbian" | "Windows Phone";
48
+ browser: "Chrome" | "Firefox" | "Safari" | "Edge" | "Opera" | "Internet Explorer" | "Brave" | "Vivaldi" | "Samsung Browser" | "UC Browser" | "Yandex";
49
+ device: "MOBILE" | "DESKTOP" | "TABLET";
50
+ }
51
+ /**
52
+ * Simple User-Agent parser to detect OS, browser, and device type.
53
+ * This parser is not exhaustive and may not cover all edge cases.
54
+ *
55
+ * Use result for non
56
+ */
57
+ declare class UserAgentParser {
58
+ parse(userAgent?: string): UserAgentInfo;
59
+ }
60
+ //#endregion
61
+ //#region src/interfaces/ServerRequest.d.ts
62
+ type TRequestBody = TObject | TString | TArray | TRecord | TStream;
63
+ type TResponseBody = TObject | TString | TRecord | TFile | TArray | TStream | TVoid;
64
+ interface RequestConfigSchema {
65
+ body?: TRequestBody;
66
+ params?: TObject;
67
+ query?: TObject;
68
+ headers?: TObject;
69
+ response?: TResponseBody;
70
+ }
71
+ interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
72
+ body: TConfig["body"] extends TRequestBody ? Static<TConfig["body"]> : any;
73
+ headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
74
+ params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
75
+ query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, any>;
76
+ }
77
+ type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
78
+ interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
79
+ method: RouteMethod;
80
+ url: URL;
81
+ requestId: string;
82
+ /**
83
+ * Client IP address.
84
+ * Will parse `X-Forwarded-For` header if present.
85
+ */
86
+ ip?: string;
87
+ /**
88
+ * Value of the `Host` header sent by the client.
89
+ */
90
+ host?: string;
91
+ /**
92
+ * Browser user agent information.
93
+ * Information are not guaranteed to be accurate. Use with caution.
94
+ *
95
+ * @see {@link UserAgentParser}
96
+ */
97
+ userAgent: UserAgentInfo;
98
+ metadata: Record<string, any>;
99
+ /**
100
+ * Reply object to be used to send response.
101
+ */
102
+ reply: ServerReply;
103
+ /**
104
+ * Raw request and response objects from platform.
105
+ * You should avoid using this property as much as possible to keep your code platform-agnostic.
106
+ */
107
+ raw: {
108
+ /**
109
+ * Node.js request and response objects.
110
+ */
111
+ node?: {
112
+ /**
113
+ * Node.js IncomingMessage object. (request)
114
+ */
115
+ req: IncomingMessage;
116
+ /**
117
+ * Node.js ServerResponse object. (response)
118
+ */
119
+ res: ServerResponse$1;
120
+ };
121
+ };
122
+ }
123
+ interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
124
+ handler: ServerHandler<TConfig>;
125
+ method?: RouteMethod;
126
+ schema?: TConfig;
127
+ /**
128
+ * @see ServerLoggerProvider
129
+ */
130
+ silent?: boolean;
131
+ }
132
+ type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TResponseBody ? Static<TConfig["response"]> : ResponseBodyType;
133
+ type ResponseKind = "json" | "text" | "void" | "file" | "any";
134
+ type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
135
+ type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
136
+ interface ServerResponse {
137
+ body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
138
+ headers: Record<string, string>;
139
+ status: number;
140
+ }
141
+ type ServerRouteRequestHandler = (request: ServerRawRequest) => Promise<ServerResponse>;
142
+ interface ServerRouteMatcher extends Route {
143
+ handler: ServerRouteRequestHandler;
144
+ }
145
+ interface ServerRawRequest {
146
+ method: RouteMethod;
147
+ url: URL;
148
+ headers: Record<string, string>;
149
+ query: Record<string, string>;
150
+ params: Record<string, string>;
151
+ raw: {
152
+ node?: {
153
+ req: IncomingMessage;
154
+ res: ServerResponse$1;
155
+ };
156
+ web?: {
157
+ req: Request;
158
+ res?: Response;
159
+ };
160
+ };
161
+ }
162
+ //#endregion
163
+ //#region src/providers/ServerProvider.d.ts
164
+ declare abstract class ServerProvider {
165
+ protected readonly alepha: Alepha;
166
+ abstract get hostname(): string;
167
+ protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
168
+ protected createRouterRequest(req: {
169
+ method?: string;
170
+ url?: string;
171
+ headers?: Record<string, string | string[] | undefined>;
172
+ }, params?: Record<string, string>): ServerRawRequest;
173
+ protected getProtocol(headers: Record<string, string>): "http" | "https";
174
+ }
175
+ //#endregion
176
+ //#region src/services/ServerRequestParser.d.ts
177
+ declare class ServerRequestParser {
178
+ protected readonly alepha: Alepha;
179
+ protected readonly userAgentParser: UserAgentParser;
180
+ createServerRequest(rawRequest: ServerRawRequest): ServerRequest;
181
+ getRequestId(request: ServerRawRequest): string | undefined;
182
+ getRequestUserAgent(request: ServerRawRequest): UserAgentInfo;
183
+ getRequestIp(request: ServerRawRequest): string | undefined;
184
+ }
185
+ //#endregion
186
+ //#region src/providers/ServerTimingProvider.d.ts
187
+ type TimingMap = Record<string, [number, number]>;
188
+ declare class ServerTimingProvider {
189
+ protected readonly log: _alepha_logger3.Logger;
190
+ protected readonly alepha: Alepha;
191
+ options: {
192
+ prefix: string;
193
+ disabled: boolean;
194
+ };
195
+ readonly onRequest: _alepha_core11.HookDescriptor<"server:onRequest">;
196
+ readonly onResponse: _alepha_core11.HookDescriptor<"server:onResponse">;
197
+ protected get handlerName(): string;
198
+ beginTiming(name: string): void;
199
+ endTiming(name: string): void;
200
+ protected setDuration(name: string, timing: TimingMap): void;
201
+ }
202
+ //#endregion
203
+ //#region src/providers/ServerRouterProvider.d.ts
204
+ /**
205
+ * Main router for all routes on the server side.
206
+ *
207
+ * - $route => generic route
208
+ * - $action => action route (for API calls)
209
+ * - $page => React route (for SSR)
210
+ */
211
+ declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
212
+ protected readonly alepha: Alepha;
213
+ protected readonly routes: ServerRoute[];
214
+ protected readonly serverTimingProvider: ServerTimingProvider;
215
+ protected readonly serverRequestParser: ServerRequestParser;
216
+ getRoutes(): ServerRoute[];
217
+ createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
218
+ protected getContextId(headers: Record<string, string>): string;
219
+ protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
220
+ status: number;
221
+ headers: Record<string, string> & {
222
+ "set-cookie"?: string[];
223
+ };
224
+ body: any;
225
+ }>;
226
+ protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
227
+ serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
228
+ protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
229
+ protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
230
+ validateRequest(route: {
231
+ schema?: RequestConfigSchema;
232
+ }, request: ServerRequestConfig): void;
233
+ }
234
+ //#endregion
235
+ //#region src/services/HttpClient.d.ts
236
+ declare class HttpClient {
237
+ protected readonly log: _alepha_logger3.Logger;
238
+ protected readonly alepha: Alepha;
239
+ readonly cache: _alepha_cache0.CacheDescriptorFn<HttpClientCache, any[]>;
240
+ protected readonly pendingRequests: HttpClientPendingRequests;
241
+ fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
242
+ fetch<T extends TSchema>(url: string, request?: RequestInitWithOptions<T>): Promise<FetchResponse<Static<T>>>;
243
+ protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
244
+ protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
245
+ protected responseData(response: Response, options: FetchOptions): Promise<any>;
246
+ protected isMaybeFile(response: Response): boolean;
247
+ protected createFileLike(response: Response, defaultFileName?: string): FileLike;
248
+ pathVariables(url: string, action: {
249
+ schema?: {
250
+ params?: TObject;
251
+ };
252
+ }, args?: ServerRequestConfigEntry): string;
253
+ queryParams(url: string, action: {
254
+ schema?: {
255
+ query?: TObject;
256
+ };
257
+ }, args?: ServerRequestConfigEntry): string;
258
+ }
259
+ interface FetchOptions<T extends TSchema = TSchema> {
260
+ /**
261
+ * Key to identify the request in the pending requests.
262
+ */
263
+ key?: string;
264
+ /**
265
+ * The schema to validate the response against.
266
+ */
267
+ schema?: {
268
+ response?: T;
269
+ };
270
+ /**
271
+ * Built-in cache options.
272
+ */
273
+ localCache?: boolean | number | DurationLike;
274
+ }
275
+ type RequestInitWithOptions<T extends TSchema = TSchema> = RequestInit & FetchOptions<T>;
276
+ interface FetchResponse<T = any> {
277
+ data: T;
278
+ status: number;
279
+ statusText: string;
280
+ headers: Headers;
281
+ raw?: Response;
282
+ }
283
+ type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
284
+ interface HttpClientCache {
285
+ data: any;
286
+ etag?: string;
287
+ }
288
+ interface FetchActionArgs {
289
+ action: HttpAction;
290
+ host?: string;
291
+ config?: ServerRequestConfigEntry;
292
+ options?: ClientRequestOptions;
293
+ }
294
+ interface HttpAction {
295
+ method?: string;
296
+ prefix?: string;
297
+ path: string;
298
+ requestBodyType?: string;
299
+ schema?: {
300
+ params?: TObject;
301
+ query?: TObject;
302
+ body?: TRequestBody;
303
+ response?: TResponseBody;
304
+ };
305
+ }
306
+ //#endregion
307
+ //#region src/descriptors/$action.d.ts
308
+ /**
309
+ * Creates a server action descriptor for defining type-safe HTTP endpoints.
310
+ *
311
+ * Server actions are the core building blocks for REST APIs in the Alepha framework. They provide
312
+ * a declarative way to define HTTP endpoints with full TypeScript type safety, automatic schema
313
+ * validation, and integrated security features. Actions automatically handle routing, request
314
+ * parsing, response serialization, and OpenAPI documentation generation.
315
+ *
316
+ * **Key Features**
317
+ *
318
+ * - **Type Safety**: Full TypeScript inference for request/response types
319
+ * - **Schema Validation**: Automatic validation using TypeBox schemas
320
+ * - **Auto-routing**: Convention-based URL generation with customizable paths
321
+ * - **Multiple Invocation**: Call directly (`run()`) or via HTTP (`fetch()`)
322
+ * - **OpenAPI Integration**: Automatic documentation generation
323
+ * - **Security Integration**: Built-in authentication and authorization support
324
+ * - **Content Type Detection**: Automatic handling of JSON, form-data, and plain text
325
+ *
326
+ * **URL Generation**
327
+ *
328
+ * By default, actions are prefixed with `/api` (configurable via `SERVER_API_PREFIX`):
329
+ * - Property name becomes the endpoint path
330
+ * - Path parameters are automatically detected from schema
331
+ * - HTTP method defaults to GET, or POST if body schema is provided
332
+ *
333
+ * **Use Cases**
334
+ *
335
+ * Perfect for building robust REST APIs:
336
+ * - CRUD operations with full type safety
337
+ * - File upload and download endpoints
338
+ * - Real-time data processing APIs
339
+ * - Integration with external services
340
+ * - Microservice communication
341
+ * - Admin and management interfaces
342
+ *
343
+ * @example
344
+ * **Basic CRUD operations:**
345
+ * ```ts
346
+ * import { $action } from "alepha/server";
347
+ * import { t } from "alepha";
348
+ *
349
+ * class UserController {
350
+ *
351
+ * getUsers = $action({
352
+ * path: "/users",
353
+ * description: "Retrieve all users with pagination",
354
+ * schema: {
355
+ * query: t.object({
356
+ * page: t.optional(t.number({ default: 1 })),
357
+ * limit: t.optional(t.number({ default: 10, maximum: 100 })),
358
+ * search: t.optional(t.text())
359
+ * }),
360
+ * response: t.object({
361
+ * users: t.array(t.object({
362
+ * id: t.text(),
363
+ * name: t.text(),
364
+ * email: t.text(),
365
+ * createdAt: t.datetime()
366
+ * })),
367
+ * total: t.number(),
368
+ * hasMore: t.boolean()
369
+ * })
370
+ * },
371
+ * handler: async ({ query }) => {
372
+ * const { page, limit, search } = query;
373
+ * const users = await this.userService.findUsers({ page, limit, search });
374
+ *
375
+ * return {
376
+ * users: users.items,
377
+ * total: users.total,
378
+ * hasMore: (page * limit) < users.total
379
+ * };
380
+ * }
381
+ * });
382
+ *
383
+ * createUser = $action({
384
+ * method: "POST",
385
+ * path: "/users",
386
+ * description: "Create a new user account",
387
+ * schema: {
388
+ * body: t.object({
389
+ * name: t.text({ minLength: 2, maxLength: 100 }),
390
+ * email: t.text({ format: "email" }),
391
+ * password: t.text({ minLength: 8 }),
392
+ * role: t.optional(t.enum(["user", "admin"]))
393
+ * }),
394
+ * response: t.object({
395
+ * id: t.text(),
396
+ * name: t.text(),
397
+ * email: t.text(),
398
+ * role: t.text(),
399
+ * createdAt: t.datetime()
400
+ * })
401
+ * },
402
+ * handler: async ({ body }) => {
403
+ * // Password validation and hashing
404
+ * await this.authService.validatePassword(body.password);
405
+ * const hashedPassword = await this.authService.hashPassword(body.password);
406
+ *
407
+ * // Create user with default role
408
+ * const user = await this.userService.create({
409
+ * ...body,
410
+ * password: hashedPassword,
411
+ * role: body.role || "user"
412
+ * });
413
+ *
414
+ * // Return user without password
415
+ * const { password, ...publicUser } = user;
416
+ * return publicUser;
417
+ * }
418
+ * });
419
+ *
420
+ * getUser = $action({
421
+ * path: "/users/:id",
422
+ * description: "Retrieve user by ID",
423
+ * schema: {
424
+ * params: t.object({
425
+ * id: t.text()
426
+ * }),
427
+ * response: t.object({
428
+ * id: t.text(),
429
+ * name: t.text(),
430
+ * email: t.text(),
431
+ * role: t.text(),
432
+ * profile: t.optional(t.object({
433
+ * bio: t.text(),
434
+ * avatar: t.text({ format: "uri" }),
435
+ * location: t.text()
436
+ * }))
437
+ * })
438
+ * },
439
+ * handler: async ({ params }) => {
440
+ * const user = await this.userService.findById(params.id);
441
+ * if (!user) {
442
+ * throw new Error(`User not found: ${params.id}`);
443
+ * }
444
+ * return user;
445
+ * }
446
+ * });
447
+ *
448
+ * updateUser = $action({
449
+ * method: "PUT",
450
+ * path: "/users/:id",
451
+ * description: "Update user information",
452
+ * schema: {
453
+ * params: t.object({ id: t.text() }),
454
+ * body: t.object({
455
+ * name: t.optional(t.text({ minLength: 2 })),
456
+ * email: t.optional(t.text({ format: "email" })),
457
+ * profile: t.optional(t.object({
458
+ * bio: t.optional(t.text()),
459
+ * avatar: t.optional(t.text({ format: "uri" })),
460
+ * location: t.optional(t.text())
461
+ * }))
462
+ * }),
463
+ * response: t.object({
464
+ * id: t.text(),
465
+ * name: t.text(),
466
+ * email: t.text(),
467
+ * updatedAt: t.datetime()
468
+ * })
469
+ * },
470
+ * handler: async ({ params, body }) => {
471
+ * const updatedUser = await this.userService.update(params.id, body);
472
+ * return updatedUser;
473
+ * }
474
+ * });
475
+ * }
476
+ * ```
477
+ *
478
+ * **Important Notes**:
479
+ * - Actions are automatically registered with the HTTP server when the service is initialized
480
+ * - Use `run()` for direct invocation (testing, internal calls, or remote services)
481
+ * - Use `fetch()` for explicit HTTP requests (client-side, external services)
482
+ * - Schema validation occurs automatically for all requests and responses
483
+ * - Path parameters are automatically extracted from schema definitions
484
+ * - Content-Type headers are automatically set based on schema types
485
+ */
486
+ declare const $action: {
487
+ <TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptorFn<TConfig>;
488
+ [KIND]: typeof ActionDescriptor;
489
+ };
490
+ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
491
+ /**
492
+ * Name of the action.
493
+ *
494
+ * - It will be used to generate the route path if `path` is not provided.
495
+ * - It will be used to generate the permission name if `security` is enabled.
496
+ */
497
+ name?: string;
498
+ /**
499
+ * Group actions together.
500
+ *
501
+ * - If not provided, the service name containing the route will be used.
502
+ * - It will be used as Tag for documentation purposes.
503
+ * - It will be used for permission name generation if `security` is enabled.
504
+ *
505
+ * @example
506
+ * ```ts
507
+ * // group = "MyController"
508
+ * class MyController {
509
+ * hello = $action({ handler: () => "Hello World" });
510
+ * }
511
+ *
512
+ * // group = "users"
513
+ * class MyOtherController {
514
+ * group = "users";
515
+ * a1 = $action({ handler: () => "Action 1", group: this.group });
516
+ * a2 = $action({ handler: () => "Action 2", group: this.group });
517
+ * }
518
+ * ```
519
+ */
520
+ group?: string;
521
+ /**
522
+ * Pathname of the route. If not provided, property key is used.
523
+ */
524
+ path?: string;
525
+ /**
526
+ * The route method.
527
+ *
528
+ * - If not provided, it will be set to "GET" by default.
529
+ * - If not provider and a body is provided, it will be set to "POST".
530
+ *
531
+ * Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
532
+ */
533
+ method?: RouteMethod;
534
+ /**
535
+ * The config schema of the route.
536
+ * - body: The request body schema.
537
+ * - params: Path variables schema.
538
+ * - query: The request query-params schema.
539
+ * - response: The response schema.
540
+ */
541
+ schema?: TConfig;
542
+ /**
543
+ * A short description of the action. Used for documentation purposes.
544
+ */
545
+ description?: string;
546
+ /**
547
+ * Disable the route. Useful with env variables do disable one specific route.
548
+ * Route won't be available in the API but can still be called locally!
549
+ */
550
+ disabled?: boolean;
551
+ /**
552
+ * Main route handler. This is where the route logic is implemented.
553
+ */
554
+ handler: ServerActionHandler<TConfig>;
555
+ }
556
+ declare class ActionDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<ActionDescriptorOptions<TConfig>> {
557
+ protected readonly log: _alepha_logger3.Logger;
558
+ protected readonly env: {
559
+ SERVER_API_PREFIX: string;
560
+ };
561
+ protected readonly httpClient: HttpClient;
562
+ protected readonly serverProvider: ServerProvider;
563
+ protected readonly serverRouterProvider: ServerRouterProvider;
564
+ protected onInit(): void;
565
+ get prefix(): string;
566
+ get route(): ServerRoute;
567
+ /**
568
+ * Returns the name of the action.
569
+ */
570
+ get name(): string;
571
+ /**
572
+ * Returns the group of the action. (e.g. "orders", "admin", etc.)
573
+ */
574
+ get group(): string;
575
+ /**
576
+ * Returns the HTTP method of the action.
577
+ */
578
+ get method(): RouteMethod;
579
+ /**
580
+ * Returns the path of the action.
581
+ *
582
+ * Path is prefixed by `/api` by default.
583
+ */
584
+ get path(): string;
585
+ get schema(): TConfig | undefined;
586
+ getBodyContentType(): string | undefined;
587
+ /**
588
+ * Call the action handler directly.
589
+ * There is no HTTP layer involved.
590
+ */
591
+ run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
592
+ /**
593
+ * Works like `run`, but always fetches (http request) the route.
594
+ */
595
+ fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
596
+ }
597
+ interface ActionDescriptorFn<TConfig extends RequestConfigSchema> extends ActionDescriptor<TConfig> {
598
+ (config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
599
+ }
600
+ type ClientRequestEntry<TConfig extends RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
601
+ type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
602
+ body: TConfig["body"] extends TObject ? Static<TConfig["body"]> : undefined;
603
+ params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : undefined;
604
+ headers?: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : undefined;
605
+ query?: TConfig["query"] extends TObject ? Partial<Static<TConfig["query"]>> : undefined;
606
+ };
607
+ interface ClientRequestOptions extends FetchOptions {
608
+ /**
609
+ * Standard request fetch options.
610
+ */
611
+ request?: RequestInit;
612
+ }
613
+ type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
614
+ /**
615
+ * Specific handler for server actions.
616
+ */
617
+ type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
618
+ /**
619
+ * Server Action Request Interface
620
+ *
621
+ * Can be extended with module augmentation to add custom properties (like `user` in Server Security).
622
+ *
623
+ * This is NOT Server Request, but a specific type for actions.
624
+ */
625
+ interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
626
+ //#endregion
627
+ //#region src/schemas/errorSchema.d.ts
628
+ declare const errorSchema: typebox0.TObject<{
629
+ error: typebox0.TString;
630
+ status: typebox0.TInteger;
631
+ message: typebox0.TString;
632
+ details: typebox0.TOptional<typebox0.TString>;
633
+ requestId: typebox0.TOptional<typebox0.TString>;
634
+ cause: typebox0.TOptional<typebox0.TObject<{
635
+ name: typebox0.TString;
636
+ message: typebox0.TString;
637
+ }>>;
638
+ }>;
639
+ type ErrorSchema = Static<typeof errorSchema>;
640
+ //#endregion
641
+ //#region src/errors/HttpError.d.ts
642
+ declare const isHttpError: (error: unknown, status?: number) => error is HttpErrorLike;
643
+ declare class HttpError extends AlephaError {
644
+ name: string;
645
+ static is: (error: unknown, status?: number) => error is HttpErrorLike;
646
+ static toJSON(error: HttpError): ErrorSchema;
647
+ readonly error: string;
648
+ readonly status: number;
649
+ readonly requestId?: string;
650
+ readonly details?: string;
651
+ readonly reason?: {
652
+ name: string;
653
+ message: string;
654
+ };
655
+ constructor(options: Partial<ErrorSchema>, cause?: unknown);
656
+ }
657
+ declare const errorNameByStatus: Record<number, string>;
658
+ interface HttpErrorLike extends Error {
659
+ status: number;
660
+ }
661
+ //#endregion
662
+ //#region src/descriptors/$route.d.ts
663
+ /**
664
+ * Create a basic endpoint.
665
+ *
666
+ * It's a low level descriptor. You probably want to use `$action` instead.
667
+ *
668
+ * @see {@link $action}
669
+ * @see {@link $page}
670
+ */
671
+ declare const $route: {
672
+ <TConfig extends RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
673
+ [KIND]: typeof RouteDescriptor;
674
+ };
675
+ interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {}
676
+ declare class RouteDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<RouteDescriptorOptions<TConfig>> {
677
+ protected readonly serverRouterProvider: ServerRouterProvider;
678
+ protected onInit(): void;
679
+ }
680
+ //#endregion
681
+ //#region src/errors/BadRequestError.d.ts
682
+ declare class BadRequestError extends HttpError {
683
+ constructor(message?: string, cause?: unknown);
684
+ }
685
+ //#endregion
686
+ //#region src/errors/ConflictError.d.ts
687
+ declare class ConflictError extends HttpError {
688
+ constructor(message?: string, cause?: unknown);
689
+ }
690
+ //#endregion
691
+ //#region src/errors/ForbiddenError.d.ts
692
+ declare class ForbiddenError extends HttpError {
693
+ constructor(message?: string, cause?: unknown);
694
+ }
695
+ //#endregion
696
+ //#region src/errors/NotFoundError.d.ts
697
+ declare class NotFoundError extends HttpError {
698
+ constructor(message?: string, cause?: unknown);
699
+ }
700
+ //#endregion
701
+ //#region src/errors/UnauthorizedError.d.ts
702
+ declare class UnauthorizedError extends HttpError {
703
+ constructor(message?: string, cause?: unknown);
704
+ }
705
+ //#endregion
706
+ //#region src/errors/ValidationError.d.ts
707
+ declare class ValidationError extends HttpError {
708
+ constructor(message?: string, cause?: unknown);
709
+ }
710
+ //#endregion
711
+ //#region src/helpers/isMultipart.d.ts
712
+ /**
713
+ * Checks if the route has multipart/form-data request body.
714
+ */
715
+ declare const isMultipart: (options: {
716
+ schema?: RequestConfigSchema;
717
+ requestBodyType?: string;
718
+ }) => boolean;
719
+ //#endregion
720
+ //#region src/schemas/okSchema.d.ts
721
+ declare const okSchema: typebox0.TObject<{
722
+ ok: typebox0.TBoolean;
723
+ id: typebox0.TOptional<typebox0.TUnion<[typebox0.TString, typebox0.TInteger]>>;
724
+ count: typebox0.TOptional<typebox0.TNumber>;
725
+ }>;
726
+ type Ok = Static<typeof okSchema>;
727
+ //#endregion
728
+ //#region src/providers/NodeHttpServerProvider.d.ts
729
+ declare const envSchema: _alepha_core11.TObject<{
730
+ SERVER_PORT: _alepha_core11.TInteger;
731
+ SERVER_HOST: _alepha_core11.TString;
732
+ }>;
733
+ declare module "alepha" {
734
+ interface Env extends Partial<Static<typeof envSchema>> {}
735
+ }
736
+ declare class NodeHttpServerProvider extends ServerProvider {
737
+ protected readonly alepha: Alepha;
738
+ protected readonly dateTimeProvider: DateTimeProvider;
739
+ protected readonly log: _alepha_logger3.Logger;
740
+ protected readonly env: {
741
+ SERVER_PORT: number;
742
+ SERVER_HOST: string;
743
+ };
744
+ protected readonly router: ServerRouterProvider;
745
+ protected readonly server: http0.Server<typeof IncomingMessage, typeof ServerResponse$1>;
746
+ protected readonly onNodeRequest: _alepha_core11.HookDescriptor<"node:request">;
747
+ handle(req: IncomingMessage, res: ServerResponse$1): Promise<void>;
748
+ get hostname(): string;
749
+ readonly start: _alepha_core11.HookDescriptor<"start">;
750
+ protected readonly stop: _alepha_core11.HookDescriptor<"stop">;
751
+ protected listen(): Promise<void>;
752
+ protected close(): Promise<void>;
753
+ }
754
+ //#endregion
755
+ //#region src/providers/ServerLoggerProvider.d.ts
756
+ declare class ServerLoggerProvider {
757
+ protected readonly log: _alepha_logger3.Logger;
758
+ protected readonly alepha: Alepha;
759
+ readonly onRequest: _alepha_core11.HookDescriptor<"server:onRequest">;
760
+ readonly onError: _alepha_core11.HookDescriptor<"server:onError">;
761
+ readonly onResponse: _alepha_core11.HookDescriptor<"server:onResponse">;
762
+ }
763
+ //#endregion
764
+ //#region src/providers/ServerNotReadyProvider.d.ts
765
+ /**
766
+ * On every request, this provider checks if the server is ready.
767
+ *
768
+ * If the server is not ready, it responds with a 503 status code and a message indicating that the server is not ready yet.
769
+ *
770
+ * The response also includes a `Retry-After` header indicating that the client should retry after 5 seconds.
771
+ */
772
+ declare class ServerNotReadyProvider {
773
+ protected readonly alepha: Alepha;
774
+ readonly onRequest: _alepha_core11.HookDescriptor<"server:onRequest">;
775
+ }
776
+ //#endregion
777
+ //#region src/index.d.ts
778
+ declare module "alepha" {
779
+ interface Hooks {
780
+ "action:onRequest": {
781
+ action: ActionDescriptor<RequestConfigSchema>;
782
+ request: ServerRequest;
783
+ options: ClientRequestOptions;
784
+ };
785
+ "action:onResponse": {
786
+ action: ActionDescriptor<RequestConfigSchema>;
787
+ request: ServerRequest;
788
+ options: ClientRequestOptions;
789
+ response: any;
790
+ };
791
+ "server:onRequest": {
792
+ route: ServerRoute;
793
+ request: ServerRequest;
794
+ };
795
+ "server:onError": {
796
+ route: ServerRoute;
797
+ request: ServerRequest;
798
+ error: Error;
799
+ };
800
+ "server:onSend": {
801
+ route: ServerRoute;
802
+ request: ServerRequest;
803
+ };
804
+ "server:onResponse": {
805
+ route: ServerRoute;
806
+ request: ServerRequest;
807
+ response: ServerResponse;
808
+ };
809
+ "client:onRequest": {
810
+ route: HttpAction;
811
+ config: ServerRequestConfigEntry;
812
+ options: ClientRequestOptions;
813
+ headers: Record<string, string>;
814
+ request: RequestInit;
815
+ };
816
+ "client:beforeFetch": {
817
+ url: string;
818
+ options: FetchOptions;
819
+ request: RequestInit;
820
+ };
821
+ "client:onError": {
822
+ route?: HttpAction;
823
+ error: HttpError;
824
+ };
825
+ "node:request": {
826
+ req: IncomingMessage;
827
+ res: ServerResponse$1;
828
+ };
829
+ "web:request": {
830
+ req: Request;
831
+ res?: Response;
832
+ };
833
+ }
834
+ }
835
+ /**
836
+ * Provides high-performance HTTP server capabilities with declarative routing and action descriptors.
837
+ *
838
+ * The server module enables building REST APIs and web applications using `$route` and `$action` descriptors
839
+ * on class properties. It provides automatic request/response handling, schema validation, middleware support,
840
+ * and seamless integration with other Alepha modules for a complete backend solution.
841
+ *
842
+ * @see {@link $route}
843
+ * @see {@link $action}
844
+ * @module alepha.server
845
+ */
846
+ declare const AlephaServer: _alepha_core11.Service<_alepha_core11.Module<{}>>;
847
+ //#endregion
848
+ export { $action, $route, ActionDescriptor, ActionDescriptorFn, ActionDescriptorOptions, AlephaServer, BadRequestError, ClientRequestEntry, ClientRequestEntryContainer, ClientRequestOptions, ClientRequestResponse, ConflictError, ErrorSchema, FetchActionArgs, FetchOptions, FetchResponse, ForbiddenError, HttpAction, HttpClient, HttpClientPendingRequests, HttpError, HttpErrorLike, NodeHttpServerProvider, NotFoundError, Ok, RequestConfigSchema, RequestInitWithOptions, ResponseBodyType, ResponseKind, RouteDescriptor, RouteDescriptorOptions, RouteMethod, ServerActionHandler, ServerActionRequest, ServerHandler, ServerLoggerProvider, ServerNotReadyProvider, ServerProvider, ServerRawRequest, ServerReply, ServerRequest, ServerRequestConfig, ServerRequestConfigEntry, ServerResponse, ServerResponseBody, ServerRoute, ServerRouteMatcher, ServerRouteRequestHandler, ServerRouterProvider, ServerTimingProvider, TRequestBody, TResponseBody, UnauthorizedError, ValidationError, errorNameByStatus, errorSchema, isHttpError, isMultipart, okSchema, routeMethods };
849
+ //# sourceMappingURL=index.d.ts.map