@alepha/react 0.13.0 → 0.13.2

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 (76) hide show
  1. package/dist/auth/index.browser.js +9 -1647
  2. package/dist/auth/index.browser.js.map +1 -1
  3. package/dist/auth/index.d.ts +330 -330
  4. package/dist/auth/index.js +11 -1649
  5. package/dist/auth/index.js.map +1 -1
  6. package/dist/core/index.browser.js +19 -18
  7. package/dist/core/index.browser.js.map +1 -1
  8. package/dist/core/index.d.ts +352 -344
  9. package/dist/core/index.js +25 -24
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/index.native.js +381 -0
  12. package/dist/core/index.native.js.map +1 -0
  13. package/dist/form/index.d.ts +3 -3
  14. package/dist/form/index.js +3 -1642
  15. package/dist/form/index.js.map +1 -1
  16. package/dist/head/index.browser.js +9 -1660
  17. package/dist/head/index.browser.js.map +1 -1
  18. package/dist/head/index.d.ts +808 -1544
  19. package/dist/head/index.js +10 -1660
  20. package/dist/head/index.js.map +1 -1
  21. package/dist/i18n/index.d.ts +34 -34
  22. package/dist/i18n/index.js +14 -1664
  23. package/dist/i18n/index.js.map +1 -1
  24. package/dist/websocket/index.d.ts +161 -5
  25. package/dist/websocket/index.js +2 -1654
  26. package/dist/websocket/index.js.map +1 -1
  27. package/package.json +12 -9
  28. package/src/auth/index.ts +1 -1
  29. package/src/auth/providers/ReactAuthProvider.ts +1 -1
  30. package/src/auth/services/ReactAuth.ts +5 -5
  31. package/src/core/components/NestedView.tsx +1 -1
  32. package/src/core/hooks/useStore.ts +4 -4
  33. package/src/core/index.browser.ts +2 -2
  34. package/src/core/index.native.ts +1 -1
  35. package/src/core/index.shared-router.ts +1 -1
  36. package/src/core/index.ts +3 -3
  37. package/src/core/{descriptors → primitives}/$page.ts +20 -20
  38. package/src/core/providers/ReactBrowserProvider.ts +2 -2
  39. package/src/core/providers/ReactBrowserRouterProvider.ts +2 -2
  40. package/src/core/providers/ReactPageProvider.ts +25 -11
  41. package/src/core/providers/ReactServerProvider.ts +12 -12
  42. package/src/core/services/ReactPageServerService.ts +6 -6
  43. package/src/core/services/ReactPageService.ts +6 -6
  44. package/src/core/services/ReactRouter.ts +3 -3
  45. package/src/head/index.browser.ts +3 -3
  46. package/src/head/index.ts +4 -4
  47. package/src/head/{descriptors → primitives}/$head.ts +6 -6
  48. package/src/i18n/hooks/useI18n.ts +2 -2
  49. package/src/i18n/index.ts +3 -3
  50. package/src/i18n/{descriptors → primitives}/$dictionary.ts +8 -8
  51. package/src/i18n/providers/I18nProvider.ts +5 -5
  52. package/src/websocket/hooks/useRoom.tsx +3 -3
  53. package/dist/auth/chunk-DhGyd7sr.js +0 -28
  54. package/dist/auth/index.cjs +0 -1800
  55. package/dist/auth/index.cjs.map +0 -1
  56. package/dist/auth/index.d.cts +0 -1274
  57. package/dist/core/chunk-DhGyd7sr.js +0 -28
  58. package/dist/core/index.cjs +0 -2087
  59. package/dist/core/index.cjs.map +0 -1
  60. package/dist/core/index.d.cts +0 -2763
  61. package/dist/form/chunk-DhGyd7sr.js +0 -28
  62. package/dist/form/index.cjs +0 -2074
  63. package/dist/form/index.cjs.map +0 -1
  64. package/dist/form/index.d.cts +0 -419
  65. package/dist/head/chunk-DhGyd7sr.js +0 -28
  66. package/dist/head/index.cjs +0 -1912
  67. package/dist/head/index.cjs.map +0 -1
  68. package/dist/head/index.d.cts +0 -1801
  69. package/dist/i18n/chunk-DhGyd7sr.js +0 -28
  70. package/dist/i18n/index.cjs +0 -1899
  71. package/dist/i18n/index.cjs.map +0 -1
  72. package/dist/i18n/index.d.cts +0 -437
  73. package/dist/websocket/index.cjs +0 -1787
  74. package/dist/websocket/index.cjs.map +0 -1
  75. package/dist/websocket/index.d.cts +0 -118
  76. package/src/i18n/README.md +0 -76
@@ -1,1780 +1,1044 @@
1
- import * as alepha84 from "alepha";
2
- import { Alepha, AlephaError, Async, Atom, Descriptor, FileLike, InstantiableClass, KIND, LogLevel, LoggerInterface, Static, StreamLike, TArray, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
3
- import React, { FC, ReactNode } from "react";
4
- import "react/jsx-runtime";
1
+ import { PageConfigSchema, PageRoute, ReactRouterState, TPropsDefault, TPropsParentDefault } from "@alepha/react";
2
+ import * as alepha30 from "alepha";
3
+ import { Alepha, AlephaError, Async, FileLike, InstantiableClass, KIND, LogLevel, LoggerInterface, Primitive, Static, StreamLike, TArray, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
5
4
  import { IncomingMessage, Server, ServerResponse } from "node:http";
6
- import dayjsDuration from "dayjs/plugin/duration.js";
7
- import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
8
5
  import { Readable } from "node:stream";
9
6
  import { ReadableStream } from "node:stream/web";
7
+ import dayjsDuration from "dayjs/plugin/duration.js";
8
+ import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
10
9
 
11
- //#region ../alepha/src/logger/schemas/logEntrySchema.d.ts
12
- declare const logEntrySchema: alepha84.TObject<{
13
- level: alepha84.TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
14
- message: alepha84.TString;
15
- service: alepha84.TString;
16
- module: alepha84.TString;
17
- context: alepha84.TOptional<alepha84.TString>;
18
- app: alepha84.TOptional<alepha84.TString>;
19
- data: alepha84.TOptional<alepha84.TAny>;
20
- timestamp: alepha84.TNumber;
21
- }>;
22
- type LogEntry = Static<typeof logEntrySchema>;
23
- //#endregion
24
- //#region ../alepha/src/datetime/providers/DateTimeProvider.d.ts
25
- type DateTime = DayjsApi.Dayjs;
26
- type Duration = dayjsDuration.Duration;
27
- type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
28
- declare class DateTimeProvider {
29
- static PLUGINS: Array<PluginFunc<any>>;
30
- protected alepha: Alepha;
31
- protected ref: DateTime | null;
32
- protected readonly timeouts: Timeout[];
33
- protected readonly intervals: Interval[];
34
- constructor();
35
- protected readonly onStart: alepha84.HookDescriptor<"start">;
36
- protected readonly onStop: alepha84.HookDescriptor<"stop">;
37
- setLocale(locale: string): void;
38
- isDateTime(value: unknown): value is DateTime;
39
- /**
40
- * Create a new UTC DateTime instance.
41
- */
42
- utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
43
- /**
44
- * Create a new DateTime instance.
45
- */
46
- of(date: string | number | Date | Dayjs | null | undefined): DateTime;
47
- /**
48
- * Get the current date as a string.
49
- */
50
- toISOString(date?: Date | string | DateTime): string;
51
- /**
52
- * Get the current date.
53
- */
54
- now(): DateTime;
55
- /**
56
- * Get the current date as a string.
57
- *
58
- * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
59
- */
60
- nowISOString(): string;
61
- /**
62
- * Get the current date as milliseconds since epoch.
63
- *
64
- * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
65
- */
66
- nowMillis(): number;
67
- /**
68
- * Get the current date as a string.
69
- *
70
- * @protected
71
- */
72
- protected getCurrentDate(): DateTime;
73
- /**
74
- * Create a new Duration instance.
75
- */
76
- duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
77
- isDurationLike(value: unknown): value is DurationLike;
78
- /**
79
- * Return a promise that resolves after the next tick.
80
- * It uses `setTimeout` with 0 ms delay.
81
- */
82
- tick(): Promise<void>;
83
- /**
84
- * Wait for a certain duration.
85
- *
86
- * You can clear the timeout by using the `AbortSignal` API.
87
- * Aborted signal will resolve the promise immediately, it does not reject it.
88
- */
89
- wait(duration: DurationLike, options?: {
90
- signal?: AbortSignal;
91
- now?: number;
92
- }): Promise<void>;
93
- createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
94
- /**
95
- * Run a callback after a certain duration.
96
- */
97
- createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
98
- clearTimeout(timeout: Timeout): void;
99
- clearInterval(interval: Interval): void;
100
- /**
101
- * Run a function with a deadline.
102
- */
103
- deadline<T$1>(fn: (signal: AbortSignal) => Promise<T$1>, duration: DurationLike): Promise<T$1>;
104
- /**
105
- * Add time to the current date.
106
- */
107
- travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
108
- /**
109
- * Stop the time.
110
- */
111
- pause(): DateTime;
112
- /**
113
- * Reset the reference date.
114
- */
115
- reset(): void;
116
- }
117
- interface Interval {
118
- timer?: any;
119
- duration: number;
120
- run: () => unknown;
121
- }
122
- interface Timeout {
123
- now: number;
124
- timer?: any;
125
- duration: number;
126
- callback: () => void;
127
- clear: () => void;
128
- }
129
- //#endregion
130
- //#region ../alepha/src/logger/providers/LogDestinationProvider.d.ts
131
- declare abstract class LogDestinationProvider {
132
- abstract write(message: string, entry: LogEntry): void;
133
- }
134
- //#endregion
135
- //#region ../alepha/src/logger/providers/LogFormatterProvider.d.ts
136
- declare abstract class LogFormatterProvider {
137
- abstract format(entry: LogEntry): string;
138
- }
139
- //#endregion
140
- //#region ../alepha/src/logger/services/Logger.d.ts
141
- declare class Logger implements LoggerInterface {
142
- protected readonly alepha: Alepha;
143
- protected readonly formatter: LogFormatterProvider;
144
- protected readonly destination: LogDestinationProvider;
145
- protected readonly dateTimeProvider: DateTimeProvider;
146
- protected readonly levels: Record<string, number>;
147
- protected readonly service: string;
148
- protected readonly module: string;
149
- protected readonly app?: string;
150
- protected appLogLevel: string;
151
- protected logLevel: LogLevel;
152
- constructor(service: string, module: string);
153
- get context(): string | undefined;
154
- get level(): string;
155
- parseLevel(level: string, app: string): LogLevel;
156
- private matchesPattern;
157
- asLogLevel(something: string): LogLevel;
158
- error(message: string, data?: unknown): void;
159
- warn(message: string, data?: unknown): void;
160
- info(message: string, data?: unknown): void;
161
- debug(message: string, data?: unknown): void;
162
- trace(message: string, data?: unknown): void;
163
- protected log(level: LogLevel, message: string, data?: unknown): void;
164
- protected emit(entry: LogEntry, message?: string): void;
165
- }
166
- //#endregion
167
- //#region ../alepha/src/logger/index.d.ts
168
- declare const envSchema$6: alepha84.TObject<{
169
- /**
170
- * Default log level for the application.
171
- *
172
- * Default by environment:
173
- * - dev = info
174
- * - prod = info
175
- * - test = error
176
- *
177
- * Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
178
- *
179
- * Level can be set for a specific module:
180
- *
181
- * @example
182
- * LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
183
- * LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
184
- */
185
- LOG_LEVEL: alepha84.TOptional<alepha84.TString>;
186
- /**
187
- * Built-in log formats.
188
- * - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
189
- * - "pretty" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
190
- * - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
191
- */
192
- LOG_FORMAT: alepha84.TOptional<alepha84.TUnsafe<"json" | "pretty" | "raw">>;
193
- }>;
194
- declare module "alepha" {
195
- interface Env extends Partial<Static<typeof envSchema$6>> {}
196
- interface State {
197
- /**
198
- * Current log level for the application or specific modules.
199
- */
200
- "alepha.logger.level"?: string;
201
- }
202
- interface Hooks {
203
- log: {
204
- message?: string;
205
- entry: LogEntry;
206
- };
207
- }
208
- }
209
- //#endregion
210
- //#region ../alepha/src/server/constants/routeMethods.d.ts
211
- declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
212
- type RouteMethod = (typeof routeMethods)[number];
213
- //#endregion
214
- //#region ../alepha/src/router/providers/RouterProvider.d.ts
215
- declare abstract class RouterProvider<T$1 extends Route = Route> {
216
- protected routePathRegex: RegExp;
217
- protected tree: Tree<T$1>;
218
- protected cache: Map<string, RouteMatch<T$1>>;
219
- match(path: string): RouteMatch<T$1>;
220
- protected test(path: string): void;
221
- protected push(route: T$1): void;
222
- protected createRouteMatch(path: string): RouteMatch<T$1>;
223
- protected mapParams(match: RouteMatch<T$1>): RouteMatch<T$1>;
224
- protected createParts(path: string): string[];
225
- }
226
- interface RouteMatch<T$1 extends Route> {
227
- route?: T$1;
228
- params?: Record<string, string>;
229
- }
230
- interface Route {
231
- path: string;
232
- /**
233
- * Rename a param in the route.
234
- * This is automatically filled when you have scenarios like:
235
- * `/customers/:id` and `/customers/:userId/payments`
236
- *
237
- * In this case, `:id` will be renamed to `:userId` in the second route.
238
- */
239
- mapParams?: Record<string, string>;
240
- }
241
- interface Tree<T$1 extends Route> {
242
- route?: T$1;
243
- children: {
244
- [key: string]: Tree<T$1>;
10
+ //#region src/head/interfaces/Head.d.ts
11
+ interface Head extends SimpleHead {
12
+ description?: string;
13
+ keywords?: string[];
14
+ author?: string;
15
+ robots?: string;
16
+ themeColor?: string;
17
+ viewport?: string | {
18
+ width?: string;
19
+ height?: string;
20
+ initialScale?: string;
21
+ maximumScale?: string;
22
+ userScalable?: "no" | "yes" | "0" | "1";
23
+ interactiveWidget?: "resizes-visual" | "resizes-content" | "overlays-content";
245
24
  };
246
- param?: {
247
- route?: T$1;
248
- name: string;
249
- children: {
250
- [key: string]: Tree<T$1>;
251
- };
25
+ og?: {
26
+ title?: string;
27
+ description?: string;
28
+ image?: string;
29
+ url?: string;
30
+ type?: string;
252
31
  };
253
- wildcard?: {
254
- route: T$1;
32
+ twitter?: {
33
+ card?: string;
34
+ title?: string;
35
+ description?: string;
36
+ image?: string;
37
+ site?: string;
255
38
  };
256
39
  }
40
+ interface SimpleHead {
41
+ title?: string;
42
+ titleSeparator?: string;
43
+ htmlAttributes?: Record<string, string>;
44
+ bodyAttributes?: Record<string, string>;
45
+ meta?: Array<{
46
+ name: string;
47
+ content: string;
48
+ }>;
49
+ }
257
50
  //#endregion
258
- //#region ../alepha/src/server/helpers/ServerReply.d.ts
51
+ //#region src/head/providers/HeadProvider.d.ts
52
+ declare class HeadProvider {
53
+ global?: Head | (() => Head);
54
+ protected getGlobalHead(): Head | undefined;
55
+ fillHead(state: ReactRouterState): void;
56
+ protected fillHeadByPage(page: PageRoute, state: ReactRouterState, props: Record<string, any>): void;
57
+ }
58
+ //#endregion
59
+ //#region src/head/primitives/$head.d.ts
259
60
  /**
260
- * Helper for building server replies.
61
+ * Set global `<head>` options for the application.
261
62
  */
262
- declare class ServerReply {
263
- headers: Record<string, string> & {
264
- "set-cookie"?: string[];
265
- };
266
- status?: number;
267
- body?: any;
268
- /**
269
- * Redirect to a given URL with optional status code (default 302).
270
- */
271
- redirect(url: string, status?: number): void;
272
- /**
273
- * Set the response status code.
274
- */
275
- setStatus(status: number): this;
276
- /**
277
- * Set a response header.
278
- */
279
- setHeader(name: string, value: string): this;
280
- /**
281
- * Set the response body.
282
- */
283
- setBody(body: any): this;
63
+ declare const $head: {
64
+ (options: HeadPrimitiveOptions): HeadPrimitive;
65
+ [KIND]: typeof HeadPrimitive;
66
+ };
67
+ type HeadPrimitiveOptions = Head | (() => Head);
68
+ declare class HeadPrimitive extends Primitive<HeadPrimitiveOptions> {
69
+ protected readonly provider: HeadProvider;
70
+ protected onInit(): void;
284
71
  }
285
72
  //#endregion
286
- //#region ../alepha/src/server/services/UserAgentParser.d.ts
287
- interface UserAgentInfo {
288
- os: "Windows" | "Android" | "Ubuntu" | "MacOS" | "iOS" | "Linux" | "FreeBSD" | "OpenBSD" | "ChromeOS" | "BlackBerry" | "Symbian" | "Windows Phone";
289
- browser: "Chrome" | "Firefox" | "Safari" | "Edge" | "Opera" | "Internet Explorer" | "Brave" | "Vivaldi" | "Samsung Browser" | "UC Browser" | "Yandex";
290
- device: "MOBILE" | "DESKTOP" | "TABLET";
291
- }
73
+ //#region src/head/hooks/useHead.d.ts
292
74
  /**
293
- * Simple User-Agent parser to detect OS, browser, and device type.
294
- * This parser is not exhaustive and may not cover all edge cases.
75
+ * ```tsx
76
+ * const App = () => {
77
+ * const [head, setHead] = useHead({
78
+ * // will set the document title on the first render
79
+ * title: "My App",
80
+ * });
295
81
  *
296
- * Use result for non
82
+ * return (
83
+ * // This will update the document title when the button is clicked
84
+ * <button onClick={() => setHead({ title: "Change Title" })}>
85
+ * Change Title {head.title}
86
+ * </button>
87
+ * );
88
+ * }
89
+ * ```
297
90
  */
298
- declare class UserAgentParser {
299
- parse(userAgent?: string): UserAgentInfo;
300
- }
91
+ declare const useHead: (options?: UseHeadOptions) => UseHeadReturn;
92
+ type UseHeadOptions = Head | ((previous?: Head) => Head);
93
+ type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
301
94
  //#endregion
302
- //#region ../alepha/src/server/interfaces/ServerRequest.d.ts
303
- type TRequestBody = TObject | TString | TArray | TRecord | TStream;
304
- type TResponseBody = TObject | TString | TRecord | TFile | TArray | TStream | TVoid;
305
- interface RequestConfigSchema {
306
- body?: TRequestBody;
307
- params?: TObject;
308
- query?: TObject;
309
- headers?: TObject;
310
- response?: TResponseBody;
311
- }
312
- interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
313
- body: TConfig["body"] extends TRequestBody ? Static<TConfig["body"]> : any;
314
- headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
315
- params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
316
- query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, any>;
317
- }
318
- type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
319
- interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
320
- /**
321
- * HTTP method used for this request.
322
- */
323
- method: RouteMethod;
324
- /**
325
- * Full request URL.
326
- */
327
- url: URL;
328
- /**
329
- * Unique request ID assigned to this request.
330
- */
331
- requestId: string;
332
- /**
333
- * Client IP address.
334
- * Will parse `X-Forwarded-For` header if present.
335
- */
336
- ip?: string;
337
- /**
338
- * Value of the `Host` header sent by the client.
339
- */
340
- host?: string;
341
- /**
342
- * Browser user agent information.
343
- * Information are not guaranteed to be accurate. Use with caution.
344
- *
345
- * @see {@link UserAgentParser}
346
- */
347
- userAgent: UserAgentInfo;
348
- /**
349
- * Arbitrary metadata attached to the request. Can be used by middlewares to store information.
350
- */
351
- metadata: Record<string, any>;
352
- /**
353
- * Reply object to be used to send response.
354
- */
355
- reply: ServerReply;
356
- /**
357
- * The raw underlying request object (Web Request).
358
- */
359
- raw: ServerRawRequest;
360
- }
361
- interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
362
- /**
363
- * Handler function for this route.
364
- */
365
- handler: ServerHandler<TConfig>;
366
- /**
367
- * HTTP method for this route.
368
- */
369
- method?: RouteMethod;
370
- /**
371
- * Request/response schema for this route.
372
- *
373
- * Request schema contains:
374
- * - body, for POST/PUT/PATCH requests
375
- * - params, for URL parameters (e.g. /user/:id)
376
- * - query, for URL query parameters (e.g. /user?id=123)
377
- * - headers, for HTTP headers
378
- *
379
- * Response schema contains:
380
- * - response
381
- *
382
- * Response schema is used to validate and serialize the response sent by the handler.
383
- */
384
- schema?: TConfig;
385
- /**
386
- * @see ServerLoggerProvider
387
- */
388
- silent?: boolean;
95
+ //#region ../alepha/src/server/schemas/errorSchema.d.ts
96
+ declare const errorSchema: alepha30.TObject<{
97
+ error: alepha30.TString;
98
+ status: alepha30.TInteger;
99
+ message: alepha30.TString;
100
+ details: alepha30.TOptional<alepha30.TString>;
101
+ requestId: alepha30.TOptional<alepha30.TString>;
102
+ cause: alepha30.TOptional<alepha30.TObject<{
103
+ name: alepha30.TString;
104
+ message: alepha30.TString;
105
+ }>>;
106
+ }>;
107
+ type ErrorSchema = Static<typeof errorSchema>;
108
+ //#endregion
109
+ //#region ../alepha/src/server/errors/HttpError.d.ts
110
+ declare class HttpError extends AlephaError {
111
+ name: string;
112
+ static is: (error: unknown, status?: number) => error is HttpErrorLike;
113
+ static toJSON(error: HttpError): ErrorSchema;
114
+ readonly error: string;
115
+ readonly status: number;
116
+ readonly requestId?: string;
117
+ readonly details?: string;
118
+ readonly reason?: {
119
+ name: string;
120
+ message: string;
121
+ };
122
+ constructor(options: Partial<ErrorSchema>, cause?: unknown);
389
123
  }
390
- type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TResponseBody ? Static<TConfig["response"]> : ResponseBodyType;
391
- type ResponseKind = "json" | "text" | "void" | "file" | "any";
392
- type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
393
- type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
394
- interface ServerResponse$1 {
395
- body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
396
- headers: Record<string, string>;
124
+ interface HttpErrorLike extends Error {
397
125
  status: number;
398
126
  }
399
- type ServerRouteRequestHandler = (request: ServerRequestData) => Promise<ServerResponse$1>;
400
- interface ServerRouteMatcher extends Route {
401
- handler: ServerRouteRequestHandler;
402
- }
403
- interface ServerRequestData {
404
- method: RouteMethod;
405
- url: URL;
406
- headers: Record<string, string>;
407
- query: Record<string, string>;
408
- params: Record<string, string>;
409
- raw: ServerRawRequest;
410
- }
411
- interface ServerRawRequest {
412
- node?: NodeRequestEvent;
413
- web?: WebRequestEvent;
414
- }
415
- interface NodeRequestEvent {
416
- req: IncomingMessage;
417
- res: ServerResponse;
418
- }
419
- interface WebRequestEvent {
420
- req: Request;
421
- res?: Response;
422
- }
423
127
  //#endregion
424
- //#region ../alepha/src/server/services/ServerRequestParser.d.ts
425
- declare class ServerRequestParser {
426
- protected readonly alepha: Alepha;
427
- protected readonly userAgentParser: UserAgentParser;
428
- createServerRequest(rawRequest: ServerRequestData): ServerRequest;
429
- getRequestId(request: ServerRequestData): string | undefined;
430
- getRequestUserAgent(request: ServerRequestData): UserAgentInfo;
431
- getRequestIp(request: ServerRequestData): string | undefined;
432
- }
433
- //#endregion
434
- //#region ../alepha/src/server/providers/ServerTimingProvider.d.ts
435
- type TimingMap = Record<string, [number, number]>;
436
- declare class ServerTimingProvider {
437
- protected readonly log: Logger;
438
- protected readonly alepha: Alepha;
439
- options: {
440
- prefix: string;
441
- disabled: boolean;
442
- };
443
- readonly onRequest: alepha84.HookDescriptor<"server:onRequest">;
444
- readonly onResponse: alepha84.HookDescriptor<"server:onResponse">;
445
- protected get handlerName(): string;
446
- beginTiming(name: string): void;
447
- endTiming(name: string): void;
448
- protected setDuration(name: string, timing: TimingMap): void;
128
+ //#region ../alepha/src/router/providers/RouterProvider.d.ts
129
+ declare abstract class RouterProvider<T extends Route = Route> {
130
+ protected routePathRegex: RegExp;
131
+ protected tree: Tree<T>;
132
+ protected cache: Map<string, RouteMatch<T>>;
133
+ match(path: string): RouteMatch<T>;
134
+ protected test(path: string): void;
135
+ protected push(route: T): void;
136
+ protected createRouteMatch(path: string): RouteMatch<T>;
137
+ protected mapParams(match: RouteMatch<T>): RouteMatch<T>;
138
+ protected createParts(path: string): string[];
449
139
  }
450
- //#endregion
451
- //#region ../alepha/src/server/providers/ServerRouterProvider.d.ts
452
- /**
453
- * Main router for all routes on the server side.
454
- *
455
- * - $route => generic route
456
- * - $action => action route (for API calls)
457
- * - $page => React route (for SSR)
458
- */
459
- declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
460
- protected readonly log: Logger;
461
- protected readonly alepha: Alepha;
462
- protected readonly routes: ServerRoute[];
463
- protected readonly serverTimingProvider: ServerTimingProvider;
464
- protected readonly serverRequestParser: ServerRequestParser;
140
+ interface RouteMatch<T extends Route> {
141
+ route?: T;
142
+ params?: Record<string, string>;
143
+ }
144
+ interface Route {
145
+ path: string;
465
146
  /**
466
- * Get all registered routes, optionally filtered by a pattern.
147
+ * Rename a param in the route.
148
+ * This is automatically filled when you have scenarios like:
149
+ * `/customers/:id` and `/customers/:userId/payments`
467
150
  *
468
- * Pattern accept simple wildcard '*' at the end.
469
- * Example: '/api/*' will match all routes starting with '/api/' but '/api/' will match only that exact route.
151
+ * In this case, `:id` will be renamed to `:userId` in the second route.
470
152
  */
471
- getRoutes(pattern?: string): ServerRoute[];
472
- createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
473
- protected getContextId(headers: Record<string, string>): string;
474
- protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
475
- status: number;
476
- headers: Record<string, string> & {
477
- "set-cookie"?: string[];
153
+ mapParams?: Record<string, string>;
154
+ }
155
+ interface Tree<T extends Route> {
156
+ route?: T;
157
+ children: {
158
+ [key: string]: Tree<T>;
159
+ };
160
+ param?: {
161
+ route?: T;
162
+ name: string;
163
+ children: {
164
+ [key: string]: Tree<T>;
478
165
  };
479
- body: any;
480
- }>;
481
- protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
482
- serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
483
- protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
484
- protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
485
- validateRequest(route: {
486
- schema?: RequestConfigSchema;
487
- }, request: ServerRequestConfig): void;
166
+ };
167
+ wildcard?: {
168
+ route: T;
169
+ };
488
170
  }
489
171
  //#endregion
490
- //#region ../alepha/src/server/providers/ServerProvider.d.ts
172
+ //#region ../alepha/src/server/constants/routeMethods.d.ts
173
+ declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
174
+ type RouteMethod = (typeof routeMethods)[number];
175
+ //#endregion
176
+ //#region ../alepha/src/server/helpers/ServerReply.d.ts
491
177
  /**
492
- * Base server provider to handle incoming requests and route them.
493
- *
494
- * This is the default implementation for serverless environments.
495
- *
496
- * ServerProvider supports both Node.js HTTP requests and Web (Fetch API) requests.
178
+ * Helper for building server replies.
497
179
  */
498
- declare class ServerProvider {
499
- protected readonly log: Logger;
500
- protected readonly alepha: Alepha;
501
- protected readonly dateTimeProvider: DateTimeProvider;
502
- protected readonly router: ServerRouterProvider;
503
- protected readonly internalServerErrorMessage = "Internal Server Error";
504
- get hostname(): string;
505
- /**
506
- * When a Node.js HTTP request is received from outside. (Vercel, AWS Lambda, etc.)
507
- */
508
- protected readonly onNodeRequest: alepha84.HookDescriptor<"node:request">;
180
+ declare class ServerReply {
181
+ headers: Record<string, string> & {
182
+ "set-cookie"?: string[];
183
+ };
184
+ status?: number;
185
+ body?: any;
509
186
  /**
510
- * When a Web (Fetch API) request is received from outside. (Netlify, Cloudflare Workers, etc.)
187
+ * Redirect to a given URL with optional status code (default 302).
511
188
  */
512
- protected readonly onWebRequest: alepha84.HookDescriptor<"web:request">;
189
+ redirect(url: string, status?: number): void;
513
190
  /**
514
- * Handle Node.js HTTP request event.
515
- *
516
- * Technically, we just convert Node.js request to Web Standard Request.
191
+ * Set the response status code.
517
192
  */
518
- handleNodeRequest(nodeRequestEvent: NodeRequestEvent): Promise<void>;
193
+ setStatus(status: number): this;
519
194
  /**
520
- * Handle Web (Fetch API) request event.
195
+ * Set a response header.
521
196
  */
522
- handleWebRequest(ev: WebRequestEvent): Promise<void>;
197
+ setHeader(name: string, value: string): this;
523
198
  /**
524
- * Helper for Vite development mode to let Vite handle (or not) 404.
199
+ * Set the response body.
525
200
  */
526
- protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
201
+ setBody(body: any): this;
527
202
  }
528
203
  //#endregion
529
- //#region ../alepha/src/cache/providers/CacheProvider.d.ts
204
+ //#region ../alepha/src/server/services/UserAgentParser.d.ts
205
+ interface UserAgentInfo {
206
+ os: "Windows" | "Android" | "Ubuntu" | "MacOS" | "iOS" | "Linux" | "FreeBSD" | "OpenBSD" | "ChromeOS" | "BlackBerry" | "Symbian" | "Windows Phone";
207
+ browser: "Chrome" | "Firefox" | "Safari" | "Edge" | "Opera" | "Internet Explorer" | "Brave" | "Vivaldi" | "Samsung Browser" | "UC Browser" | "Yandex";
208
+ device: "MOBILE" | "DESKTOP" | "TABLET";
209
+ }
530
210
  /**
531
- * Cache provider interface.
211
+ * Simple User-Agent parser to detect OS, browser, and device type.
212
+ * This parser is not exhaustive and may not cover all edge cases.
532
213
  *
533
- * All methods are asynchronous and return promises.
534
- * Values are stored as Uint8Array.
214
+ * Use result for non
535
215
  */
536
- declare abstract class CacheProvider {
537
- /**
538
- * Get the value of a key.
539
- *
540
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
541
- * @param key The key of the value to get.
542
- *
543
- * @return The value of the key, or undefined if the key does not exist.
544
- */
545
- abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
216
+ declare class UserAgentParser {
217
+ parse(userAgent?: string): UserAgentInfo;
218
+ }
219
+ //#endregion
220
+ //#region ../alepha/src/server/interfaces/ServerRequest.d.ts
221
+ type TRequestBody = TObject | TString | TArray | TRecord | TStream;
222
+ type TResponseBody = TObject | TString | TRecord | TFile | TArray | TStream | TVoid;
223
+ interface RequestConfigSchema {
224
+ body?: TRequestBody;
225
+ params?: TObject;
226
+ query?: TObject;
227
+ headers?: TObject;
228
+ response?: TResponseBody;
229
+ }
230
+ interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
231
+ body: TConfig["body"] extends TRequestBody ? Static<TConfig["body"]> : any;
232
+ headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
233
+ params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
234
+ query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, any>;
235
+ }
236
+ type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
237
+ interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
546
238
  /**
547
- * Set the string value of a key.
548
- *
549
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
550
- * @param key The key of the value to set.
551
- * @param value The value to set.
552
- * @param ttl The time-to-live of the key, in milliseconds.
553
- *
554
- * @return The value of the key.
239
+ * HTTP method used for this request.
555
240
  */
556
- abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
241
+ method: RouteMethod;
557
242
  /**
558
- * Remove the specified keys.
559
- *
560
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
561
- * @param keys The keys to delete.
243
+ * Full request URL.
562
244
  */
563
- abstract del(name: string, ...keys: string[]): Promise<void>;
564
- abstract has(name: string, key: string): Promise<boolean>;
565
- abstract keys(name: string, filter?: string): Promise<string[]>;
245
+ url: URL;
566
246
  /**
567
- * Remove all keys from all cache names.
247
+ * Unique request ID assigned to this request.
568
248
  */
569
- abstract clear(): Promise<void>;
570
- }
571
- //#endregion
572
- //#region ../alepha/src/cache/descriptors/$cache.d.ts
573
- interface CacheDescriptorOptions<TReturn = any, TParameter extends any[] = any[]> {
249
+ requestId: string;
574
250
  /**
575
- * The cache name. This is useful for invalidating multiple caches at once.
576
- *
577
- * Store key as `cache:$name:$key`.
578
- *
579
- * @default Name of the key of the class.
251
+ * Client IP address.
252
+ * Will parse `X-Forwarded-For` header if present.
580
253
  */
581
- name?: string;
254
+ ip?: string;
582
255
  /**
583
- * Function which returns cached data.
256
+ * Value of the `Host` header sent by the client.
584
257
  */
585
- handler?: (...args: TParameter) => TReturn;
258
+ host?: string;
586
259
  /**
587
- * The key generator for the cache.
588
- * If not provided, the arguments will be json.stringify().
260
+ * Browser user agent information.
261
+ * Information are not guaranteed to be accurate. Use with caution.
262
+ *
263
+ * @see {@link UserAgentParser}
589
264
  */
590
- key?: (...args: TParameter) => string;
265
+ userAgent: UserAgentInfo;
591
266
  /**
592
- * The store provider for the cache.
593
- * If not provided, the default store provider will be used.
267
+ * Arbitrary metadata attached to the request. Can be used by middlewares to store information.
594
268
  */
595
- provider?: InstantiableClass<CacheProvider> | "memory";
269
+ metadata: Record<string, any>;
596
270
  /**
597
- * The time-to-live for the cache in seconds.
598
- * Set 0 to skip expiration.
599
- *
600
- * @default 300 (5 minutes).
271
+ * Reply object to be used to send response.
601
272
  */
602
- ttl?: DurationLike;
273
+ reply: ServerReply;
603
274
  /**
604
- * If the cache is disabled.
275
+ * The raw underlying request object (Web Request).
605
276
  */
606
- disabled?: boolean;
607
- }
608
- declare class CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> extends Descriptor<CacheDescriptorOptions<TReturn, TParameter>> {
609
- protected readonly env: {
610
- CACHE_ENABLED: boolean;
611
- CACHE_DEFAULT_TTL: number;
612
- };
613
- protected readonly dateTimeProvider: DateTimeProvider;
614
- protected readonly provider: CacheProvider;
615
- protected encoder: TextEncoder;
616
- protected decoder: TextDecoder;
617
- protected codes: {
618
- BINARY: number;
619
- JSON: number;
620
- STRING: number;
621
- };
622
- get container(): string;
623
- run(...args: TParameter): Promise<TReturn>;
624
- key(...args: TParameter): string;
625
- invalidate(...keys: string[]): Promise<void>;
626
- set(key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
627
- get(key: string): Promise<TReturn | undefined>;
628
- protected serialize<TReturn>(value: TReturn): Uint8Array;
629
- protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
630
- protected $provider(): CacheProvider;
277
+ raw: ServerRawRequest;
631
278
  }
632
- interface CacheDescriptorFn<TReturn = any, TParameter extends any[] = any[]> extends CacheDescriptor<TReturn, TParameter> {
279
+ interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
633
280
  /**
634
- * Run the cache descriptor with the provided arguments.
281
+ * Handler function for this route.
635
282
  */
636
- (...args: TParameter): Promise<TReturn>;
637
- }
638
- //#endregion
639
- //#region ../alepha/src/server/services/HttpClient.d.ts
640
- declare class HttpClient {
641
- protected readonly log: Logger;
642
- protected readonly alepha: Alepha;
643
- readonly cache: CacheDescriptorFn<HttpClientCache, any[]>;
644
- protected readonly pendingRequests: HttpClientPendingRequests;
645
- fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
646
- fetch<T$1 extends TSchema>(url: string, request?: RequestInitWithOptions<T$1>): Promise<FetchResponse<Static<T$1>>>;
647
- protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
648
- protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
649
- protected responseData(response: Response, options: FetchOptions): Promise<any>;
650
- protected isMaybeFile(response: Response): boolean;
651
- protected createFileLike(response: Response, defaultFileName?: string): FileLike;
652
- pathVariables(url: string, action: {
653
- schema?: {
654
- params?: TObject;
655
- };
656
- }, args?: ServerRequestConfigEntry): string;
657
- queryParams(url: string, action: {
658
- schema?: {
659
- query?: TObject;
660
- };
661
- }, args?: ServerRequestConfigEntry): string;
662
- }
663
- interface FetchOptions<T$1 extends TSchema = TSchema> {
283
+ handler: ServerHandler<TConfig>;
664
284
  /**
665
- * Key to identify the request in the pending requests.
285
+ * HTTP method for this route.
666
286
  */
667
- key?: string;
287
+ method?: RouteMethod;
668
288
  /**
669
- * The schema to validate the response against.
289
+ * Request/response schema for this route.
290
+ *
291
+ * Request schema contains:
292
+ * - body, for POST/PUT/PATCH requests
293
+ * - params, for URL parameters (e.g. /user/:id)
294
+ * - query, for URL query parameters (e.g. /user?id=123)
295
+ * - headers, for HTTP headers
296
+ *
297
+ * Response schema contains:
298
+ * - response
299
+ *
300
+ * Response schema is used to validate and serialize the response sent by the handler.
670
301
  */
671
- schema?: {
672
- response?: T$1;
673
- };
302
+ schema?: TConfig;
674
303
  /**
675
- * Built-in cache options.
304
+ * @see ServerLoggerProvider
676
305
  */
677
- localCache?: boolean | number | DurationLike;
306
+ silent?: boolean;
678
307
  }
679
- type RequestInitWithOptions<T$1 extends TSchema = TSchema> = RequestInit & FetchOptions<T$1>;
680
- interface FetchResponse<T$1 = any> {
681
- data: T$1;
308
+ type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TResponseBody ? Static<TConfig["response"]> : ResponseBodyType;
309
+ type ResponseKind = "json" | "text" | "void" | "file" | "any";
310
+ type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
311
+ type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
312
+ interface ServerResponse$1 {
313
+ body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
314
+ headers: Record<string, string>;
682
315
  status: number;
683
- statusText: string;
684
- headers: Headers;
685
- raw?: Response;
686
316
  }
687
- type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
688
- interface HttpClientCache {
689
- data: any;
690
- etag?: string;
317
+ type ServerRouteRequestHandler = (request: ServerRequestData) => Promise<ServerResponse$1>;
318
+ interface ServerRouteMatcher extends Route {
319
+ handler: ServerRouteRequestHandler;
691
320
  }
692
- interface FetchActionArgs {
693
- action: HttpAction;
694
- host?: string;
695
- config?: ServerRequestConfigEntry;
696
- options?: ClientRequestOptions;
321
+ interface ServerRequestData {
322
+ method: RouteMethod;
323
+ url: URL;
324
+ headers: Record<string, string>;
325
+ query: Record<string, string>;
326
+ params: Record<string, string>;
327
+ raw: ServerRawRequest;
697
328
  }
698
- interface HttpAction {
699
- method?: string;
700
- prefix?: string;
701
- path: string;
702
- requestBodyType?: string;
703
- schema?: {
704
- params?: TObject;
705
- query?: TObject;
706
- body?: TRequestBody;
707
- response?: TResponseBody;
708
- };
329
+ interface ServerRawRequest {
330
+ node?: NodeRequestEvent;
331
+ web?: WebRequestEvent;
332
+ }
333
+ interface NodeRequestEvent {
334
+ req: IncomingMessage;
335
+ res: ServerResponse;
336
+ }
337
+ interface WebRequestEvent {
338
+ req: Request;
339
+ res?: Response;
709
340
  }
710
341
  //#endregion
711
- //#region ../alepha/src/server/descriptors/$action.d.ts
712
- interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
713
- /**
714
- * Name of the action.
715
- *
716
- * - It will be used to generate the route path if `path` is not provided.
717
- * - It will be used to generate the permission name if `security` is enabled.
718
- */
719
- name?: string;
720
- /**
721
- * Group actions together.
722
- *
723
- * - If not provided, the service name containing the route will be used.
724
- * - It will be used as Tag for documentation purposes.
725
- * - It will be used for permission name generation if `security` is enabled.
726
- *
727
- * @example
728
- * ```ts
729
- * // group = "MyController"
730
- * class MyController {
731
- * hello = $action({ handler: () => "Hello World" });
732
- * }
733
- *
734
- * // group = "users"
735
- * class MyOtherController {
736
- * group = "users";
737
- * a1 = $action({ handler: () => "Action 1", group: this.group });
738
- * a2 = $action({ handler: () => "Action 2", group: this.group });
739
- * }
740
- * ```
741
- */
742
- group?: string;
342
+ //#region ../alepha/src/logger/schemas/logEntrySchema.d.ts
343
+ declare const logEntrySchema: alepha30.TObject<{
344
+ level: alepha30.TUnsafe<"TRACE" | "SILENT" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
345
+ message: alepha30.TString;
346
+ service: alepha30.TString;
347
+ module: alepha30.TString;
348
+ context: alepha30.TOptional<alepha30.TString>;
349
+ app: alepha30.TOptional<alepha30.TString>;
350
+ data: alepha30.TOptional<alepha30.TAny>;
351
+ timestamp: alepha30.TNumber;
352
+ }>;
353
+ type LogEntry = Static<typeof logEntrySchema>;
354
+ //#endregion
355
+ //#region ../alepha/src/datetime/providers/DateTimeProvider.d.ts
356
+ type DateTime = DayjsApi.Dayjs;
357
+ type Duration = dayjsDuration.Duration;
358
+ type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
359
+ declare class DateTimeProvider {
360
+ static PLUGINS: Array<PluginFunc<any>>;
361
+ protected alepha: Alepha;
362
+ protected ref: DateTime | null;
363
+ protected readonly timeouts: Timeout[];
364
+ protected readonly intervals: Interval[];
365
+ constructor();
366
+ protected readonly onStart: alepha30.HookPrimitive<"start">;
367
+ protected readonly onStop: alepha30.HookPrimitive<"stop">;
368
+ setLocale(locale: string): void;
369
+ isDateTime(value: unknown): value is DateTime;
743
370
  /**
744
- * Pathname of the route. If not provided, property key is used.
371
+ * Create a new UTC DateTime instance.
745
372
  */
746
- path?: string;
373
+ utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
747
374
  /**
748
- * The route method.
749
- *
750
- * - If not provided, it will be set to "GET" by default.
751
- * - If not provider and a body is provided, it will be set to "POST".
752
- *
753
- * Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
375
+ * Create a new DateTime instance.
754
376
  */
755
- method?: RouteMethod;
377
+ of(date: string | number | Date | Dayjs | null | undefined): DateTime;
756
378
  /**
757
- * The config schema of the route.
758
- * - body: The request body schema.
759
- * - params: Path variables schema.
760
- * - query: The request query-params schema.
761
- * - response: The response schema.
379
+ * Get the current date as a string.
762
380
  */
763
- schema?: TConfig;
381
+ toISOString(date?: Date | string | DateTime): string;
764
382
  /**
765
- * A short description of the action. Used for documentation purposes.
383
+ * Get the current date.
766
384
  */
767
- description?: string;
385
+ now(): DateTime;
768
386
  /**
769
- * Disable the route. Useful with env variables do disable one specific route.
770
- * Route won't be available in the API but can still be called locally!
387
+ * Get the current date as a string.
388
+ *
389
+ * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
771
390
  */
772
- disabled?: boolean;
391
+ nowISOString(): string;
773
392
  /**
774
- * Main route handler. This is where the route logic is implemented.
393
+ * Get the current date as milliseconds since epoch.
394
+ *
395
+ * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
775
396
  */
776
- handler: ServerActionHandler<TConfig>;
777
- }
778
- declare class ActionDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<ActionDescriptorOptions<TConfig>> {
779
- protected readonly log: Logger;
780
- protected readonly env: {
781
- SERVER_API_PREFIX: string;
782
- };
783
- protected readonly httpClient: HttpClient;
784
- protected readonly serverProvider: ServerProvider;
785
- protected readonly serverRouterProvider: ServerRouterProvider;
786
- protected onInit(): void;
787
- get prefix(): string;
788
- get route(): ServerRoute;
397
+ nowMillis(): number;
789
398
  /**
790
- * Returns the name of the action.
399
+ * Get the current date as a string.
400
+ *
401
+ * @protected
791
402
  */
792
- get name(): string;
403
+ protected getCurrentDate(): DateTime;
793
404
  /**
794
- * Returns the group of the action. (e.g. "orders", "admin", etc.)
405
+ * Create a new Duration instance.
795
406
  */
796
- get group(): string;
407
+ duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
408
+ isDurationLike(value: unknown): value is DurationLike;
797
409
  /**
798
- * Returns the HTTP method of the action.
410
+ * Return a promise that resolves after the next tick.
411
+ * It uses `setTimeout` with 0 ms delay.
799
412
  */
800
- get method(): RouteMethod;
413
+ tick(): Promise<void>;
801
414
  /**
802
- * Returns the path of the action.
415
+ * Wait for a certain duration.
803
416
  *
804
- * Path is prefixed by `/api` by default.
805
- */
806
- get path(): string;
807
- get schema(): TConfig | undefined;
808
- getBodyContentType(): string | undefined;
809
- /**
810
- * Call the action handler directly.
811
- * There is no HTTP layer involved.
417
+ * You can clear the timeout by using the `AbortSignal` API.
418
+ * Aborted signal will resolve the promise immediately, it does not reject it.
812
419
  */
813
- run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
420
+ wait(duration: DurationLike, options?: {
421
+ signal?: AbortSignal;
422
+ now?: number;
423
+ }): Promise<void>;
424
+ createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
814
425
  /**
815
- * Works like `run`, but always fetches (http request) the route.
426
+ * Run a callback after a certain duration.
816
427
  */
817
- fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
818
- }
819
- type ClientRequestEntry<TConfig extends RequestConfigSchema, T$1 = ClientRequestEntryContainer<TConfig>> = { [K in keyof T$1 as T$1[K] extends undefined ? never : K]: T$1[K] };
820
- type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
821
- body: TConfig["body"] extends TObject ? Static<TConfig["body"]> : undefined;
822
- params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : undefined;
823
- headers?: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : undefined;
824
- query?: TConfig["query"] extends TObject ? Partial<Static<TConfig["query"]>> : undefined;
825
- };
826
- interface ClientRequestOptions extends FetchOptions {
428
+ createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
429
+ clearTimeout(timeout: Timeout): void;
430
+ clearInterval(interval: Interval): void;
827
431
  /**
828
- * Standard request fetch options.
829
- */
830
- request?: RequestInit;
831
- }
832
- type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
833
- /**
834
- * Specific handler for server actions.
835
- */
836
- type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
837
- /**
838
- * Server Action Request Interface
839
- *
840
- * Can be extended with module augmentation to add custom properties (like `user` in Server Security).
841
- *
842
- * This is NOT Server Request, but a specific type for actions.
843
- */
844
- interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
845
- //#endregion
846
- //#region ../alepha/src/server/schemas/errorSchema.d.ts
847
- declare const errorSchema: alepha84.TObject<{
848
- error: alepha84.TString;
849
- status: alepha84.TInteger;
850
- message: alepha84.TString;
851
- details: alepha84.TOptional<alepha84.TString>;
852
- requestId: alepha84.TOptional<alepha84.TString>;
853
- cause: alepha84.TOptional<alepha84.TObject<{
854
- name: alepha84.TString;
855
- message: alepha84.TString;
856
- }>>;
857
- }>;
858
- type ErrorSchema = Static<typeof errorSchema>;
859
- //#endregion
860
- //#region ../alepha/src/server/errors/HttpError.d.ts
861
- declare class HttpError extends AlephaError {
862
- name: string;
863
- static is: (error: unknown, status?: number) => error is HttpErrorLike;
864
- static toJSON(error: HttpError): ErrorSchema;
865
- readonly error: string;
866
- readonly status: number;
867
- readonly requestId?: string;
868
- readonly details?: string;
869
- readonly reason?: {
870
- name: string;
871
- message: string;
872
- };
873
- constructor(options: Partial<ErrorSchema>, cause?: unknown);
432
+ * Run a function with a deadline.
433
+ */
434
+ deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
435
+ /**
436
+ * Add time to the current date.
437
+ */
438
+ travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
439
+ /**
440
+ * Stop the time.
441
+ */
442
+ pause(): DateTime;
443
+ /**
444
+ * Reset the reference date.
445
+ */
446
+ reset(): void;
874
447
  }
875
- interface HttpErrorLike extends Error {
876
- status: number;
448
+ interface Interval {
449
+ timer?: any;
450
+ duration: number;
451
+ run: () => unknown;
452
+ }
453
+ interface Timeout {
454
+ now: number;
455
+ timer?: any;
456
+ duration: number;
457
+ callback: () => void;
458
+ clear: () => void;
877
459
  }
878
460
  //#endregion
879
- //#region ../alepha/src/server/providers/BunHttpServerProvider.d.ts
880
- declare const envSchema$5: alepha84.TObject<{
881
- SERVER_PORT: alepha84.TInteger;
882
- SERVER_HOST: alepha84.TString;
883
- }>;
884
- declare module "alepha" {
885
- interface Env extends Partial<Static<typeof envSchema$5>> {}
461
+ //#region ../alepha/src/logger/providers/LogDestinationProvider.d.ts
462
+ declare abstract class LogDestinationProvider {
463
+ abstract write(message: string, entry: LogEntry): void;
886
464
  }
887
465
  //#endregion
888
- //#region ../alepha/src/server/providers/NodeHttpServerProvider.d.ts
889
- declare const envSchema$4: alepha84.TObject<{
890
- SERVER_PORT: alepha84.TInteger;
891
- SERVER_HOST: alepha84.TString;
892
- }>;
893
- declare module "alepha" {
894
- interface Env extends Partial<Static<typeof envSchema$4>> {}
466
+ //#region ../alepha/src/logger/providers/LogFormatterProvider.d.ts
467
+ declare abstract class LogFormatterProvider {
468
+ abstract format(entry: LogEntry): string;
895
469
  }
896
470
  //#endregion
897
- //#region ../alepha/src/server/index.d.ts
471
+ //#region ../alepha/src/logger/services/Logger.d.ts
472
+ declare class Logger implements LoggerInterface {
473
+ protected readonly alepha: Alepha;
474
+ protected readonly formatter: LogFormatterProvider;
475
+ protected readonly destination: LogDestinationProvider;
476
+ protected readonly dateTimeProvider: DateTimeProvider;
477
+ protected readonly levels: Record<string, number>;
478
+ protected readonly service: string;
479
+ protected readonly module: string;
480
+ protected readonly app?: string;
481
+ protected appLogLevel: string;
482
+ protected logLevel: LogLevel;
483
+ constructor(service: string, module: string);
484
+ get context(): string | undefined;
485
+ get level(): string;
486
+ parseLevel(level: string, app: string): LogLevel;
487
+ private matchesPattern;
488
+ asLogLevel(something: string): LogLevel;
489
+ error(message: string, data?: unknown): void;
490
+ warn(message: string, data?: unknown): void;
491
+ info(message: string, data?: unknown): void;
492
+ debug(message: string, data?: unknown): void;
493
+ trace(message: string, data?: unknown): void;
494
+ protected log(level: LogLevel, message: string, data?: unknown): void;
495
+ protected emit(entry: LogEntry, message?: string): void;
496
+ }
497
+ //#endregion
498
+ //#region ../alepha/src/logger/index.d.ts
499
+ declare const envSchema$2: alepha30.TObject<{
500
+ /**
501
+ * Default log level for the application.
502
+ *
503
+ * Default by environment:
504
+ * - dev = info
505
+ * - prod = info
506
+ * - test = error
507
+ *
508
+ * Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
509
+ *
510
+ * Level can be set for a specific module:
511
+ *
512
+ * @example
513
+ * LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
514
+ * LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
515
+ */
516
+ LOG_LEVEL: alepha30.TOptional<alepha30.TString>;
517
+ /**
518
+ * Built-in log formats.
519
+ * - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
520
+ * - "pretty" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
521
+ * - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
522
+ */
523
+ LOG_FORMAT: alepha30.TOptional<alepha30.TUnsafe<"json" | "pretty" | "raw">>;
524
+ }>;
898
525
  declare module "alepha" {
526
+ interface Env extends Partial<Static<typeof envSchema$2>> {}
899
527
  interface State {
900
- "alepha.node.server"?: Server;
528
+ /**
529
+ * Current log level for the application or specific modules.
530
+ */
531
+ "alepha.logger.level"?: string;
901
532
  }
902
533
  interface Hooks {
903
- "action:onRequest": {
904
- action: ActionDescriptor<RequestConfigSchema>;
905
- request: ServerRequest;
906
- options: ClientRequestOptions;
907
- };
908
- "action:onResponse": {
909
- action: ActionDescriptor<RequestConfigSchema>;
910
- request: ServerRequest;
911
- options: ClientRequestOptions;
912
- response: any;
913
- };
914
- "server:onRequest": {
915
- route: ServerRoute;
916
- request: ServerRequest;
917
- };
918
- "server:onError": {
919
- route: ServerRoute;
920
- request: ServerRequest;
921
- error: Error;
922
- };
923
- "server:onSend": {
924
- route: ServerRoute;
925
- request: ServerRequest;
926
- };
927
- "server:onResponse": {
928
- route: ServerRoute;
929
- request: ServerRequest;
930
- response: ServerResponse$1;
931
- };
932
- "client:onRequest": {
933
- route: HttpAction;
934
- config: ServerRequestConfigEntry;
935
- options: ClientRequestOptions;
936
- headers: Record<string, string>;
937
- request: RequestInit;
938
- };
939
- "client:beforeFetch": {
940
- url: string;
941
- options: FetchOptions;
942
- request: RequestInit;
943
- };
944
- "client:onError": {
945
- route?: HttpAction;
946
- error: HttpError;
534
+ log: {
535
+ message?: string;
536
+ entry: LogEntry;
947
537
  };
948
- "node:request": NodeRequestEvent;
949
- "web:request": WebRequestEvent;
950
538
  }
951
539
  }
952
540
  //#endregion
953
- //#region ../alepha/src/server-cache/providers/ServerCacheProvider.d.ts
954
- declare module "alepha/server" {
955
- interface ServerRoute {
956
- /**
957
- * Enable caching for this route.
958
- * - If true: enables both store and etag
959
- * - If object: fine-grained control over store, etag, and cache-control headers
960
- *
961
- * @default false
962
- */
963
- cache?: ServerRouteCache;
964
- }
965
- interface ActionDescriptor<TConfig extends RequestConfigSchema> {
966
- invalidate: () => Promise<void>;
967
- }
541
+ //#region ../alepha/src/server/services/ServerRequestParser.d.ts
542
+ declare class ServerRequestParser {
543
+ protected readonly alepha: Alepha;
544
+ protected readonly userAgentParser: UserAgentParser;
545
+ createServerRequest(rawRequest: ServerRequestData): ServerRequest;
546
+ getRequestId(request: ServerRequestData): string | undefined;
547
+ getRequestUserAgent(request: ServerRequestData): UserAgentInfo;
548
+ getRequestIp(request: ServerRequestData): string | undefined;
968
549
  }
969
- type ServerRouteCache =
970
- /**
971
- * If true, enables caching with:
972
- * - store: true
973
- * - etag: true
974
- */
975
- boolean
550
+ //#endregion
551
+ //#region ../alepha/src/server/providers/ServerTimingProvider.d.ts
552
+ type TimingMap = Record<string, [number, number]>;
553
+ declare class ServerTimingProvider {
554
+ protected readonly log: Logger;
555
+ protected readonly alepha: Alepha;
556
+ options: {
557
+ prefix: string;
558
+ disabled: boolean;
559
+ };
560
+ readonly onRequest: alepha30.HookPrimitive<"server:onRequest">;
561
+ readonly onResponse: alepha30.HookPrimitive<"server:onResponse">;
562
+ protected get handlerName(): string;
563
+ beginTiming(name: string): void;
564
+ endTiming(name: string): void;
565
+ protected setDuration(name: string, timing: TimingMap): void;
566
+ }
567
+ //#endregion
568
+ //#region ../alepha/src/server/providers/ServerRouterProvider.d.ts
976
569
  /**
977
- * Object configuration for fine-grained cache control.
570
+ * Main router for all routes on the server side.
978
571
  *
979
- * If empty, no caching will be applied.
980
- */ | {
572
+ * - $route => generic route
573
+ * - $action => action route (for API calls)
574
+ * - $page => React route (for SSR)
575
+ */
576
+ declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
577
+ protected readonly log: Logger;
578
+ protected readonly alepha: Alepha;
579
+ protected readonly routes: ServerRoute[];
580
+ protected readonly serverTimingProvider: ServerTimingProvider;
581
+ protected readonly serverRequestParser: ServerRequestParser;
981
582
  /**
982
- * If true, enables storing cached responses. (in-memory, Redis, @see alepha/cache for other providers)
983
- * If a DurationLike is provided, it will be used as the TTL for the cache.
984
- * If CacheDescriptorOptions is provided, it will be used to configure the cache storage.
583
+ * Get all registered routes, optionally filtered by a pattern.
985
584
  *
986
- * @default false
987
- */
988
- store?: true | DurationLike | CacheDescriptorOptions;
989
- /**
990
- * If true, enables ETag support for the cached responses.
991
- */
992
- etag?: true;
993
- /**
994
- * - If true, sets Cache-Control to "public, max-age=300" (5 minutes).
995
- * - If string, sets Cache-Control to the provided value directly.
996
- * - If object, configures Cache-Control directives.
585
+ * Pattern accept simple wildcard '*' at the end.
586
+ * Example: '/api/*' will match all routes starting with '/api/' but '/api/' will match only that exact route.
997
587
  */
998
- control?: true
999
- /**
1000
- * If string, sets Cache-Control to the provided value directly.
1001
- */ | string
1002
- /**
1003
- * If object, configures Cache-Control directives.
1004
- */ | {
1005
- /**
1006
- * Indicates that the response may be cached by any cache.
1007
- */
1008
- public?: boolean;
1009
- /**
1010
- * Indicates that the response is intended for a single user and must not be stored by a shared cache.
1011
- */
1012
- private?: boolean;
1013
- /**
1014
- * Forces caches to submit the request to the origin server for validation before releasing a cached copy.
1015
- */
1016
- noCache?: boolean;
1017
- /**
1018
- * Instructs caches not to store the response.
1019
- */
1020
- noStore?: boolean;
1021
- /**
1022
- * Maximum amount of time a resource is considered fresh.
1023
- * Can be specified as a number (seconds) or as a DurationLike object.
1024
- *
1025
- * @example 300 // 5 minutes in seconds
1026
- * @example { minutes: 5 } // 5 minutes
1027
- * @example { hours: 1 } // 1 hour
1028
- */
1029
- maxAge?: number | DurationLike;
1030
- /**
1031
- * Overrides max-age for shared caches (e.g., CDNs).
1032
- * Can be specified as a number (seconds) or as a DurationLike object.
1033
- */
1034
- sMaxAge?: number | DurationLike;
1035
- /**
1036
- * Indicates that once a resource becomes stale, caches must not use it without successful validation.
1037
- */
1038
- mustRevalidate?: boolean;
1039
- /**
1040
- * Similar to must-revalidate, but only for shared caches.
1041
- */
1042
- proxyRevalidate?: boolean;
1043
- /**
1044
- * Indicates that the response can be stored but must be revalidated before each use.
1045
- */
1046
- immutable?: boolean;
1047
- };
1048
- };
1049
- //#endregion
1050
- //#region src/core/components/ClientOnly.d.ts
1051
- interface ClientOnlyProps {
1052
- fallback?: ReactNode;
1053
- disabled?: boolean;
588
+ getRoutes(pattern?: string): ServerRoute[];
589
+ createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
590
+ protected getContextId(headers: Record<string, string>): string;
591
+ protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
592
+ status: number;
593
+ headers: Record<string, string> & {
594
+ "set-cookie"?: string[];
595
+ };
596
+ body: any;
597
+ }>;
598
+ protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
599
+ serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
600
+ protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
601
+ protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
602
+ validateRequest(route: {
603
+ schema?: RequestConfigSchema;
604
+ }, request: ServerRequestConfig): void;
1054
605
  }
1055
606
  //#endregion
1056
- //#region src/core/errors/Redirection.d.ts
607
+ //#region ../alepha/src/server/providers/ServerProvider.d.ts
1057
608
  /**
1058
- * Used for Redirection during the page loading.
609
+ * Base server provider to handle incoming requests and route them.
1059
610
  *
1060
- * Depends on the context, it can be thrown or just returned.
611
+ * This is the default implementation for serverless environments.
612
+ *
613
+ * ServerProvider supports both Node.js HTTP requests and Web (Fetch API) requests.
1061
614
  */
1062
- declare class Redirection extends Error {
1063
- readonly redirect: string;
1064
- constructor(redirect: string);
1065
- }
1066
- //#endregion
1067
- //#region src/core/providers/ReactPageProvider.d.ts
1068
- declare const envSchema$3: alepha84.TObject<{
1069
- REACT_STRICT_MODE: alepha84.TBoolean;
1070
- }>;
1071
- declare module "alepha" {
1072
- interface Env extends Partial<Static<typeof envSchema$3>> {}
1073
- }
1074
- interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
1075
- children?: PageRouteEntry[];
1076
- }
1077
- interface PageRoute extends PageRouteEntry {
1078
- type: "page";
1079
- name: string;
1080
- parent?: PageRoute;
1081
- match: string;
1082
- }
1083
- interface Layer {
1084
- config?: {
1085
- query?: Record<string, any>;
1086
- params?: Record<string, any>;
1087
- context?: Record<string, any>;
1088
- };
1089
- name: string;
1090
- props?: Record<string, any>;
1091
- error?: Error;
1092
- part?: string;
1093
- element: ReactNode;
1094
- index: number;
1095
- path: string;
1096
- route?: PageRoute;
1097
- cache?: boolean;
1098
- }
1099
- type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
1100
- interface ReactRouterState {
1101
- /**
1102
- * Stack of layers for the current page.
1103
- */
1104
- layers: Array<Layer>;
615
+ declare class ServerProvider {
616
+ protected readonly log: Logger;
617
+ protected readonly alepha: Alepha;
618
+ protected readonly dateTimeProvider: DateTimeProvider;
619
+ protected readonly router: ServerRouterProvider;
620
+ protected readonly internalServerErrorMessage = "Internal Server Error";
621
+ get hostname(): string;
1105
622
  /**
1106
- * URL of the current page.
623
+ * When a Node.js HTTP request is received from outside. (Vercel, AWS Lambda, etc.)
1107
624
  */
1108
- url: URL;
625
+ protected readonly onNodeRequest: alepha30.HookPrimitive<"node:request">;
1109
626
  /**
1110
- * Error handler for the current page.
627
+ * When a Web (Fetch API) request is received from outside. (Netlify, Cloudflare Workers, etc.)
1111
628
  */
1112
- onError: ErrorHandler;
629
+ protected readonly onWebRequest: alepha30.HookPrimitive<"web:request">;
1113
630
  /**
1114
- * Params extracted from the URL for the current page.
631
+ * Handle Node.js HTTP request event.
632
+ *
633
+ * Technically, we just convert Node.js request to Web Standard Request.
1115
634
  */
1116
- params: Record<string, any>;
635
+ handleNodeRequest(nodeRequestEvent: NodeRequestEvent): Promise<void>;
1117
636
  /**
1118
- * Query parameters extracted from the URL for the current page.
637
+ * Handle Web (Fetch API) request event.
1119
638
  */
1120
- query: Record<string, string>;
639
+ handleWebRequest(ev: WebRequestEvent): Promise<void>;
1121
640
  /**
1122
- * Optional meta information associated with the current page.
641
+ * Helper for Vite development mode to let Vite handle (or not) 404.
1123
642
  */
1124
- meta: Record<string, any>;
1125
- }
1126
- //#endregion
1127
- //#region src/core/services/ReactPageService.d.ts
1128
- declare class ReactPageService {
1129
- fetch(pathname: string, options?: PageDescriptorRenderOptions): Promise<{
1130
- html: string;
1131
- response: Response;
1132
- }>;
1133
- render(name: string, options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
643
+ protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
1134
644
  }
1135
645
  //#endregion
1136
- //#region src/core/descriptors/$page.d.ts
1137
- interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
646
+ //#region ../alepha/src/cache/providers/CacheProvider.d.ts
647
+ /**
648
+ * Cache provider interface.
649
+ *
650
+ * All methods are asynchronous and return promises.
651
+ * Values are stored as Uint8Array.
652
+ */
653
+ declare abstract class CacheProvider {
1138
654
  /**
1139
- * Identifier name for the page. Must be unique.
655
+ * Get the value of a key.
1140
656
  *
1141
- * @default Descriptor key
657
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
658
+ * @param key The key of the value to get.
659
+ *
660
+ * @return The value of the key, or undefined if the key does not exist.
1142
661
  */
1143
- name?: string;
662
+ abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
1144
663
  /**
1145
- * Add a pathname to the page.
664
+ * Set the string value of a key.
1146
665
  *
1147
- * Pathname can contain parameters, like `/post/:slug`.
666
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
667
+ * @param key The key of the value to set.
668
+ * @param value The value to set.
669
+ * @param ttl The time-to-live of the key, in milliseconds.
1148
670
  *
1149
- * @default ""
671
+ * @return The value of the key.
1150
672
  */
1151
- path?: string;
673
+ abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
1152
674
  /**
1153
- * Add an input schema to define:
1154
- * - `params`: parameters from the pathname.
1155
- * - `query`: query parameters from the URL.
675
+ * Remove the specified keys.
676
+ *
677
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
678
+ * @param keys The keys to delete.
1156
679
  */
1157
- schema?: TConfig;
680
+ abstract del(name: string, ...keys: string[]): Promise<void>;
681
+ abstract has(name: string, key: string): Promise<boolean>;
682
+ abstract keys(name: string, filter?: string): Promise<string[]>;
1158
683
  /**
1159
- * Load data before rendering the page.
1160
- *
1161
- * This function receives
1162
- * - the request context and
1163
- * - the parent props (if page has a parent)
1164
- *
1165
- * In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.
684
+ * Remove all keys from all cache names.
685
+ */
686
+ abstract clear(): Promise<void>;
687
+ }
688
+ //#endregion
689
+ //#region ../alepha/src/cache/primitives/$cache.d.ts
690
+ interface CachePrimitiveOptions<TReturn = any, TParameter extends any[] = any[]> {
691
+ /**
692
+ * The cache name. This is useful for invalidating multiple caches at once.
1166
693
  *
1167
- * Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.
1168
- * It's common to throw a `NotFoundError` to display a 404 page.
694
+ * Store key as `cache:$name:$key`.
1169
695
  *
1170
- * RedirectError can be thrown to redirect the user to another page.
696
+ * @default Name of the key of the class.
1171
697
  */
1172
- resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;
698
+ name?: string;
1173
699
  /**
1174
- * The component to render when the page is loaded.
1175
- *
1176
- * If `lazy` is defined, this will be ignored.
1177
- * Prefer using `lazy` to improve the initial loading time.
700
+ * Function which returns cached data.
1178
701
  */
1179
- component?: FC<TProps & TPropsParent>;
702
+ handler?: (...args: TParameter) => TReturn;
703
+ /**
704
+ * The key generator for the cache.
705
+ * If not provided, the arguments will be json.stringify().
706
+ */
707
+ key?: (...args: TParameter) => string;
708
+ /**
709
+ * The store provider for the cache.
710
+ * If not provided, the default store provider will be used.
711
+ */
712
+ provider?: InstantiableClass<CacheProvider> | "memory";
1180
713
  /**
1181
- * Lazy load the component when the page is loaded.
714
+ * The time-to-live for the cache in seconds.
715
+ * Set 0 to skip expiration.
1182
716
  *
1183
- * It's recommended to use this for components to improve the initial loading time
1184
- * and enable code-splitting.
717
+ * @default 300 (5 minutes).
1185
718
  */
1186
- lazy?: () => Promise<{
1187
- default: FC<TProps & TPropsParent>;
1188
- }>;
719
+ ttl?: DurationLike;
720
+ /**
721
+ * If the cache is disabled.
722
+ */
723
+ disabled?: boolean;
724
+ }
725
+ declare class CachePrimitive<TReturn = any, TParameter extends any[] = any[]> extends Primitive<CachePrimitiveOptions<TReturn, TParameter>> {
726
+ protected readonly env: {
727
+ CACHE_ENABLED: boolean;
728
+ CACHE_DEFAULT_TTL: number;
729
+ };
730
+ protected readonly dateTimeProvider: DateTimeProvider;
731
+ protected readonly provider: CacheProvider;
732
+ protected encoder: TextEncoder;
733
+ protected decoder: TextDecoder;
734
+ protected codes: {
735
+ BINARY: number;
736
+ JSON: number;
737
+ STRING: number;
738
+ };
739
+ get container(): string;
740
+ run(...args: TParameter): Promise<TReturn>;
741
+ key(...args: TParameter): string;
742
+ invalidate(...keys: string[]): Promise<void>;
743
+ set(key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
744
+ get(key: string): Promise<TReturn | undefined>;
745
+ protected serialize<TReturn>(value: TReturn): Uint8Array;
746
+ protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
747
+ protected $provider(): CacheProvider;
748
+ }
749
+ interface CachePrimitiveFn<TReturn = any, TParameter extends any[] = any[]> extends CachePrimitive<TReturn, TParameter> {
750
+ /**
751
+ * Run the cache primitive with the provided arguments.
752
+ */
753
+ (...args: TParameter): Promise<TReturn>;
754
+ }
755
+ //#endregion
756
+ //#region ../alepha/src/server/services/HttpClient.d.ts
757
+ declare class HttpClient {
758
+ protected readonly log: Logger;
759
+ protected readonly alepha: Alepha;
760
+ readonly cache: CachePrimitiveFn<HttpClientCache, any[]>;
761
+ protected readonly pendingRequests: HttpClientPendingRequests;
762
+ fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
763
+ fetch<T extends TSchema>(url: string, request?: RequestInitWithOptions<T>): Promise<FetchResponse<Static<T>>>;
764
+ protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
765
+ protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
766
+ protected responseData(response: Response, options: FetchOptions): Promise<any>;
767
+ protected isMaybeFile(response: Response): boolean;
768
+ protected createFileLike(response: Response, defaultFileName?: string): FileLike;
769
+ pathVariables(url: string, action: {
770
+ schema?: {
771
+ params?: TObject;
772
+ };
773
+ }, args?: ServerRequestConfigEntry): string;
774
+ queryParams(url: string, action: {
775
+ schema?: {
776
+ query?: TObject;
777
+ };
778
+ }, args?: ServerRequestConfigEntry): string;
779
+ }
780
+ interface FetchOptions<T extends TSchema = TSchema> {
781
+ /**
782
+ * Key to identify the request in the pending requests.
783
+ */
784
+ key?: string;
1189
785
  /**
1190
- * Attach child pages to create nested routes.
1191
- * This will make the page a parent route.
786
+ * The schema to validate the response against.
1192
787
  */
1193
- children?: Array<PageDescriptor> | (() => Array<PageDescriptor>);
788
+ schema?: {
789
+ response?: T;
790
+ };
1194
791
  /**
1195
- * Define a parent page for nested routing.
792
+ * Built-in cache options.
1196
793
  */
1197
- parent?: PageDescriptor<PageConfigSchema, TPropsParent, any>;
1198
- can?: () => boolean;
794
+ localCache?: boolean | number | DurationLike;
795
+ }
796
+ type RequestInitWithOptions<T extends TSchema = TSchema> = RequestInit & FetchOptions<T>;
797
+ interface FetchResponse<T = any> {
798
+ data: T;
799
+ status: number;
800
+ statusText: string;
801
+ headers: Headers;
802
+ raw?: Response;
803
+ }
804
+ type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
805
+ interface HttpClientCache {
806
+ data: any;
807
+ etag?: string;
808
+ }
809
+ interface FetchActionArgs {
810
+ action: HttpAction;
811
+ host?: string;
812
+ config?: ServerRequestConfigEntry;
813
+ options?: ClientRequestOptions;
814
+ }
815
+ interface HttpAction {
816
+ method?: string;
817
+ prefix?: string;
818
+ path: string;
819
+ requestBodyType?: string;
820
+ schema?: {
821
+ params?: TObject;
822
+ query?: TObject;
823
+ body?: TRequestBody;
824
+ response?: TResponseBody;
825
+ };
826
+ }
827
+ //#endregion
828
+ //#region ../alepha/src/server/primitives/$action.d.ts
829
+ interface ActionPrimitiveOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
1199
830
  /**
1200
- * Catch any error from the `resolve` function or during `rendering`.
831
+ * Name of the action.
1201
832
  *
1202
- * Expected to return one of the following:
1203
- * - a ReactNode to render an error page
1204
- * - a Redirection to redirect the user
1205
- * - undefined to let the error propagate
833
+ * - It will be used to generate the route path if `path` is not provided.
834
+ * - It will be used to generate the permission name if `security` is enabled.
835
+ */
836
+ name?: string;
837
+ /**
838
+ * Group actions together.
1206
839
  *
1207
- * If not defined, the error will be thrown and handled by the server or client error handler.
1208
- * If a leaf $page does not define an error handler, the error can be caught by parent pages.
840
+ * - If not provided, the service name containing the route will be used.
841
+ * - It will be used as Tag for documentation purposes.
842
+ * - It will be used for permission name generation if `security` is enabled.
1209
843
  *
1210
- * @example Catch a 404 from API and render a custom not found component:
844
+ * @example
1211
845
  * ```ts
1212
- * resolve: async ({ params, query }) => {
1213
- * api.fetch("/api/resource", { params, query });
1214
- * },
1215
- * errorHandler: (error, context) => {
1216
- * if (HttpError.is(error, 404)) {
1217
- * return <ResourceNotFound />;
1218
- * }
846
+ * // group = "MyController"
847
+ * class MyController {
848
+ * hello = $action({ handler: () => "Hello World" });
1219
849
  * }
1220
- * ```
1221
850
  *
1222
- * @example Catch an 401 error and redirect the user to the login page:
1223
- * ```ts
1224
- * resolve: async ({ params, query }) => {
1225
- * // but the user is not authenticated
1226
- * api.fetch("/api/resource", { params, query });
1227
- * },
1228
- * errorHandler: (error, context) => {
1229
- * if (HttpError.is(error, 401)) {
1230
- * // throwing a Redirection is also valid!
1231
- * return new Redirection("/login");
1232
- * }
851
+ * // group = "users"
852
+ * class MyOtherController {
853
+ * group = "users";
854
+ * a1 = $action({ handler: () => "Action 1", group: this.group });
855
+ * a2 = $action({ handler: () => "Action 2", group: this.group });
1233
856
  * }
1234
857
  * ```
1235
858
  */
1236
- errorHandler?: ErrorHandler;
859
+ group?: string;
860
+ /**
861
+ * Pathname of the route. If not provided, property key is used.
862
+ */
863
+ path?: string;
1237
864
  /**
1238
- * If true, the page will be considered as a static page, immutable and cacheable.
1239
- * Replace boolean by an object to define static entries. (e.g. list of params/query)
865
+ * The route method.
1240
866
  *
1241
- * Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.
867
+ * - If not provided, it will be set to "GET" by default.
868
+ * - If not provider and a body is provided, it will be set to "POST".
1242
869
  *
1243
- * Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.
870
+ * Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
1244
871
  */
1245
- static?: boolean | {
1246
- entries?: Array<Partial<PageRequestConfig<TConfig>>>;
1247
- };
1248
- cache?: ServerRouteCache;
872
+ method?: RouteMethod;
1249
873
  /**
1250
- * If true, force the page to be rendered only on the client-side (browser).
1251
- * It uses the `<ClientOnly/>` component to render the page.
874
+ * The config schema of the route.
875
+ * - body: The request body schema.
876
+ * - params: Path variables schema.
877
+ * - query: The request query-params schema.
878
+ * - response: The response schema.
1252
879
  */
1253
- client?: boolean | ClientOnlyProps;
880
+ schema?: TConfig;
1254
881
  /**
1255
- * Called before the server response is sent to the client. (server only)
882
+ * A short description of the action. Used for documentation purposes.
1256
883
  */
1257
- onServerResponse?: (request: ServerRequest) => unknown;
884
+ description?: string;
1258
885
  /**
1259
- * Called when user leaves the page. (browser only)
886
+ * Disable the route. Useful with env variables do disable one specific route.
887
+ * Route won't be available in the API but can still be called locally!
1260
888
  */
1261
- onLeave?: () => void;
889
+ disabled?: boolean;
1262
890
  /**
1263
- * @experimental
1264
- *
1265
- * Add a css animation when the page is loaded or unloaded.
1266
- * It uses CSS animations, so you need to define the keyframes in your CSS.
1267
- *
1268
- * @example Simple animation name
1269
- * ```ts
1270
- * animation: "fadeIn"
1271
- * ```
1272
- *
1273
- * CSS example:
1274
- * ```css
1275
- * @keyframes fadeIn {
1276
- * from { opacity: 0; }
1277
- * to { opacity: 1; }
1278
- * }
1279
- * ```
1280
- *
1281
- * @example Detailed animation
1282
- * ```ts
1283
- * animation: {
1284
- * enter: { name: "fadeIn", duration: 300 },
1285
- * exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
1286
- * }
1287
- * ```
1288
- *
1289
- * @example Only exit animation
1290
- * ```ts
1291
- * animation: {
1292
- * exit: "fadeOut"
1293
- * }
1294
- * ```
1295
- *
1296
- * @example With custom timing function
1297
- * ```ts
1298
- * animation: {
1299
- * enter: { name: "fadeIn", duration: 300, timing: "cubic-bezier(0.4, 0, 0.2, 1)" },
1300
- * exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
1301
- * }
1302
- * ```
891
+ * Main route handler. This is where the route logic is implemented.
1303
892
  */
1304
- animation?: PageAnimation;
893
+ handler: ServerActionHandler<TConfig>;
1305
894
  }
1306
- type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
1307
- declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Descriptor<PageDescriptorOptions<TConfig, TProps, TPropsParent>> {
1308
- protected readonly reactPageService: ReactPageService;
895
+ declare class ActionPrimitive<TConfig extends RequestConfigSchema> extends Primitive<ActionPrimitiveOptions<TConfig>> {
896
+ protected readonly log: Logger;
897
+ protected readonly env: {
898
+ SERVER_API_PREFIX: string;
899
+ };
900
+ protected readonly httpClient: HttpClient;
901
+ protected readonly serverProvider: ServerProvider;
902
+ protected readonly serverRouterProvider: ServerRouterProvider;
1309
903
  protected onInit(): void;
1310
- get name(): string;
904
+ get prefix(): string;
905
+ get route(): ServerRoute;
1311
906
  /**
1312
- * For testing or build purposes.
1313
- *
1314
- * This will render the page (HTML layout included or not) and return the HTML + context.
1315
- * Only valid for server-side rendering, it will throw an error if called on the client-side.
907
+ * Returns the name of the action.
1316
908
  */
1317
- render(options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
1318
- fetch(options?: PageDescriptorRenderOptions): Promise<{
1319
- html: string;
1320
- response: Response;
1321
- }>;
1322
- match(url: string): boolean;
1323
- pathname(config: any): string;
1324
- }
1325
- interface PageConfigSchema {
1326
- query?: TSchema;
1327
- params?: TSchema;
1328
- }
1329
- type TPropsDefault = any;
1330
- type TPropsParentDefault = {};
1331
- interface PageDescriptorRenderOptions {
1332
- params?: Record<string, string>;
1333
- query?: Record<string, string>;
909
+ get name(): string;
910
+ /**
911
+ * Returns the group of the action. (e.g. "orders", "admin", etc.)
912
+ */
913
+ get group(): string;
1334
914
  /**
1335
- * If true, the HTML layout will be included in the response.
1336
- * If false, only the page content will be returned.
1337
- *
1338
- * @default true
915
+ * Returns the HTTP method of the action.
1339
916
  */
1340
- html?: boolean;
1341
- hydration?: boolean;
1342
- }
1343
- interface PageDescriptorRenderResult {
1344
- html: string;
1345
- state: ReactRouterState;
1346
- redirect?: string;
1347
- }
1348
- interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
1349
- params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
1350
- query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
1351
- }
1352
- type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
1353
- type PageAnimation = PageAnimationObject | ((state: ReactRouterState) => PageAnimationObject | undefined);
1354
- type PageAnimationObject = CssAnimationName | {
1355
- enter?: CssAnimation | CssAnimationName;
1356
- exit?: CssAnimation | CssAnimationName;
1357
- };
1358
- type CssAnimationName = string;
1359
- type CssAnimation = {
1360
- name: string;
1361
- duration?: number;
1362
- timing?: string;
1363
- };
1364
- //#endregion
1365
- //#region ../alepha/src/security/schemas/userAccountInfoSchema.d.ts
1366
- declare const userAccountInfoSchema: alepha84.TObject<{
1367
- id: alepha84.TString;
1368
- name: alepha84.TOptional<alepha84.TString>;
1369
- email: alepha84.TOptional<alepha84.TString>;
1370
- username: alepha84.TOptional<alepha84.TString>;
1371
- picture: alepha84.TOptional<alepha84.TString>;
1372
- sessionId: alepha84.TOptional<alepha84.TString>;
1373
- organizations: alepha84.TOptional<alepha84.TArray<alepha84.TString>>;
1374
- roles: alepha84.TOptional<alepha84.TArray<alepha84.TString>>;
1375
- }>;
1376
- type UserAccount = Static<typeof userAccountInfoSchema>;
1377
- //#endregion
1378
- //#region ../alepha/src/security/interfaces/UserAccountToken.d.ts
1379
- /**
1380
- * Add contextual metadata to a user account info.
1381
- * E.g. UserAccountToken is a UserAccountInfo during a request.
1382
- */
1383
- interface UserAccountToken extends UserAccount {
917
+ get method(): RouteMethod;
1384
918
  /**
1385
- * Access token for the user.
919
+ * Returns the path of the action.
920
+ *
921
+ * Path is prefixed by `/api` by default.
1386
922
  */
1387
- token?: string;
923
+ get path(): string;
924
+ get schema(): TConfig | undefined;
925
+ getBodyContentType(): string | undefined;
1388
926
  /**
1389
- * Realm name of the user.
927
+ * Call the action handler directly.
928
+ * There is no HTTP layer involved.
1390
929
  */
1391
- realm?: string;
930
+ run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
1392
931
  /**
1393
- * Is user dedicated to his own resources for this scope ?
1394
- * Mostly, Admin is false and Customer is true.
932
+ * Works like `run`, but always fetches (http request) the route.
1395
933
  */
1396
- ownership?: string | boolean;
1397
- }
1398
- //#endregion
1399
- //#region ../alepha/src/security/providers/SecurityProvider.d.ts
1400
- declare const envSchema$2: alepha84.TObject<{
1401
- APP_SECRET: alepha84.TString;
1402
- }>;
1403
- declare module "alepha" {
1404
- interface Env extends Partial<Static<typeof envSchema$2>> {}
1405
- }
1406
- //#endregion
1407
- //#region ../alepha/src/security/index.d.ts
1408
- declare module "alepha" {
1409
- interface Hooks {
1410
- "security:user:created": {
1411
- realm: string;
1412
- user: UserAccount;
1413
- };
1414
- }
1415
- }
1416
- /**
1417
- * Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
1418
- *
1419
- * The security module enables building secure applications using descriptors like `$realm`, `$role`, and `$permission`
1420
- * on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
1421
- * integration with various authentication providers and user management systems.
1422
- *
1423
- * @see {@link $realm}
1424
- * @see {@link $role}
1425
- * @see {@link $permission}
1426
- * @module alepha.security
1427
- */
1428
- //#endregion
1429
- //#region ../alepha/src/server-security/providers/ServerBasicAuthProvider.d.ts
1430
- interface BasicAuthOptions {
1431
- username: string;
1432
- password: string;
934
+ fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
1433
935
  }
1434
- //#endregion
1435
- //#region ../alepha/src/server-security/providers/ServerSecurityProvider.d.ts
1436
- type ServerRouteSecure = {
1437
- realm?: string;
1438
- basic?: BasicAuthOptions;
936
+ type ClientRequestEntry<TConfig extends RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
937
+ type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
938
+ body: TConfig["body"] extends TObject ? Static<TConfig["body"]> : undefined;
939
+ params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : undefined;
940
+ headers?: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : undefined;
941
+ query?: TConfig["query"] extends TObject ? Partial<Static<TConfig["query"]>> : undefined;
1439
942
  };
1440
- //#endregion
1441
- //#region ../alepha/src/server-security/index.d.ts
1442
- declare module "alepha" {
1443
- interface State {
1444
- /**
1445
- * Real (or fake) user account, used for internal actions.
1446
- *
1447
- * If you define this, you assume that all actions are executed by this user by default.
1448
- * > To force a different user, you need to pass it explicitly in the options.
1449
- */
1450
- "alepha.server.security.system.user"?: UserAccountToken;
1451
- /**
1452
- * The authenticated user account attached to the server request state.
1453
- *
1454
- * @internal
1455
- */
1456
- "alepha.server.request.user"?: UserAccount;
1457
- }
1458
- }
1459
- declare module "alepha/server" {
1460
- interface ServerRequest<TConfig> {
1461
- user?: UserAccountToken;
1462
- }
1463
- interface ServerActionRequest<TConfig> {
1464
- user: UserAccountToken;
1465
- }
1466
- interface ServerRoute {
1467
- /**
1468
- * If true, the route will be protected by the security provider.
1469
- * All actions are secure by default, but you can disable it for specific actions.
1470
- */
1471
- secure?: boolean | ServerRouteSecure;
1472
- }
1473
- interface ClientRequestOptions extends FetchOptions {
1474
- /**
1475
- * Forward user from the previous request.
1476
- * If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
1477
- * If "context", use the user from the current context (e.g. request).
1478
- *
1479
- * @default "system" if provided, else "context" if available.
1480
- */
1481
- user?: UserAccountToken | "system" | "context";
1482
- }
943
+ interface ClientRequestOptions extends FetchOptions {
944
+ /**
945
+ * Standard request fetch options.
946
+ */
947
+ request?: RequestInit;
1483
948
  }
949
+ type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
1484
950
  /**
1485
- * Plugin for Alepha Server that provides security features. Based on the Alepha Security module.
1486
- *
1487
- * By default, all $action will be guarded by a permission check.
1488
- *
1489
- * @see {@link ServerSecurityProvider}
1490
- * @module alepha.server.security
951
+ * Specific handler for server actions.
1491
952
  */
1492
- //#endregion
1493
- //#region ../alepha/src/server-links/schemas/apiLinksResponseSchema.d.ts
1494
- declare const apiLinksResponseSchema: alepha84.TObject<{
1495
- prefix: alepha84.TOptional<alepha84.TString>;
1496
- links: alepha84.TArray<alepha84.TObject<{
1497
- name: alepha84.TString;
1498
- group: alepha84.TOptional<alepha84.TString>;
1499
- path: alepha84.TString;
1500
- method: alepha84.TOptional<alepha84.TString>;
1501
- requestBodyType: alepha84.TOptional<alepha84.TString>;
1502
- service: alepha84.TOptional<alepha84.TString>;
1503
- }>>;
1504
- }>;
1505
- type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
1506
- //#endregion
1507
- //#region ../alepha/src/server-links/index.d.ts
1508
- declare module "alepha" {
1509
- interface State {
1510
- /**
1511
- * API links attached to the server request state.
1512
- *
1513
- * @see {@link ApiLinksResponse}
1514
- * @internal
1515
- */
1516
- "alepha.server.request.apiLinks"?: ApiLinksResponse;
1517
- }
1518
- }
953
+ type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
1519
954
  /**
1520
- * Provides server-side link management and remote capabilities for client-server interactions.
955
+ * Server Action Request Interface
1521
956
  *
1522
- * The server-links module enables declarative link definitions using `$remote` and `$client` descriptors,
1523
- * facilitating seamless API endpoint management and client-server communication. It integrates with server
1524
- * security features to ensure safe and controlled access to resources.
957
+ * Can be extended with module augmentation to add custom properties (like `user` in Server Security).
1525
958
  *
1526
- * @see {@link $remote}
1527
- * @see {@link $client}
1528
- * @module alepha.server.links
959
+ * This is NOT Server Request, but a specific type for actions.
1529
960
  */
961
+ interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
1530
962
  //#endregion
1531
- //#region src/core/providers/ReactBrowserProvider.d.ts
1532
- declare const envSchema$1: alepha84.TObject<{
1533
- REACT_ROOT_ID: alepha84.TString;
963
+ //#region ../alepha/src/server/providers/BunHttpServerProvider.d.ts
964
+ declare const envSchema$1: alepha30.TObject<{
965
+ SERVER_PORT: alepha30.TInteger;
966
+ SERVER_HOST: alepha30.TString;
1534
967
  }>;
1535
968
  declare module "alepha" {
1536
969
  interface Env extends Partial<Static<typeof envSchema$1>> {}
1537
970
  }
1538
- /**
1539
- * React browser renderer configuration atom
1540
- */
1541
- declare const reactBrowserOptions: alepha84.Atom<alepha84.TObject<{
1542
- scrollRestoration: alepha84.TUnsafe<"top" | "manual">;
1543
- }>, "alepha.react.browser.options">;
1544
- type ReactBrowserRendererOptions = Static<typeof reactBrowserOptions.schema>;
1545
- declare module "alepha" {
1546
- interface State {
1547
- [reactBrowserOptions.key]: ReactBrowserRendererOptions;
1548
- }
1549
- }
1550
- type ReactHydrationState = {
1551
- layers?: Array<PreviousLayerData>;
1552
- } & {
1553
- [key: string]: any;
1554
- };
1555
971
  //#endregion
1556
- //#region src/core/providers/ReactServerProvider.d.ts
1557
- declare const envSchema: alepha84.TObject<{
1558
- REACT_SSR_ENABLED: alepha84.TOptional<alepha84.TBoolean>;
1559
- REACT_ROOT_ID: alepha84.TString;
1560
- REACT_SERVER_TEMPLATE: alepha84.TOptional<alepha84.TString>;
972
+ //#region ../alepha/src/server/providers/NodeHttpServerProvider.d.ts
973
+ declare const envSchema: alepha30.TObject<{
974
+ SERVER_PORT: alepha30.TInteger;
975
+ SERVER_HOST: alepha30.TString;
1561
976
  }>;
1562
977
  declare module "alepha" {
1563
978
  interface Env extends Partial<Static<typeof envSchema>> {}
1564
- interface State {
1565
- "alepha.react.server.ssr"?: boolean;
1566
- }
1567
- }
1568
- /**
1569
- * React server provider configuration atom
1570
- */
1571
- declare const reactServerOptions: alepha84.Atom<alepha84.TObject<{
1572
- publicDir: alepha84.TString;
1573
- staticServer: alepha84.TObject<{
1574
- disabled: alepha84.TBoolean;
1575
- path: alepha84.TString;
1576
- }>;
1577
- }>, "alepha.react.server.options">;
1578
- type ReactServerProviderOptions = Static<typeof reactServerOptions.schema>;
1579
- declare module "alepha" {
1580
- interface State {
1581
- [reactServerOptions.key]: ReactServerProviderOptions;
1582
- }
1583
979
  }
1584
980
  //#endregion
1585
- //#region src/core/index.d.ts
981
+ //#region ../alepha/src/server/index.d.ts
1586
982
  declare module "alepha" {
1587
983
  interface State {
1588
- "alepha.react.router.state"?: ReactRouterState;
984
+ "alepha.node.server"?: Server;
1589
985
  }
1590
986
  interface Hooks {
1591
- /**
1592
- * Fires when the React application is starting to be rendered on the server.
1593
- */
1594
- "react:server:render:begin": {
1595
- request?: ServerRequest;
1596
- state: ReactRouterState;
1597
- };
1598
- /**
1599
- * Fires when the React application has been rendered on the server.
1600
- */
1601
- "react:server:render:end": {
1602
- request?: ServerRequest;
1603
- state: ReactRouterState;
1604
- html: string;
1605
- };
1606
- /**
1607
- * Fires when the React application is being rendered on the browser.
1608
- */
1609
- "react:browser:render": {
1610
- root: HTMLElement;
1611
- element: ReactNode;
1612
- state: ReactRouterState;
1613
- hydration?: ReactHydrationState;
987
+ "action:onRequest": {
988
+ action: ActionPrimitive<RequestConfigSchema>;
989
+ request: ServerRequest;
990
+ options: ClientRequestOptions;
1614
991
  };
1615
- /**
1616
- * Fires when a user action is starting.
1617
- * Action can be a form submission, a route transition, or a custom action.
1618
- */
1619
- "react:action:begin": {
1620
- type: string;
1621
- id?: string;
992
+ "action:onResponse": {
993
+ action: ActionPrimitive<RequestConfigSchema>;
994
+ request: ServerRequest;
995
+ options: ClientRequestOptions;
996
+ response: any;
1622
997
  };
1623
- /**
1624
- * Fires when a user action has succeeded.
1625
- * Action can be a form submission, a route transition, or a custom action.
1626
- */
1627
- "react:action:success": {
1628
- type: string;
1629
- id?: string;
998
+ "server:onRequest": {
999
+ route: ServerRoute;
1000
+ request: ServerRequest;
1630
1001
  };
1631
- /**
1632
- * Fires when a user action has failed.
1633
- * Action can be a form submission, a route transition, or a custom action.
1634
- */
1635
- "react:action:error": {
1636
- type: string;
1637
- id?: string;
1002
+ "server:onError": {
1003
+ route: ServerRoute;
1004
+ request: ServerRequest;
1638
1005
  error: Error;
1639
1006
  };
1640
- /**
1641
- * Fires when a user action has completed, regardless of success or failure.
1642
- * Action can be a form submission, a route transition, or a custom action.
1643
- */
1644
- "react:action:end": {
1645
- type: string;
1646
- id?: string;
1007
+ "server:onSend": {
1008
+ route: ServerRoute;
1009
+ request: ServerRequest;
1647
1010
  };
1648
- /**
1649
- * Fires when a route transition is starting.
1650
- */
1651
- "react:transition:begin": {
1652
- previous: ReactRouterState;
1653
- state: ReactRouterState;
1654
- animation?: PageAnimation;
1011
+ "server:onResponse": {
1012
+ route: ServerRoute;
1013
+ request: ServerRequest;
1014
+ response: ServerResponse$1;
1655
1015
  };
1656
- /**
1657
- * Fires when a route transition has succeeded.
1658
- */
1659
- "react:transition:success": {
1660
- state: ReactRouterState;
1016
+ "client:onRequest": {
1017
+ route: HttpAction;
1018
+ config: ServerRequestConfigEntry;
1019
+ options: ClientRequestOptions;
1020
+ headers: Record<string, string>;
1021
+ request: RequestInit;
1661
1022
  };
1662
- /**
1663
- * Fires when a route transition has failed.
1664
- */
1665
- "react:transition:error": {
1666
- state: ReactRouterState;
1667
- error: Error;
1023
+ "client:beforeFetch": {
1024
+ url: string;
1025
+ options: FetchOptions;
1026
+ request: RequestInit;
1668
1027
  };
1669
- /**
1670
- * Fires when a route transition has completed, regardless of success or failure.
1671
- */
1672
- "react:transition:end": {
1673
- state: ReactRouterState;
1028
+ "client:onError": {
1029
+ route?: HttpAction;
1030
+ error: HttpError;
1674
1031
  };
1032
+ "node:request": NodeRequestEvent;
1033
+ "web:request": WebRequestEvent;
1675
1034
  }
1676
1035
  }
1677
- /**
1678
- * Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
1679
- *
1680
- * The React module enables building modern React applications using the `$page` descriptor on class properties.
1681
- * It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
1682
- * type safety and schema validation for route parameters and data.
1683
- *
1684
- * @see {@link $page}
1685
- * @module alepha.react
1686
- */
1687
- //#endregion
1688
- //#region src/head/interfaces/Head.d.ts
1689
- interface Head extends SimpleHead {
1690
- description?: string;
1691
- keywords?: string[];
1692
- author?: string;
1693
- robots?: string;
1694
- themeColor?: string;
1695
- viewport?: string | {
1696
- width?: string;
1697
- height?: string;
1698
- initialScale?: string;
1699
- maximumScale?: string;
1700
- userScalable?: "no" | "yes" | "0" | "1";
1701
- interactiveWidget?: "resizes-visual" | "resizes-content" | "overlays-content";
1702
- };
1703
- og?: {
1704
- title?: string;
1705
- description?: string;
1706
- image?: string;
1707
- url?: string;
1708
- type?: string;
1709
- };
1710
- twitter?: {
1711
- card?: string;
1712
- title?: string;
1713
- description?: string;
1714
- image?: string;
1715
- site?: string;
1716
- };
1717
- }
1718
- interface SimpleHead {
1719
- title?: string;
1720
- titleSeparator?: string;
1721
- htmlAttributes?: Record<string, string>;
1722
- bodyAttributes?: Record<string, string>;
1723
- meta?: Array<{
1724
- name: string;
1725
- content: string;
1726
- }>;
1727
- }
1728
- //#endregion
1729
- //#region src/head/providers/HeadProvider.d.ts
1730
- declare class HeadProvider {
1731
- global?: Head | (() => Head);
1732
- protected getGlobalHead(): Head | undefined;
1733
- fillHead(state: ReactRouterState): void;
1734
- protected fillHeadByPage(page: PageRoute, state: ReactRouterState, props: Record<string, any>): void;
1735
- }
1736
- //#endregion
1737
- //#region src/head/descriptors/$head.d.ts
1738
- /**
1739
- * Set global `<head>` options for the application.
1740
- */
1741
- declare const $head: {
1742
- (options: HeadDescriptorOptions): HeadDescriptor;
1743
- [KIND]: typeof HeadDescriptor;
1744
- };
1745
- type HeadDescriptorOptions = Head | (() => Head);
1746
- declare class HeadDescriptor extends Descriptor<HeadDescriptorOptions> {
1747
- protected readonly provider: HeadProvider;
1748
- protected onInit(): void;
1749
- }
1750
- //#endregion
1751
- //#region src/head/hooks/useHead.d.ts
1752
- /**
1753
- * ```tsx
1754
- * const App = () => {
1755
- * const [head, setHead] = useHead({
1756
- * // will set the document title on the first render
1757
- * title: "My App",
1758
- * });
1759
- *
1760
- * return (
1761
- * // This will update the document title when the button is clicked
1762
- * <button onClick={() => setHead({ title: "Change Title" })}>
1763
- * Change Title {head.title}
1764
- * </button>
1765
- * );
1766
- * }
1767
- * ```
1768
- */
1769
- declare const useHead: (options?: UseHeadOptions) => UseHeadReturn;
1770
- type UseHeadOptions = Head | ((previous?: Head) => Head);
1771
- type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
1772
1036
  //#endregion
1773
1037
  //#region src/head/providers/ServerHeadProvider.d.ts
1774
1038
  declare class ServerHeadProvider {
1775
1039
  protected readonly headProvider: HeadProvider;
1776
1040
  protected readonly serverTimingProvider: ServerTimingProvider;
1777
- protected readonly onServerRenderEnd: alepha84.HookDescriptor<"react:server:render:end">;
1041
+ protected readonly onServerRenderEnd: alepha30.HookPrimitive<"react:server:render:end">;
1778
1042
  renderHead(template: string, head: SimpleHead): string;
1779
1043
  protected mergeAttributes(existing: string, attrs: Record<string, string>): string;
1780
1044
  protected parseAttributes(attrStr: string): Record<string, string>;
@@ -1783,7 +1047,7 @@ declare class ServerHeadProvider {
1783
1047
  //#endregion
1784
1048
  //#region src/head/index.d.ts
1785
1049
  declare module "@alepha/react" {
1786
- interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
1050
+ interface PagePrimitiveOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
1787
1051
  head?: Head | ((props: TProps, previous?: Head) => Head);
1788
1052
  }
1789
1053
  interface ReactRouterState {
@@ -1796,7 +1060,7 @@ declare module "@alepha/react" {
1796
1060
  * @see {@link ServerHeadProvider}
1797
1061
  * @module alepha.react.head
1798
1062
  */
1799
- declare const AlephaReactHead: alepha84.Service<alepha84.Module>;
1063
+ declare const AlephaReactHead: alepha30.Service<alepha30.Module>;
1800
1064
  //#endregion
1801
- export { $head, AlephaReactHead, Head, HeadDescriptor, HeadDescriptorOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
1065
+ export { $head, AlephaReactHead, Head, HeadPrimitive, HeadPrimitiveOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
1802
1066
  //# sourceMappingURL=index.d.ts.map