alepha 0.8.1 → 0.9.1

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,22 +1,21 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import * as _alepha_core3 from "alepha";
3
- import * as _alepha_core7 from "alepha";
4
- import * as _alepha_core8 from "alepha";
5
- import * as _alepha_core12 from "alepha";
6
- import * as _alepha_core15 from "alepha";
7
- import * as _alepha_core24 from "alepha";
8
- import { Alepha, Async, FileLike, KIND, Module, OPTIONS, Static, StreamLike, TObject, TSchema } from "alepha";
9
- import { JwtProvider, Permission, SecurityProvider, ServiceAccountDescriptor, UserAccountToken } from "alepha/security";
10
- import * as _alepha_cache2 from "alepha/cache";
2
+ import * as _alepha_core0$1 from "alepha";
3
+ import * as _alepha_core2 from "alepha";
4
+ import * as _alepha_core9 from "alepha";
5
+ import * as _alepha_core13 from "alepha";
6
+ import * as _alepha_core14 from "alepha";
7
+ import * as _alepha_core0 from "alepha";
8
+ import { Alepha, Async, Descriptor, FileLike, KIND, Static, StreamLike, TObject, TSchema } from "alepha";
11
9
  import { Readable } from "node:stream";
12
10
  import { ReadableStream } from "node:stream/web";
13
11
  import { Route, RouterProvider } from "alepha/router";
12
+ import * as _alepha_cache0 from "alepha/cache";
14
13
  import { IncomingMessage, ServerResponse as ServerResponse$1 } from "node:http";
15
- import { DurationLike } from "alepha/datetime";
16
- import * as _sinclair_typebox38 from "@sinclair/typebox";
17
- import * as _sinclair_typebox64 from "@sinclair/typebox";
18
- import * as _sinclair_typebox30 from "@sinclair/typebox";
19
- import * as http20 from "http";
14
+ import { DateTimeProvider, DurationLike } from "alepha/datetime";
15
+ import * as _sinclair_typebox0 from "@sinclair/typebox";
16
+ import * as _sinclair_typebox33 from "@sinclair/typebox";
17
+ import * as _sinclair_typebox25 from "@sinclair/typebox";
18
+ import * as http0 from "http";
20
19
 
21
20
  //#region src/constants/routeMethods.d.ts
22
21
  declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
@@ -36,7 +35,7 @@ declare class ServerReply {
36
35
  }
37
36
  //# sourceMappingURL=ServerReply.d.ts.map
38
37
  //#endregion
39
- //#region src/interfaces/index.d.ts
38
+ //#region src/interfaces/ServerRequest.d.ts
40
39
  interface RequestConfigSchema {
41
40
  body?: TSchema;
42
41
  params?: TObject;
@@ -62,20 +61,15 @@ interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchem
62
61
  res: ServerResponse$1;
63
62
  };
64
63
  };
65
- user: UserAccountToken;
66
64
  }
67
65
  interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
68
- method?: RouteMethod;
69
66
  handler: ServerHandler<TConfig>;
67
+ method?: RouteMethod;
70
68
  schema?: TConfig;
71
69
  /**
72
70
  * @see ServerLoggerProvider
73
71
  */
74
72
  silent?: boolean;
75
- /**
76
- * @see ServerSecurityProvider
77
- */
78
- secure?: ServerRouteSecure;
79
73
  }
80
74
  type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : ResponseBodyType;
81
75
  type ResponseKind = "json" | "text" | "void" | "file" | "any";
@@ -87,7 +81,7 @@ interface ServerResponse {
87
81
  headers: Record<string, string>;
88
82
  status: number;
89
83
  }
90
- interface ServerRouteWithHandler extends Route {
84
+ interface ServerRouteMatcher extends Route {
91
85
  handler: (request: ServerRawRequest) => Promise<ServerResponse>;
92
86
  }
93
87
  interface ServerRawRequest {
@@ -103,39 +97,53 @@ interface ServerRawRequest {
103
97
  };
104
98
  };
105
99
  }
106
- type ServerRouteSecure = boolean | {
107
- permissions?: string[];
108
- roles?: string[];
109
- realms?: string[];
110
- organizations?: string[];
111
- };
112
- //# sourceMappingURL=index.d.ts.map
100
+ //# sourceMappingURL=ServerRequest.d.ts.map
101
+ //#endregion
102
+ //#region src/providers/ServerProvider.d.ts
103
+ declare abstract class ServerProvider {
104
+ protected readonly alepha: Alepha;
105
+ abstract get hostname(): string;
106
+ protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
107
+ }
108
+ //# sourceMappingURL=ServerProvider.d.ts.map
109
+
113
110
  //#endregion
114
- //#region src/helpers/ActionDescriptorHelper.d.ts
115
- declare class ActionDescriptorHelper {
116
- name(options: ActionDescriptorOptions, instance: any, key: string): string;
117
- path(options: ActionDescriptorOptions, _instance: any, key: string): string;
118
- method(options: {
119
- method?: string;
120
- schema?: any;
121
- }): RouteMethod;
122
- permission(options: ActionDescriptorOptions, instance: any, key: string): Permission;
123
- group(options: ActionDescriptorOptions, instance: any): string;
124
- isMultipart(options: {
111
+ //#region src/providers/ServerRouterProvider.d.ts
112
+ /**
113
+ * Main router for all routes on the server side.
114
+ *
115
+ * - $route => generic route
116
+ * - $action => action route (for API calls)
117
+ * - $page => React route (for SSR)
118
+ */
119
+ declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
120
+ protected readonly alepha: Alepha;
121
+ protected readonly routes: ServerRoute[];
122
+ getRoutes(): ServerRoute[];
123
+ createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
124
+ onRequest(route: ServerRoute, rawRequest: ServerRawRequest, responseKind: ResponseKind): Promise<ServerResponse>;
125
+ protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
126
+ status: number;
127
+ headers: Record<string, string> & {
128
+ "set-cookie"?: string[];
129
+ };
130
+ body: any;
131
+ }>;
132
+ protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
133
+ protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
134
+ protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
135
+ validateRequest(route: {
125
136
  schema?: RequestConfigSchema;
126
- }): boolean;
127
- bodyContentType(options: ActionDescriptorOptions): string | undefined;
128
- protected short(name: string): string;
129
- fetchLinks(_url: string): void;
137
+ }, request: ServerRequestConfig): void;
138
+ serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
130
139
  }
131
- //# sourceMappingURL=ActionDescriptorHelper.d.ts.map
140
+ //# sourceMappingURL=ServerRouterProvider.d.ts.map
132
141
  //#endregion
133
142
  //#region src/services/HttpClient.d.ts
134
143
  declare class HttpClient {
135
144
  protected readonly log: _alepha_core1.Logger;
136
145
  protected readonly alepha: Alepha;
137
- protected readonly helper: ActionDescriptorHelper;
138
- readonly cache: _alepha_cache2.CacheDescriptor<HttpClientCache, any[]>;
146
+ readonly cache: _alepha_cache0.CacheDescriptorFn<HttpClientCache, any[]>;
139
147
  protected readonly pendingRequests: HttpClientPendingRequests;
140
148
  clear(): Promise<void>;
141
149
  fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
@@ -204,43 +212,69 @@ interface HttpAction {
204
212
  }
205
213
  //#endregion
206
214
  //#region src/descriptors/$action.d.ts
207
- declare const KEY$1 = "ACTION";
215
+ /**
216
+ * Create an action endpoint.
217
+ *
218
+ * By default, all actions are prefixed by `/api`.
219
+ * If `name` is not provided, the action will be named after the property key.
220
+ * If `path` is not provided, the action will be named after the function name.
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * class MyController {
225
+ * hello = $action({
226
+ * handler: () => "Hello World",
227
+ * })
228
+ * }
229
+ * // GET /api/hello -> "Hello World"
230
+ * ```
231
+ */
208
232
  declare const $action: {
209
233
  <TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptor<TConfig>;
210
- [KIND]: string;
234
+ [KIND]: typeof ActionDescriptor;
211
235
  };
212
- interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema"> {
236
+ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
213
237
  /**
214
- * Name the route.
238
+ * Name of the action.
239
+ *
240
+ * - It will be used to generate the route path if `path` is not provided.
241
+ * - It will be used to generate the permission name if `security` is enabled.
215
242
  */
216
243
  name?: string;
217
244
  /**
218
- * Namespace of the route, used for grouping.
245
+ * Group actions together.
219
246
  *
220
- * @default Class name containing the route.
221
- */
222
- group?: string;
223
- /**
224
- * If false, disabled the security check for this route.
247
+ * - If not provided, the service name containing the route will be used.
248
+ * - It will be used as Tag for documentation purposes.
249
+ * - It will be used for permission name generation if `security` is enabled.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * // group = "MyController"
254
+ * class MyController {
255
+ * hello = $action({ handler: () => "Hello World" });
256
+ * }
225
257
  *
226
- * @default true when SecurityModule is enabled, false otherwise.
227
- * @deprecated
258
+ * // group = "users"
259
+ * class MyOtherController {
260
+ * group = "users";
261
+ * a1 = $action({ handler: () => "Action 1", group: this.group });
262
+ * a2 = $action({ handler: () => "Action 2", group: this.group });
263
+ * }
264
+ * ```
228
265
  */
229
- security?: boolean;
266
+ group?: string;
230
267
  /**
231
- * Pathname of the route.
268
+ * Pathname of the route. If not provided, property key is used.
232
269
  */
233
270
  path?: string;
234
- /**
235
- * Inherit options from another route.
236
- */
237
- use?: {
238
- [OPTIONS]: ActionDescriptorOptions<TConfig>;
239
- };
240
271
  /**
241
272
  * The route method.
242
273
  *
243
- * @default "GET" or "POST" when schema body is defined.
274
+ * - If not provided, it will be set to "GET" by default.
275
+ * - If not provider and a body is provided, it will be set to "POST".
276
+ *
277
+ * Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
244
278
  */
245
279
  method?: RouteMethod;
246
280
  /**
@@ -252,66 +286,87 @@ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestC
252
286
  */
253
287
  schema?: TConfig;
254
288
  /**
255
- * Short description of the route.
256
- */
257
- summary?: string;
258
- /**
259
- * Long description of the route.
289
+ * A short description of the action. Used for documentation purposes.
260
290
  */
261
291
  description?: string;
262
292
  /**
263
293
  * Disable the route. Useful with env variables do disable one specific route.
294
+ * Route won't be available in the API but can still be called locally!
264
295
  */
265
296
  disabled?: boolean;
266
- /**
267
- * Mark the route as private.
268
- * - It won't be exposed in the API documentation.
269
- * - It won't be exposed in _links.
270
- */
271
- internal?: boolean;
272
297
  /**
273
298
  * Main route handler. This is where the route logic is implemented.
274
299
  */
275
- handler?: ServerHandler<TConfig>;
300
+ handler: ServerActionHandler<TConfig>;
276
301
  }
277
- interface ActionDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> {
278
- [KIND]: typeof KEY$1;
279
- [OPTIONS]: ActionDescriptorOptions<TConfig>;
302
+ declare class ActionDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<ActionDescriptorOptions<TConfig>> {
303
+ protected readonly log: _alepha_core0$1.Logger;
304
+ protected readonly env: {
305
+ SERVER_API_PREFIX: string;
306
+ };
307
+ protected readonly httpClient: HttpClient;
308
+ protected readonly serverProvider: ServerProvider;
309
+ protected readonly serverRouterProvider: ServerRouterProvider;
310
+ protected onInit(): void;
311
+ get prefix(): string;
312
+ get route(): ServerRoute;
313
+ /**
314
+ * Returns the name of the action.
315
+ */
316
+ get name(): string;
280
317
  /**
281
- * Fetch or just call local route when available.
318
+ * Returns the group of the action. (e.g. "orders", "admin", etc.)
282
319
  */
283
- (config?: ClientRequestEntry<TConfig>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
320
+ get group(): string;
284
321
  /**
285
- * Just fetch the route. Skip any local route.
322
+ * Returns the HTTP method of the action.
323
+ */
324
+ get method(): RouteMethod;
325
+ /**
326
+ * Returns the path of the action.
327
+ *
328
+ * Path is prefixed by `/api` by default.
286
329
  */
287
- fetch: (config?: ClientRequestEntry<TConfig>, opts?: ClientRequestOptions) => Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
330
+ get path(): string;
331
+ get schema(): TConfig | undefined;
332
+ getBodyContentType(): string | undefined;
288
333
  /**
289
- * Name of the permission required to access this route.
334
+ * Call the action handler directly.
335
+ * There is no HTTP layer involved.
290
336
  */
291
- permission: () => string;
337
+ run(config: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
338
+ /**
339
+ * Works like `run`, but always fetches (http request) the route.
340
+ */
341
+ fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
292
342
  }
293
- type ClientRequestEntry<TConfig extends RequestConfigSchema = RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
294
- type ClientRequestEntryContainer<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
343
+ type ClientRequestEntry<TConfig extends RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
344
+ type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
295
345
  body: TConfig["body"] extends TSchema ? Static<TConfig["body"]> : undefined;
296
346
  params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : undefined;
297
347
  headers?: TConfig["headers"] extends TSchema ? Static<TConfig["headers"]> : undefined;
298
348
  query?: TConfig["query"] extends TSchema ? Partial<Static<TConfig["query"]>> : undefined;
299
349
  };
300
350
  interface ClientRequestOptions extends FetchOptions {
301
- /**
302
- * Forward user from the previous request.
303
- * If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
304
- * If "context", use the user from the current context (e.g. request).
305
- *
306
- * @default "system" is provided, else "context" is used.
307
- */
308
- user?: UserAccountToken | "system" | "context";
309
351
  /**
310
352
  * Standard request fetch options.
311
353
  */
312
354
  request?: RequestInit;
313
355
  }
314
356
  type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
357
+ /**
358
+ * Specific handler for server actions.
359
+ */
360
+ type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
361
+ /**
362
+ * Server Action Request Interface
363
+ *
364
+ * Can be extended with module augmentation to add custom properties (like `user` in Server Security).
365
+ *
366
+ * This is NOT Server Request, but a specific type for actions.
367
+ */
368
+ interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
369
+ //# sourceMappingURL=$action.d.ts.map
315
370
  //#endregion
316
371
  //#region src/errors/HttpError.d.ts
317
372
  declare class HttpError extends Error {
@@ -353,16 +408,24 @@ interface HttpErrorLike extends Error {
353
408
  //# sourceMappingURL=HttpError.d.ts.map
354
409
  //#endregion
355
410
  //#region src/descriptors/$route.d.ts
356
- declare const KEY = "ROUTE";
411
+ /**
412
+ * Create a basic endpoint.
413
+ *
414
+ * It's a low level descriptor. You probably want to use `$action` instead.
415
+ *
416
+ * @see {@link $action}
417
+ * @see {@link $page}
418
+ */
357
419
  declare const $route: {
358
- <TConfig extends RequestConfigSchema = RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
359
- [KIND]: string;
420
+ <TConfig extends RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
421
+ [KIND]: typeof RouteDescriptor;
360
422
  };
361
423
  interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {}
362
- type RouteDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
363
- [KIND]: typeof KEY;
364
- [OPTIONS]: RouteDescriptorOptions<TConfig>;
365
- };
424
+ declare class RouteDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<RouteDescriptorOptions<TConfig>> {
425
+ protected readonly serverRouterProvider: ServerRouterProvider;
426
+ protected onInit(): void;
427
+ }
428
+ //# sourceMappingURL=$route.d.ts.map
366
429
  //#endregion
367
430
  //#region src/errors/BadRequestError.d.ts
368
431
  declare class BadRequestError extends HttpError {
@@ -400,24 +463,30 @@ declare class ValidationError extends HttpError {
400
463
  }
401
464
  //# sourceMappingURL=ValidationError.d.ts.map
402
465
  //#endregion
466
+ //#region src/helpers/isMultipart.d.ts
467
+ declare const isMultipart: (options: {
468
+ schema?: RequestConfigSchema;
469
+ }) => boolean;
470
+ //# sourceMappingURL=isMultipart.d.ts.map
471
+ //#endregion
403
472
  //#region src/schemas/apiLinksResponseSchema.d.ts
404
- declare const apiLinkSchema: _sinclair_typebox38.TObject<{
405
- name: _sinclair_typebox38.TString;
406
- path: _sinclair_typebox38.TString;
407
- method: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
408
- group: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
409
- requestBodyType: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
410
- service: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
473
+ declare const apiLinkSchema: _sinclair_typebox0.TObject<{
474
+ name: _sinclair_typebox0.TString;
475
+ path: _sinclair_typebox0.TString;
476
+ method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
477
+ group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
478
+ requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
479
+ service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
411
480
  }>;
412
- declare const apiLinksResponseSchema: _sinclair_typebox38.TObject<{
413
- prefix: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
414
- links: _sinclair_typebox38.TArray<_sinclair_typebox38.TObject<{
415
- name: _sinclair_typebox38.TString;
416
- path: _sinclair_typebox38.TString;
417
- method: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
418
- group: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
419
- requestBodyType: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
420
- service: _sinclair_typebox38.TOptional<_sinclair_typebox38.TString>;
481
+ declare const apiLinksResponseSchema: _sinclair_typebox0.TObject<{
482
+ prefix: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
483
+ links: _sinclair_typebox0.TArray<_sinclair_typebox0.TObject<{
484
+ name: _sinclair_typebox0.TString;
485
+ path: _sinclair_typebox0.TString;
486
+ method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
487
+ group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
488
+ requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
489
+ service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
421
490
  }>>;
422
491
  }>;
423
492
  type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
@@ -425,38 +494,67 @@ type ApiLink = Static<typeof apiLinkSchema>;
425
494
  //# sourceMappingURL=apiLinksResponseSchema.d.ts.map
426
495
  //#endregion
427
496
  //#region src/schemas/errorSchema.d.ts
428
- declare const errorSchema: _sinclair_typebox64.TObject<{
429
- error: _sinclair_typebox64.TString;
430
- status: _sinclair_typebox64.TNumber;
431
- message: _sinclair_typebox64.TString;
432
- details: _sinclair_typebox64.TOptional<_sinclair_typebox64.TString>;
433
- cause: _sinclair_typebox64.TOptional<_sinclair_typebox64.TObject<{
434
- name: _sinclair_typebox64.TString;
435
- message: _sinclair_typebox64.TString;
497
+ declare const errorSchema: _sinclair_typebox33.TObject<{
498
+ error: _sinclair_typebox33.TString;
499
+ status: _sinclair_typebox33.TNumber;
500
+ message: _sinclair_typebox33.TString;
501
+ details: _sinclair_typebox33.TOptional<_sinclair_typebox33.TString>;
502
+ cause: _sinclair_typebox33.TOptional<_sinclair_typebox33.TObject<{
503
+ name: _sinclair_typebox33.TString;
504
+ message: _sinclair_typebox33.TString;
436
505
  }>>;
437
506
  }>;
438
507
  //# sourceMappingURL=errorSchema.d.ts.map
439
508
  //#endregion
440
509
  //#region src/schemas/okSchema.d.ts
441
- declare const okSchema: _sinclair_typebox30.TObject<{
442
- ok: _sinclair_typebox30.TBoolean;
443
- id: _sinclair_typebox30.TOptional<_sinclair_typebox30.TUnion<[_sinclair_typebox30.TString, _sinclair_typebox30.TInteger]>>;
444
- count: _sinclair_typebox30.TOptional<_sinclair_typebox30.TNumber>;
510
+ declare const okSchema: _sinclair_typebox25.TObject<{
511
+ ok: _sinclair_typebox25.TBoolean;
512
+ id: _sinclair_typebox25.TOptional<_sinclair_typebox25.TUnion<[_sinclair_typebox25.TString, _sinclair_typebox25.TInteger]>>;
513
+ count: _sinclair_typebox25.TOptional<_sinclair_typebox25.TNumber>;
445
514
  }>;
446
515
  type Ok = Static<typeof okSchema>;
447
516
  //# sourceMappingURL=okSchema.d.ts.map
448
517
  //#endregion
449
- //#region src/providers/features/ServerLoggerProvider.d.ts
518
+ //#region src/providers/NodeHttpServerProvider.d.ts
519
+ declare const envSchema: _alepha_core2.TObject<{
520
+ SERVER_PORT: _alepha_core2.TNumber;
521
+ SERVER_HOST: _alepha_core2.TString;
522
+ }>;
523
+ declare module "alepha" {
524
+ interface Env extends Partial<Static<typeof envSchema>> {}
525
+ }
526
+ declare class NodeHttpServerProvider extends ServerProvider {
527
+ protected readonly alepha: Alepha;
528
+ protected readonly dateTimeProvider: DateTimeProvider;
529
+ protected readonly log: _alepha_core2.Logger;
530
+ protected readonly env: {
531
+ SERVER_PORT: number;
532
+ SERVER_HOST: string;
533
+ };
534
+ protected readonly router: ServerRouterProvider;
535
+ protected readonly server: http0.Server<typeof IncomingMessage, typeof ServerResponse$1>;
536
+ protected readonly onNodeRequest: _alepha_core2.HookDescriptor<"node:request">;
537
+ handle(req: IncomingMessage, res: ServerResponse$1): Promise<void>;
538
+ createRouterRequest(req: IncomingMessage, res: ServerResponse$1, params?: Record<string, string>): ServerRawRequest;
539
+ getProtocol(req: IncomingMessage): "http" | "https";
540
+ get hostname(): string;
541
+ readonly start: _alepha_core2.HookDescriptor<"start">;
542
+ protected readonly stop: _alepha_core2.HookDescriptor<"stop">;
543
+ protected listen(): Promise<void>;
544
+ protected close(): Promise<void>;
545
+ }
546
+ //#endregion
547
+ //#region src/providers/ServerLoggerProvider.d.ts
450
548
  declare class ServerLoggerProvider {
451
- protected readonly log: _alepha_core3.Logger;
549
+ protected readonly log: _alepha_core9.Logger;
452
550
  protected readonly alepha: Alepha;
453
- readonly onRequest: _alepha_core3.HookDescriptor<"server:onRequest">;
454
- readonly onError: _alepha_core3.HookDescriptor<"server:onError">;
455
- readonly onResponse: _alepha_core3.HookDescriptor<"server:onResponse">;
551
+ readonly onRequest: _alepha_core9.HookDescriptor<"server:onRequest">;
552
+ readonly onError: _alepha_core9.HookDescriptor<"server:onError">;
553
+ readonly onResponse: _alepha_core9.HookDescriptor<"server:onResponse">;
456
554
  }
457
555
  //# sourceMappingURL=ServerLoggerProvider.d.ts.map
458
556
  //#endregion
459
- //#region src/providers/features/ServerNotReadyProvider.d.ts
557
+ //#region src/providers/ServerNotReadyProvider.d.ts
460
558
  /**
461
559
  * On every request, this provider checks if the server is ready.
462
560
  *
@@ -466,182 +564,30 @@ declare class ServerLoggerProvider {
466
564
  */
467
565
  declare class ServerNotReadyProvider {
468
566
  protected readonly alepha: Alepha;
469
- readonly onRequest: _alepha_core7.HookDescriptor<"server:onRequest">;
567
+ readonly onRequest: _alepha_core13.HookDescriptor<"server:onRequest">;
470
568
  }
471
569
  //# sourceMappingURL=ServerNotReadyProvider.d.ts.map
472
570
  //#endregion
473
- //#region src/providers/features/ServerSecurityProvider.d.ts
474
- declare class ServerSecurityProvider {
475
- protected readonly log: _alepha_core8.Logger;
476
- protected readonly securityProvider: SecurityProvider;
477
- protected readonly jwtProvider: JwtProvider;
478
- protected readonly alepha: Alepha;
479
- readonly onClientRequest: _alepha_core8.HookDescriptor<"client:onRequest">;
480
- protected readonly onRequest: _alepha_core8.HookDescriptor<"server:onRequest">;
481
- protected readonly onRoute: _alepha_core8.HookDescriptor<"server:onRoute">;
482
- }
483
- //# sourceMappingURL=ServerSecurityProvider.d.ts.map
484
- //#endregion
485
- //#region src/providers/features/ServerTimingProvider.d.ts
571
+ //#region src/providers/ServerTimingProvider.d.ts
486
572
  type TimingMap = Record<string, [number, number]>;
487
573
  declare class ServerTimingProvider {
488
- protected readonly log: _alepha_core12.Logger;
574
+ protected readonly log: _alepha_core14.Logger;
489
575
  protected readonly alepha: Alepha;
490
- readonly onRequest: _alepha_core12.HookDescriptor<"server:onRequest">;
491
- readonly onResponse: _alepha_core12.HookDescriptor<"server:onResponse">;
576
+ readonly onRequest: _alepha_core14.HookDescriptor<"server:onRequest">;
577
+ readonly onResponse: _alepha_core14.HookDescriptor<"server:onResponse">;
492
578
  protected get handlerName(): string;
493
579
  beginTiming(name: string): void;
494
580
  endTiming(name: string): void;
495
581
  protected setDuration(name: string, timing: TimingMap): void;
496
582
  }
497
583
  //#endregion
498
- //#region src/providers/ServerRouterProvider.d.ts
499
- /**
500
- * Main router for all routes on the server side.
501
- *
502
- * - $route => generic route
503
- * - $action => action route (for API calls)
504
- * - $page => React route (for SSR)
505
- */
506
- declare class ServerRouterProvider extends RouterProvider<ServerRouteWithHandler> {
507
- protected readonly alepha: Alepha;
508
- route<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): Promise<void>;
509
- onRequest(route: ServerRoute, rawRequest: ServerRawRequest, responseKind: ResponseKind): Promise<ServerResponse>;
510
- protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
511
- status: number;
512
- headers: Record<string, string> & {
513
- "set-cookie"?: string[];
514
- };
515
- body: any;
516
- }>;
517
- protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
518
- protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
519
- protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
520
- validateRequest(route: {
521
- schema?: RequestConfigSchema;
522
- }, request: ServerRequestConfig): void;
523
- serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
524
- }
525
- //# sourceMappingURL=ServerRouterProvider.d.ts.map
526
- //#endregion
527
- //#region src/providers/platforms/ServerProvider.d.ts
528
- declare abstract class ServerProvider {
529
- protected readonly alepha: Alepha;
530
- abstract get hostname(): string;
531
- protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
532
- }
533
- //# sourceMappingURL=ServerProvider.d.ts.map
534
- //#endregion
535
- //#region src/providers/platforms/NodeHttpServerProvider.d.ts
536
- declare const envSchema$1: _alepha_core15.TObject<{
537
- SERVER_PORT: _alepha_core15.TNumber;
538
- SERVER_HOST: _alepha_core15.TString;
539
- }>;
540
- declare module "alepha" {
541
- interface Env extends Partial<Static<typeof envSchema$1>> {}
542
- }
543
- declare class NodeHttpServerProvider extends ServerProvider {
544
- protected readonly alepha: Alepha;
545
- protected readonly log: _alepha_core15.Logger;
546
- protected readonly env: {
547
- SERVER_PORT: number;
548
- SERVER_HOST: string;
549
- };
550
- protected readonly router: ServerRouterProvider;
551
- protected readonly server: http20.Server<typeof IncomingMessage, typeof ServerResponse$1>;
552
- protected readonly onNodeRequest: _alepha_core15.HookDescriptor<"node:request">;
553
- handle(req: IncomingMessage, res: ServerResponse$1): Promise<void>;
554
- createRouterRequest(req: IncomingMessage, res: ServerResponse$1, params?: Record<string, string>): ServerRawRequest;
555
- getProtocol(req: IncomingMessage): "http" | "https";
556
- get hostname(): string;
557
- readonly start: _alepha_core15.HookDescriptor<"start">;
558
- protected readonly stop: _alepha_core15.HookDescriptor<"stop">;
559
- protected listen(): Promise<void>;
560
- protected close(): Promise<void>;
561
- }
562
- //#endregion
563
- //#region src/providers/ServerActionDescriptorProvider.d.ts
564
- declare const envSchema: _alepha_core24.TObject<{
565
- SERVER_API_PREFIX: _alepha_core24.TString;
566
- SERVER_SECURITY_ENABLED: _alepha_core24.TBoolean;
567
- }>;
568
- declare module "alepha" {
569
- interface Env extends Partial<Static<typeof envSchema>> {}
570
- interface State {
571
- /**
572
- * Real (or fake) user account, used for internal actions.
573
- * If you define this, you assume that all actions are executed by this user by default.
574
- * And to force a different user, you need to pass it explicitly in the options.
575
- */
576
- "ServerSecurityProvider.localSystemUser"?: UserAccountToken;
577
- }
578
- }
579
- declare class ServerActionDescriptorProvider {
580
- protected readonly log: _alepha_core24.Logger;
581
- protected readonly alepha: Alepha;
582
- protected readonly env: {
583
- SERVER_API_PREFIX: string;
584
- SERVER_SECURITY_ENABLED: boolean;
585
- };
586
- protected readonly client: HttpClient;
587
- protected readonly serverProvider: ServerProvider;
588
- protected readonly helper: ActionDescriptorHelper;
589
- protected readonly routerProvider: ServerRouterProvider;
590
- protected readonly actions: ServerRouteAction[];
591
- getActions(): ServerRouteAction<RequestConfigSchema>[];
592
- getPrefix(): string;
593
- readonly configure: _alepha_core24.HookDescriptor<"configure">;
594
- registerAction(value: ActionDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
595
- /**
596
- * Check a mock function for the specified route.
597
- *
598
- * This is mostly used for testing purposes.
599
- */
600
- protected createLocalHandler(action: ActionDescriptorOptions, permission: Permission): (config?: ServerRequestConfigEntry, options?: ClientRequestOptions) => Promise<any>;
601
- /**
602
- * Get the user account token for a local action call.
603
- * It will check the options, context, and system user.
604
- */
605
- protected getUserFromLocalFunctionContext(options: {
606
- user?: UserAccountToken | "system" | "context";
607
- }, permission: Permission, isRouteSecure: boolean): UserAccountToken | undefined;
608
- }
609
- declare const isServerAction: (value: any) => value is ServerRouteAction;
610
- interface ServerRemote {
611
- url: string;
612
- name: string;
613
- proxy: boolean;
614
- internal: boolean;
615
- links: (args: {
616
- authorization?: string;
617
- }) => Promise<ApiLinksResponse>;
618
- schema: (args: {
619
- name: string;
620
- authorization?: string;
621
- }) => Promise<any>;
622
- serviceAccount?: ServiceAccountDescriptor;
623
- prefix: string;
624
- }
625
- interface ServerRouteAction<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
626
- prefix: string;
627
- method: RouteMethod;
628
- name: string;
629
- group: string;
630
- permission: Permission;
631
- options: ActionDescriptorOptions;
632
- localHandler: LocalHandler;
633
- }
634
- type LocalHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (config?: ServerRequestConfigEntry<TConfig>, options?: ClientRequestOptions) => Promise<any>;
635
- //#endregion
636
584
  //#region src/index.d.ts
637
585
  declare module "alepha" {
638
586
  interface Hooks {
639
- "node:request": {
640
- req: IncomingMessage;
641
- res: ServerResponse$1;
642
- };
643
- "server:onRoute": {
644
- route: ServerRoute;
587
+ "action:onRequest": {
588
+ action: ActionDescriptor<RequestConfigSchema>;
589
+ request: ServerRequest;
590
+ options: ClientRequestOptions;
645
591
  };
646
592
  "server:onRequest": {
647
593
  route: ServerRoute;
@@ -677,6 +623,10 @@ declare module "alepha" {
677
623
  route?: HttpAction;
678
624
  error: HttpError;
679
625
  };
626
+ "node:request": {
627
+ req: IncomingMessage;
628
+ res: ServerResponse$1;
629
+ };
680
630
  }
681
631
  }
682
632
  /**
@@ -686,158 +636,13 @@ declare module "alepha" {
686
636
  * on class properties. It provides automatic request/response handling, schema validation, middleware support,
687
637
  * and seamless integration with other Alepha modules for a complete backend solution.
688
638
  *
689
- * **Key Features:**
690
- * - Declarative route definition with `$route` descriptor
691
- * - API action handlers with `$action` descriptor
692
- * - Schema validation for requests and responses
693
- * - Automatic body parsing and response formatting
694
- * - Built-in middleware system and error handling
695
- * - Type-safe request parameters and response data
696
- * - Integration with authentication and security modules
697
- *
698
- * **Basic Routing:**
699
- * ```ts
700
- * import { Alepha, run, t } from "alepha";
701
- * import { AlephaServer, $route } from "alepha/server";
702
- *
703
- * class ApiRoutes {
704
- * // Simple GET route
705
- * getUsers = $route({
706
- * path: "/api/users",
707
- * method: "GET",
708
- * handler: async () => {
709
- * const users = await getAllUsers();
710
- * return Response.json(users);
711
- * },
712
- * });
713
- *
714
- * // POST route with body validation
715
- * createUser = $route({
716
- * path: "/api/users",
717
- * method: "POST",
718
- * schema: {
719
- * body: t.object({
720
- * name: t.string(),
721
- * email: t.string(),
722
- * }),
723
- * },
724
- * handler: async ({ body }) => {
725
- * const user = await createUser(body);
726
- * return Response.json(user, { status: 201 });
727
- * },
728
- * });
729
- *
730
- * // Dynamic route with parameters
731
- * getUserById = $route({
732
- * path: "/api/users/:id",
733
- * method: "GET",
734
- * schema: {
735
- * params: t.object({
736
- * id: t.string(),
737
- * }),
738
- * },
739
- * handler: async ({ params }) => {
740
- * const user = await findUserById(params.id);
741
- * if (!user) {
742
- * return new Response("User not found", { status: 404 });
743
- * }
744
- * return Response.json(user);
745
- * },
746
- * });
747
- * }
748
- *
749
- * const alepha = Alepha.create()
750
- * .with(AlephaServer)
751
- * .with(ApiRoutes);
752
- *
753
- * run(alepha);
754
- * ```
755
- *
756
- * **Action Descriptors:**
757
- * ```ts
758
- * import { $action } from "alepha/server";
759
- *
760
- * class UserController {
761
- * // Reusable business logic action
762
- * getUserProfile = $action({
763
- * schema: {
764
- * params: t.object({
765
- * userId: t.string(),
766
- * }),
767
- * response: t.object({
768
- * id: t.string(),
769
- * name: t.string(),
770
- * email: t.string(),
771
- * }),
772
- * },
773
- * handler: async ({ params }) => {
774
- * const user = await getUserById(params.userId);
775
- * return {
776
- * id: user.id,
777
- * name: user.name,
778
- * email: user.email,
779
- * };
780
- * },
781
- * });
782
- *
783
- * // Route that uses the action
784
- * profileRoute = $route({
785
- * path: "/api/profile/:userId",
786
- * method: "GET",
787
- * handler: async ({ params }) => {
788
- * const profile = await this.getUserProfile({ params });
789
- * return Response.json(profile);
790
- * },
791
- * });
792
- * }
793
- * ```
794
- *
795
- * **Middleware and Error Handling:**
796
- * ```ts
797
- * class AppServer {
798
- * // Global middleware
799
- * middleware = $route({
800
- * path: "*",
801
- * method: "*",
802
- * handler: async ({ request, next }) => {
803
- * console.log(`${request.method} ${request.url}`);
804
- * try {
805
- * return await next();
806
- * } catch (error) {
807
- * console.error("Request failed:", error);
808
- * return Response.json({ error: "Internal Server Error" }, { status: 500 });
809
- * }
810
- * },
811
- * });
812
- *
813
- * // CORS preflight handling
814
- * corsPrelight = $route({
815
- * path: "*",
816
- * method: "OPTIONS",
817
- * handler: async () => {
818
- * return new Response(null, {
819
- * status: 200,
820
- * headers: {
821
- * "Access-Control-Allow-Origin": "*",
822
- * "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
823
- * "Access-Control-Allow-Headers": "Content-Type, Authorization",
824
- * },
825
- * });
826
- * },
827
- * });
828
- * }
829
- * ```
830
- *
831
639
  * @see {@link $route}
832
640
  * @see {@link $action}
833
641
  * @module alepha.server
834
642
  */
835
- declare class AlephaServer implements Module {
836
- readonly name = "alepha.server";
837
- readonly $services: (alepha: Alepha) => void;
838
- }
643
+ declare const AlephaServer: _alepha_core0.ModuleDescriptor;
839
644
  //# sourceMappingURL=index.d.ts.map
840
645
 
841
646
  //#endregion
842
- export { $action, $route, ActionDescriptor, ActionDescriptorHelper, ActionDescriptorOptions, AlephaServer, ApiLink, ApiLinksResponse, BadRequestError, ClientRequestEntry, ClientRequestEntryContainer, ClientRequestOptions, ClientRequestResponse, ConflictError, FetchActionArgs, FetchOptions, FetchResponse, ForbiddenError, HttpAction, HttpClient, HttpClientPendingRequests, HttpError, HttpErrorLike, LocalHandler, NodeHttpServerProvider, NotFoundError, Ok, RequestConfigSchema, ResponseBodyType, ResponseKind, RouteDescriptor, RouteDescriptorOptions, RouteMethod, ServerActionDescriptorProvider, ServerHandler, ServerLoggerProvider, ServerMiddlewareHandler, ServerNotReadyProvider, ServerProvider, ServerRawRequest, ServerRemote, ServerReply, ServerRequest, ServerRequestConfig, ServerRequestConfigEntry, ServerResponse, ServerResponseBody, ServerRoute, ServerRouteAction, ServerRouteSecure, ServerRouteWithHandler, ServerRouterProvider, ServerSecurityProvider, ServerTimingProvider, UnauthorizedError, ValidationError, apiLinkSchema, apiLinksResponseSchema, errorNameByStatus, errorSchema, isHttpError, isServerAction, okSchema, routeMethods };
647
+ export { $action, $route, ActionDescriptor, ActionDescriptorOptions, AlephaServer, ApiLink, ApiLinksResponse, BadRequestError, ClientRequestEntry, ClientRequestEntryContainer, ClientRequestOptions, ClientRequestResponse, ConflictError, FetchActionArgs, FetchOptions, FetchResponse, ForbiddenError, HttpAction, HttpClient, HttpClientPendingRequests, HttpError, HttpErrorLike, NodeHttpServerProvider, NotFoundError, Ok, RequestConfigSchema, ResponseBodyType, ResponseKind, RouteDescriptor, RouteDescriptorOptions, RouteMethod, ServerActionHandler, ServerActionRequest, ServerHandler, ServerLoggerProvider, ServerMiddlewareHandler, ServerNotReadyProvider, ServerProvider, ServerRawRequest, ServerReply, ServerRequest, ServerRequestConfig, ServerRequestConfigEntry, ServerResponse, ServerResponseBody, ServerRoute, ServerRouteMatcher, ServerRouterProvider, ServerTimingProvider, UnauthorizedError, ValidationError, apiLinkSchema, apiLinksResponseSchema, errorNameByStatus, errorSchema, isHttpError, isMultipart, okSchema, routeMethods };
843
648
  //# sourceMappingURL=index.d.ts.map