alepha 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +47 -44
  3. package/batch.d.ts +87 -88
  4. package/bucket.cjs +8 -0
  5. package/bucket.d.ts +194 -0
  6. package/bucket.js +1 -0
  7. package/cache/redis.d.ts +14 -16
  8. package/cache.d.ts +101 -170
  9. package/command.d.ts +70 -77
  10. package/core.d.ts +1043 -887
  11. package/datetime.d.ts +91 -117
  12. package/file.cjs +8 -0
  13. package/file.d.ts +56 -0
  14. package/file.js +1 -0
  15. package/lock/redis.d.ts +11 -13
  16. package/lock.d.ts +125 -117
  17. package/package.json +66 -38
  18. package/postgres.d.ts +232 -275
  19. package/queue/redis.d.ts +13 -15
  20. package/queue.d.ts +88 -116
  21. package/react/auth.d.ts +50 -55
  22. package/react/head.d.ts +5 -8
  23. package/react.d.ts +71 -73
  24. package/redis.d.ts +32 -14
  25. package/retry.d.ts +70 -58
  26. package/router.cjs +8 -0
  27. package/router.d.ts +45 -0
  28. package/router.js +1 -0
  29. package/scheduler.d.ts +54 -96
  30. package/security.d.ts +117 -119
  31. package/server/cache.d.ts +22 -31
  32. package/server/compress.d.ts +16 -7
  33. package/server/cookies.d.ts +70 -61
  34. package/server/cors.d.ts +15 -13
  35. package/server/health.d.ts +23 -26
  36. package/server/helmet.d.ts +17 -20
  37. package/server/links.d.ts +113 -90
  38. package/server/metrics.d.ts +25 -23
  39. package/server/multipart.d.ts +12 -16
  40. package/server/proxy.d.ts +25 -20
  41. package/server/security.cjs +8 -0
  42. package/server/security.d.ts +90 -0
  43. package/server/security.js +1 -0
  44. package/server/static.d.ts +67 -68
  45. package/server/swagger.d.ts +77 -65
  46. package/server.d.ts +265 -308
  47. package/topic/redis.d.ts +25 -26
  48. package/topic.d.ts +76 -122
  49. package/vite.d.ts +52 -36
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";
2
+ import * as _alepha_core0$1 from "alepha";
3
+ import * as _alepha_core5 from "alepha";
4
+ import * as _alepha_core13 from "alepha";
5
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";
6
+ import * as _alepha_core2 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
14
  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";
15
+ import * as _sinclair_typebox7 from "@sinclair/typebox";
16
+ import * as _sinclair_typebox33 from "@sinclair/typebox";
17
+ import * as _sinclair_typebox0 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,39 +212,69 @@ interface HttpAction {
204
212
  }
205
213
  //#endregion
206
214
  //#region src/descriptors/$action.d.ts
207
- declare const KEY$1 = "ACTION";
208
- interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema"> {
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
+ */
232
+ declare const $action: {
233
+ <TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptor<TConfig>;
234
+ [KIND]: typeof ActionDescriptor;
235
+ };
236
+ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
209
237
  /**
210
- * 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.
211
242
  */
212
243
  name?: string;
213
244
  /**
214
- * Namespace of the route, used for grouping.
245
+ * Group actions together.
215
246
  *
216
- * @default Class name containing the route.
217
- */
218
- group?: string;
219
- /**
220
- * 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
+ * }
221
257
  *
222
- * @default true when SecurityModule is enabled, false otherwise.
223
- * @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
+ * ```
224
265
  */
225
- security?: boolean;
266
+ group?: string;
226
267
  /**
227
- * Pathname of the route.
268
+ * Pathname of the route. If not provided, property key is used.
228
269
  */
229
270
  path?: string;
230
- /**
231
- * Inherit options from another route.
232
- */
233
- use?: {
234
- [OPTIONS]: ActionDescriptorOptions<TConfig>;
235
- };
236
271
  /**
237
272
  * The route method.
238
273
  *
239
- * @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.)
240
278
  */
241
279
  method?: RouteMethod;
242
280
  /**
@@ -248,70 +286,87 @@ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestC
248
286
  */
249
287
  schema?: TConfig;
250
288
  /**
251
- * Short description of the route.
252
- */
253
- summary?: string;
254
- /**
255
- * Long description of the route.
289
+ * A short description of the action. Used for documentation purposes.
256
290
  */
257
291
  description?: string;
258
292
  /**
259
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!
260
295
  */
261
296
  disabled?: boolean;
262
- /**
263
- * Mark the route as private.
264
- * - It won't be exposed in the API documentation.
265
- * - It won't be exposed in _links.
266
- */
267
- internal?: boolean;
268
297
  /**
269
298
  * Main route handler. This is where the route logic is implemented.
270
299
  */
271
- handler?: ServerHandler<TConfig>;
300
+ handler: ServerActionHandler<TConfig>;
272
301
  }
273
- interface ActionDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> {
274
- [KIND]: typeof KEY$1;
275
- [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;
317
+ /**
318
+ * Returns the group of the action. (e.g. "orders", "admin", etc.)
319
+ */
320
+ get group(): string;
276
321
  /**
277
- * Fetch or just call local route when available.
322
+ * Returns the HTTP method of the action.
278
323
  */
279
- (config?: ClientRequestEntry<TConfig>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
324
+ get method(): RouteMethod;
280
325
  /**
281
- * Just fetch the route. Skip any local route.
326
+ * Returns the path of the action.
327
+ *
328
+ * Path is prefixed by `/api` by default.
282
329
  */
283
- fetch: (config?: ClientRequestEntry<TConfig>, opts?: ClientRequestOptions) => Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
330
+ get path(): string;
331
+ get schema(): TConfig | undefined;
332
+ getBodyContentType(): string | undefined;
284
333
  /**
285
- * Name of the permission required to access this route.
334
+ * Call the action handler directly.
335
+ * There is no HTTP layer involved.
286
336
  */
287
- 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>>>;
288
342
  }
289
- declare const $action: {
290
- <TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptor<TConfig>;
291
- [KIND]: string;
292
- };
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";
357
- interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {}
358
- type RouteDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
359
- [KIND]: typeof KEY;
360
- [OPTIONS]: RouteDescriptorOptions<TConfig>;
361
- };
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
+ */
362
419
  declare const $route: {
363
- <TConfig extends RequestConfigSchema = RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
364
- [KIND]: string;
420
+ <TConfig extends RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
421
+ [KIND]: typeof RouteDescriptor;
365
422
  };
423
+ interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {}
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_typebox7.TObject<{
474
+ name: _sinclair_typebox7.TString;
475
+ path: _sinclair_typebox7.TString;
476
+ method: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
477
+ group: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
478
+ requestBodyType: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
479
+ service: _sinclair_typebox7.TOptional<_sinclair_typebox7.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_typebox7.TObject<{
482
+ prefix: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
483
+ links: _sinclair_typebox7.TArray<_sinclair_typebox7.TObject<{
484
+ name: _sinclair_typebox7.TString;
485
+ path: _sinclair_typebox7.TString;
486
+ method: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
487
+ group: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
488
+ requestBodyType: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
489
+ service: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
421
490
  }>>;
422
491
  }>;
423
492
  type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
@@ -425,38 +494,66 @@ 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_typebox0.TObject<{
511
+ ok: _sinclair_typebox0.TBoolean;
512
+ id: _sinclair_typebox0.TOptional<_sinclair_typebox0.TUnion<[_sinclair_typebox0.TString, _sinclair_typebox0.TInteger]>>;
513
+ count: _sinclair_typebox0.TOptional<_sinclair_typebox0.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_core5.TObject<{
520
+ SERVER_PORT: _alepha_core5.TNumber;
521
+ SERVER_HOST: _alepha_core5.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 log: _alepha_core5.Logger;
529
+ protected readonly env: {
530
+ SERVER_PORT: number;
531
+ SERVER_HOST: string;
532
+ };
533
+ protected readonly router: ServerRouterProvider;
534
+ protected readonly server: http0.Server<typeof IncomingMessage, typeof ServerResponse$1>;
535
+ protected readonly onNodeRequest: _alepha_core5.HookDescriptor<"node:request">;
536
+ handle(req: IncomingMessage, res: ServerResponse$1): Promise<void>;
537
+ createRouterRequest(req: IncomingMessage, res: ServerResponse$1, params?: Record<string, string>): ServerRawRequest;
538
+ getProtocol(req: IncomingMessage): "http" | "https";
539
+ get hostname(): string;
540
+ readonly start: _alepha_core5.HookDescriptor<"start">;
541
+ protected readonly stop: _alepha_core5.HookDescriptor<"stop">;
542
+ protected listen(): Promise<void>;
543
+ protected close(): Promise<void>;
544
+ }
545
+ //#endregion
546
+ //#region src/providers/ServerLoggerProvider.d.ts
450
547
  declare class ServerLoggerProvider {
451
- protected readonly log: _alepha_core3.Logger;
548
+ protected readonly log: _alepha_core13.Logger;
452
549
  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">;
550
+ readonly onRequest: _alepha_core13.HookDescriptor<"server:onRequest">;
551
+ readonly onError: _alepha_core13.HookDescriptor<"server:onError">;
552
+ readonly onResponse: _alepha_core13.HookDescriptor<"server:onResponse">;
456
553
  }
457
554
  //# sourceMappingURL=ServerLoggerProvider.d.ts.map
458
555
  //#endregion
459
- //#region src/providers/features/ServerNotReadyProvider.d.ts
556
+ //#region src/providers/ServerNotReadyProvider.d.ts
460
557
  /**
461
558
  * On every request, this provider checks if the server is ready.
462
559
  *
@@ -466,182 +563,30 @@ declare class ServerLoggerProvider {
466
563
  */
467
564
  declare class ServerNotReadyProvider {
468
565
  protected readonly alepha: Alepha;
469
- readonly onRequest: _alepha_core7.HookDescriptor<"server:onRequest">;
566
+ readonly onRequest: _alepha_core12.HookDescriptor<"server:onRequest">;
470
567
  }
471
568
  //# sourceMappingURL=ServerNotReadyProvider.d.ts.map
472
569
  //#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
570
+ //#region src/providers/ServerTimingProvider.d.ts
486
571
  type TimingMap = Record<string, [number, number]>;
487
572
  declare class ServerTimingProvider {
488
- protected readonly log: _alepha_core12.Logger;
573
+ protected readonly log: _alepha_core2.Logger;
489
574
  protected readonly alepha: Alepha;
490
- readonly onRequest: _alepha_core12.HookDescriptor<"server:onRequest">;
491
- readonly onResponse: _alepha_core12.HookDescriptor<"server:onResponse">;
575
+ readonly onRequest: _alepha_core2.HookDescriptor<"server:onRequest">;
576
+ readonly onResponse: _alepha_core2.HookDescriptor<"server:onResponse">;
492
577
  protected get handlerName(): string;
493
578
  beginTiming(name: string): void;
494
579
  endTiming(name: string): void;
495
580
  protected setDuration(name: string, timing: TimingMap): void;
496
581
  }
497
582
  //#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
583
  //#region src/index.d.ts
637
584
  declare module "alepha" {
638
585
  interface Hooks {
639
- "node:request": {
640
- req: IncomingMessage;
641
- res: ServerResponse$1;
642
- };
643
- "server:onRoute": {
644
- route: ServerRoute;
586
+ "action:onRequest": {
587
+ action: ActionDescriptor<RequestConfigSchema>;
588
+ request: ServerRequest;
589
+ options: ClientRequestOptions;
645
590
  };
646
591
  "server:onRequest": {
647
592
  route: ServerRoute;
@@ -677,14 +622,26 @@ declare module "alepha" {
677
622
  route?: HttpAction;
678
623
  error: HttpError;
679
624
  };
625
+ "node:request": {
626
+ req: IncomingMessage;
627
+ res: ServerResponse$1;
628
+ };
680
629
  }
681
630
  }
682
- declare class AlephaServer implements Module {
683
- readonly name = "alepha.server";
684
- readonly $services: (alepha: Alepha) => void;
685
- }
631
+ /**
632
+ * Provides high-performance HTTP server capabilities with declarative routing and action descriptors.
633
+ *
634
+ * The server module enables building REST APIs and web applications using `$route` and `$action` descriptors
635
+ * on class properties. It provides automatic request/response handling, schema validation, middleware support,
636
+ * and seamless integration with other Alepha modules for a complete backend solution.
637
+ *
638
+ * @see {@link $route}
639
+ * @see {@link $action}
640
+ * @module alepha.server
641
+ */
642
+ declare const AlephaServer: _alepha_core0.ModuleDescriptor;
686
643
  //# sourceMappingURL=index.d.ts.map
687
644
 
688
645
  //#endregion
689
- 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 };
646
+ 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 };
690
647
  //# sourceMappingURL=index.d.ts.map