@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.
- package/dist/auth/index.browser.js +9 -1647
- package/dist/auth/index.browser.js.map +1 -1
- package/dist/auth/index.d.ts +330 -330
- package/dist/auth/index.js +11 -1649
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.browser.js +19 -18
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +352 -344
- package/dist/core/index.js +25 -24
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +381 -0
- package/dist/core/index.native.js.map +1 -0
- package/dist/form/index.d.ts +3 -3
- package/dist/form/index.js +3 -1642
- package/dist/form/index.js.map +1 -1
- package/dist/head/index.browser.js +9 -1660
- package/dist/head/index.browser.js.map +1 -1
- package/dist/head/index.d.ts +808 -1544
- package/dist/head/index.js +10 -1660
- package/dist/head/index.js.map +1 -1
- package/dist/i18n/index.d.ts +34 -34
- package/dist/i18n/index.js +14 -1664
- package/dist/i18n/index.js.map +1 -1
- package/dist/websocket/index.d.ts +161 -5
- package/dist/websocket/index.js +2 -1654
- package/dist/websocket/index.js.map +1 -1
- package/package.json +12 -9
- package/src/auth/index.ts +1 -1
- package/src/auth/providers/ReactAuthProvider.ts +1 -1
- package/src/auth/services/ReactAuth.ts +5 -5
- package/src/core/components/NestedView.tsx +1 -1
- package/src/core/hooks/useStore.ts +4 -4
- package/src/core/index.browser.ts +2 -2
- package/src/core/index.native.ts +1 -1
- package/src/core/index.shared-router.ts +1 -1
- package/src/core/index.ts +3 -3
- package/src/core/{descriptors → primitives}/$page.ts +20 -20
- package/src/core/providers/ReactBrowserProvider.ts +2 -2
- package/src/core/providers/ReactBrowserRouterProvider.ts +2 -2
- package/src/core/providers/ReactPageProvider.ts +25 -11
- package/src/core/providers/ReactServerProvider.ts +12 -12
- package/src/core/services/ReactPageServerService.ts +6 -6
- package/src/core/services/ReactPageService.ts +6 -6
- package/src/core/services/ReactRouter.ts +3 -3
- package/src/head/index.browser.ts +3 -3
- package/src/head/index.ts +4 -4
- package/src/head/{descriptors → primitives}/$head.ts +6 -6
- package/src/i18n/hooks/useI18n.ts +2 -2
- package/src/i18n/index.ts +3 -3
- package/src/i18n/{descriptors → primitives}/$dictionary.ts +8 -8
- package/src/i18n/providers/I18nProvider.ts +5 -5
- package/src/websocket/hooks/useRoom.tsx +3 -3
- package/dist/auth/chunk-DhGyd7sr.js +0 -28
- package/dist/auth/index.cjs +0 -1800
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.d.cts +0 -1274
- package/dist/core/chunk-DhGyd7sr.js +0 -28
- package/dist/core/index.cjs +0 -2087
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -2763
- package/dist/form/chunk-DhGyd7sr.js +0 -28
- package/dist/form/index.cjs +0 -2074
- package/dist/form/index.cjs.map +0 -1
- package/dist/form/index.d.cts +0 -419
- package/dist/head/chunk-DhGyd7sr.js +0 -28
- package/dist/head/index.cjs +0 -1912
- package/dist/head/index.cjs.map +0 -1
- package/dist/head/index.d.cts +0 -1801
- package/dist/i18n/chunk-DhGyd7sr.js +0 -28
- package/dist/i18n/index.cjs +0 -1899
- package/dist/i18n/index.cjs.map +0 -1
- package/dist/i18n/index.d.cts +0 -437
- package/dist/websocket/index.cjs +0 -1787
- package/dist/websocket/index.cjs.map +0 -1
- package/dist/websocket/index.d.cts +0 -118
- package/src/i18n/README.md +0 -76
package/dist/head/index.d.ts
CHANGED
|
@@ -1,1780 +1,1044 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
25
|
+
og?: {
|
|
26
|
+
title?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
image?: string;
|
|
29
|
+
url?: string;
|
|
30
|
+
type?: string;
|
|
252
31
|
};
|
|
253
|
-
|
|
254
|
-
|
|
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
|
|
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
|
-
*
|
|
61
|
+
* Set global `<head>` options for the application.
|
|
261
62
|
*/
|
|
262
|
-
declare
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
|
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
|
-
*
|
|
294
|
-
*
|
|
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
|
-
*
|
|
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
|
|
299
|
-
|
|
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/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
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/
|
|
425
|
-
declare class
|
|
426
|
-
protected
|
|
427
|
-
protected
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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/
|
|
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
|
-
*
|
|
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
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
*
|
|
187
|
+
* Redirect to a given URL with optional status code (default 302).
|
|
511
188
|
*/
|
|
512
|
-
|
|
189
|
+
redirect(url: string, status?: number): void;
|
|
513
190
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
* Technically, we just convert Node.js request to Web Standard Request.
|
|
191
|
+
* Set the response status code.
|
|
517
192
|
*/
|
|
518
|
-
|
|
193
|
+
setStatus(status: number): this;
|
|
519
194
|
/**
|
|
520
|
-
*
|
|
195
|
+
* Set a response header.
|
|
521
196
|
*/
|
|
522
|
-
|
|
197
|
+
setHeader(name: string, value: string): this;
|
|
523
198
|
/**
|
|
524
|
-
*
|
|
199
|
+
* Set the response body.
|
|
525
200
|
*/
|
|
526
|
-
|
|
201
|
+
setBody(body: any): this;
|
|
527
202
|
}
|
|
528
203
|
//#endregion
|
|
529
|
-
//#region ../alepha/src/
|
|
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
|
-
*
|
|
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
|
-
*
|
|
534
|
-
* Values are stored as Uint8Array.
|
|
214
|
+
* Use result for non
|
|
535
215
|
*/
|
|
536
|
-
declare
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
241
|
+
method: RouteMethod;
|
|
557
242
|
/**
|
|
558
|
-
*
|
|
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
|
-
|
|
564
|
-
abstract has(name: string, key: string): Promise<boolean>;
|
|
565
|
-
abstract keys(name: string, filter?: string): Promise<string[]>;
|
|
245
|
+
url: URL;
|
|
566
246
|
/**
|
|
567
|
-
*
|
|
247
|
+
* Unique request ID assigned to this request.
|
|
568
248
|
*/
|
|
569
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
254
|
+
ip?: string;
|
|
582
255
|
/**
|
|
583
|
-
*
|
|
256
|
+
* Value of the `Host` header sent by the client.
|
|
584
257
|
*/
|
|
585
|
-
|
|
258
|
+
host?: string;
|
|
586
259
|
/**
|
|
587
|
-
*
|
|
588
|
-
*
|
|
260
|
+
* Browser user agent information.
|
|
261
|
+
* Information are not guaranteed to be accurate. Use with caution.
|
|
262
|
+
*
|
|
263
|
+
* @see {@link UserAgentParser}
|
|
589
264
|
*/
|
|
590
|
-
|
|
265
|
+
userAgent: UserAgentInfo;
|
|
591
266
|
/**
|
|
592
|
-
*
|
|
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
|
-
|
|
269
|
+
metadata: Record<string, any>;
|
|
596
270
|
/**
|
|
597
|
-
*
|
|
598
|
-
* Set 0 to skip expiration.
|
|
599
|
-
*
|
|
600
|
-
* @default 300 (5 minutes).
|
|
271
|
+
* Reply object to be used to send response.
|
|
601
272
|
*/
|
|
602
|
-
|
|
273
|
+
reply: ServerReply;
|
|
603
274
|
/**
|
|
604
|
-
*
|
|
275
|
+
* The raw underlying request object (Web Request).
|
|
605
276
|
*/
|
|
606
|
-
|
|
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
|
|
279
|
+
interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
|
|
633
280
|
/**
|
|
634
|
-
*
|
|
281
|
+
* Handler function for this route.
|
|
635
282
|
*/
|
|
636
|
-
|
|
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
|
-
*
|
|
285
|
+
* HTTP method for this route.
|
|
666
286
|
*/
|
|
667
|
-
|
|
287
|
+
method?: RouteMethod;
|
|
668
288
|
/**
|
|
669
|
-
*
|
|
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
|
-
*
|
|
304
|
+
* @see ServerLoggerProvider
|
|
676
305
|
*/
|
|
677
|
-
|
|
306
|
+
silent?: boolean;
|
|
678
307
|
}
|
|
679
|
-
type
|
|
680
|
-
|
|
681
|
-
|
|
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
|
|
688
|
-
interface
|
|
689
|
-
|
|
690
|
-
etag?: string;
|
|
317
|
+
type ServerRouteRequestHandler = (request: ServerRequestData) => Promise<ServerResponse$1>;
|
|
318
|
+
interface ServerRouteMatcher extends Route {
|
|
319
|
+
handler: ServerRouteRequestHandler;
|
|
691
320
|
}
|
|
692
|
-
interface
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
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/
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
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
|
-
*
|
|
371
|
+
* Create a new UTC DateTime instance.
|
|
745
372
|
*/
|
|
746
|
-
|
|
373
|
+
utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
747
374
|
/**
|
|
748
|
-
*
|
|
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
|
-
|
|
377
|
+
of(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
756
378
|
/**
|
|
757
|
-
*
|
|
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
|
-
|
|
381
|
+
toISOString(date?: Date | string | DateTime): string;
|
|
764
382
|
/**
|
|
765
|
-
*
|
|
383
|
+
* Get the current date.
|
|
766
384
|
*/
|
|
767
|
-
|
|
385
|
+
now(): DateTime;
|
|
768
386
|
/**
|
|
769
|
-
*
|
|
770
|
-
*
|
|
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
|
-
|
|
391
|
+
nowISOString(): string;
|
|
773
392
|
/**
|
|
774
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
399
|
+
* Get the current date as a string.
|
|
400
|
+
*
|
|
401
|
+
* @protected
|
|
791
402
|
*/
|
|
792
|
-
|
|
403
|
+
protected getCurrentDate(): DateTime;
|
|
793
404
|
/**
|
|
794
|
-
*
|
|
405
|
+
* Create a new Duration instance.
|
|
795
406
|
*/
|
|
796
|
-
|
|
407
|
+
duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
|
|
408
|
+
isDurationLike(value: unknown): value is DurationLike;
|
|
797
409
|
/**
|
|
798
|
-
*
|
|
410
|
+
* Return a promise that resolves after the next tick.
|
|
411
|
+
* It uses `setTimeout` with 0 ms delay.
|
|
799
412
|
*/
|
|
800
|
-
|
|
413
|
+
tick(): Promise<void>;
|
|
801
414
|
/**
|
|
802
|
-
*
|
|
415
|
+
* Wait for a certain duration.
|
|
803
416
|
*
|
|
804
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
426
|
+
* Run a callback after a certain duration.
|
|
816
427
|
*/
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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
|
-
*
|
|
829
|
-
*/
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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
|
|
876
|
-
|
|
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/
|
|
880
|
-
declare
|
|
881
|
-
|
|
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/
|
|
889
|
-
declare
|
|
890
|
-
|
|
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/
|
|
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
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Current log level for the application or specific modules.
|
|
530
|
+
*/
|
|
531
|
+
"alepha.logger.level"?: string;
|
|
901
532
|
}
|
|
902
533
|
interface Hooks {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
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
|
|
954
|
-
declare
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
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
|
-
*
|
|
570
|
+
* Main router for all routes on the server side.
|
|
978
571
|
*
|
|
979
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
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/
|
|
607
|
+
//#region ../alepha/src/server/providers/ServerProvider.d.ts
|
|
1057
608
|
/**
|
|
1058
|
-
*
|
|
609
|
+
* Base server provider to handle incoming requests and route them.
|
|
1059
610
|
*
|
|
1060
|
-
*
|
|
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
|
|
1063
|
-
readonly
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
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
|
-
*
|
|
623
|
+
* When a Node.js HTTP request is received from outside. (Vercel, AWS Lambda, etc.)
|
|
1107
624
|
*/
|
|
1108
|
-
|
|
625
|
+
protected readonly onNodeRequest: alepha30.HookPrimitive<"node:request">;
|
|
1109
626
|
/**
|
|
1110
|
-
*
|
|
627
|
+
* When a Web (Fetch API) request is received from outside. (Netlify, Cloudflare Workers, etc.)
|
|
1111
628
|
*/
|
|
1112
|
-
|
|
629
|
+
protected readonly onWebRequest: alepha30.HookPrimitive<"web:request">;
|
|
1113
630
|
/**
|
|
1114
|
-
*
|
|
631
|
+
* Handle Node.js HTTP request event.
|
|
632
|
+
*
|
|
633
|
+
* Technically, we just convert Node.js request to Web Standard Request.
|
|
1115
634
|
*/
|
|
1116
|
-
|
|
635
|
+
handleNodeRequest(nodeRequestEvent: NodeRequestEvent): Promise<void>;
|
|
1117
636
|
/**
|
|
1118
|
-
*
|
|
637
|
+
* Handle Web (Fetch API) request event.
|
|
1119
638
|
*/
|
|
1120
|
-
|
|
639
|
+
handleWebRequest(ev: WebRequestEvent): Promise<void>;
|
|
1121
640
|
/**
|
|
1122
|
-
*
|
|
641
|
+
* Helper for Vite development mode to let Vite handle (or not) 404.
|
|
1123
642
|
*/
|
|
1124
|
-
|
|
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/
|
|
1137
|
-
|
|
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
|
-
*
|
|
655
|
+
* Get the value of a key.
|
|
1140
656
|
*
|
|
1141
|
-
* @
|
|
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
|
|
662
|
+
abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
|
|
1144
663
|
/**
|
|
1145
|
-
*
|
|
664
|
+
* Set the string value of a key.
|
|
1146
665
|
*
|
|
1147
|
-
*
|
|
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
|
-
* @
|
|
671
|
+
* @return The value of the key.
|
|
1150
672
|
*/
|
|
1151
|
-
|
|
673
|
+
abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
|
|
1152
674
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
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
|
-
*
|
|
1168
|
-
* It's common to throw a `NotFoundError` to display a 404 page.
|
|
694
|
+
* Store key as `cache:$name:$key`.
|
|
1169
695
|
*
|
|
1170
|
-
*
|
|
696
|
+
* @default Name of the key of the class.
|
|
1171
697
|
*/
|
|
1172
|
-
|
|
698
|
+
name?: string;
|
|
1173
699
|
/**
|
|
1174
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
714
|
+
* The time-to-live for the cache in seconds.
|
|
715
|
+
* Set 0 to skip expiration.
|
|
1182
716
|
*
|
|
1183
|
-
*
|
|
1184
|
-
* and enable code-splitting.
|
|
717
|
+
* @default 300 (5 minutes).
|
|
1185
718
|
*/
|
|
1186
|
-
|
|
1187
|
-
|
|
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
|
-
*
|
|
1191
|
-
* This will make the page a parent route.
|
|
786
|
+
* The schema to validate the response against.
|
|
1192
787
|
*/
|
|
1193
|
-
|
|
788
|
+
schema?: {
|
|
789
|
+
response?: T;
|
|
790
|
+
};
|
|
1194
791
|
/**
|
|
1195
|
-
*
|
|
792
|
+
* Built-in cache options.
|
|
1196
793
|
*/
|
|
1197
|
-
|
|
1198
|
-
|
|
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
|
-
*
|
|
831
|
+
* Name of the action.
|
|
1201
832
|
*
|
|
1202
|
-
*
|
|
1203
|
-
* -
|
|
1204
|
-
|
|
1205
|
-
|
|
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
|
|
1208
|
-
*
|
|
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
|
|
844
|
+
* @example
|
|
1211
845
|
* ```ts
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
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
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
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
|
-
|
|
859
|
+
group?: string;
|
|
860
|
+
/**
|
|
861
|
+
* Pathname of the route. If not provided, property key is used.
|
|
862
|
+
*/
|
|
863
|
+
path?: string;
|
|
1237
864
|
/**
|
|
1238
|
-
*
|
|
1239
|
-
* Replace boolean by an object to define static entries. (e.g. list of params/query)
|
|
865
|
+
* The route method.
|
|
1240
866
|
*
|
|
1241
|
-
*
|
|
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
|
-
*
|
|
870
|
+
* Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
|
|
1244
871
|
*/
|
|
1245
|
-
|
|
1246
|
-
entries?: Array<Partial<PageRequestConfig<TConfig>>>;
|
|
1247
|
-
};
|
|
1248
|
-
cache?: ServerRouteCache;
|
|
872
|
+
method?: RouteMethod;
|
|
1249
873
|
/**
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
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
|
-
|
|
880
|
+
schema?: TConfig;
|
|
1254
881
|
/**
|
|
1255
|
-
*
|
|
882
|
+
* A short description of the action. Used for documentation purposes.
|
|
1256
883
|
*/
|
|
1257
|
-
|
|
884
|
+
description?: string;
|
|
1258
885
|
/**
|
|
1259
|
-
*
|
|
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
|
-
|
|
889
|
+
disabled?: boolean;
|
|
1262
890
|
/**
|
|
1263
|
-
*
|
|
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
|
-
|
|
893
|
+
handler: ServerActionHandler<TConfig>;
|
|
1305
894
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
protected readonly
|
|
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
|
|
904
|
+
get prefix(): string;
|
|
905
|
+
get route(): ServerRoute;
|
|
1311
906
|
/**
|
|
1312
|
-
*
|
|
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
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
919
|
+
* Returns the path of the action.
|
|
920
|
+
*
|
|
921
|
+
* Path is prefixed by `/api` by default.
|
|
1386
922
|
*/
|
|
1387
|
-
|
|
923
|
+
get path(): string;
|
|
924
|
+
get schema(): TConfig | undefined;
|
|
925
|
+
getBodyContentType(): string | undefined;
|
|
1388
926
|
/**
|
|
1389
|
-
*
|
|
927
|
+
* Call the action handler directly.
|
|
928
|
+
* There is no HTTP layer involved.
|
|
1390
929
|
*/
|
|
1391
|
-
|
|
930
|
+
run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
|
|
1392
931
|
/**
|
|
1393
|
-
*
|
|
1394
|
-
* Mostly, Admin is false and Customer is true.
|
|
932
|
+
* Works like `run`, but always fetches (http request) the route.
|
|
1395
933
|
*/
|
|
1396
|
-
|
|
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
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
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
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
955
|
+
* Server Action Request Interface
|
|
1521
956
|
*
|
|
1522
|
-
*
|
|
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
|
-
*
|
|
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/
|
|
1532
|
-
declare const envSchema$1:
|
|
1533
|
-
|
|
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/
|
|
1557
|
-
declare const envSchema:
|
|
1558
|
-
|
|
1559
|
-
|
|
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/
|
|
981
|
+
//#region ../alepha/src/server/index.d.ts
|
|
1586
982
|
declare module "alepha" {
|
|
1587
983
|
interface State {
|
|
1588
|
-
"alepha.
|
|
984
|
+
"alepha.node.server"?: Server;
|
|
1589
985
|
}
|
|
1590
986
|
interface Hooks {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
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
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
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
|
-
|
|
1625
|
-
|
|
1626
|
-
*/
|
|
1627
|
-
"react:action:success": {
|
|
1628
|
-
type: string;
|
|
1629
|
-
id?: string;
|
|
998
|
+
"server:onRequest": {
|
|
999
|
+
route: ServerRoute;
|
|
1000
|
+
request: ServerRequest;
|
|
1630
1001
|
};
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
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
|
-
|
|
1642
|
-
|
|
1643
|
-
*/
|
|
1644
|
-
"react:action:end": {
|
|
1645
|
-
type: string;
|
|
1646
|
-
id?: string;
|
|
1007
|
+
"server:onSend": {
|
|
1008
|
+
route: ServerRoute;
|
|
1009
|
+
request: ServerRequest;
|
|
1647
1010
|
};
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
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
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1016
|
+
"client:onRequest": {
|
|
1017
|
+
route: HttpAction;
|
|
1018
|
+
config: ServerRequestConfigEntry;
|
|
1019
|
+
options: ClientRequestOptions;
|
|
1020
|
+
headers: Record<string, string>;
|
|
1021
|
+
request: RequestInit;
|
|
1661
1022
|
};
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
state: ReactRouterState;
|
|
1667
|
-
error: Error;
|
|
1023
|
+
"client:beforeFetch": {
|
|
1024
|
+
url: string;
|
|
1025
|
+
options: FetchOptions;
|
|
1026
|
+
request: RequestInit;
|
|
1668
1027
|
};
|
|
1669
|
-
|
|
1670
|
-
|
|
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:
|
|
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
|
|
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:
|
|
1063
|
+
declare const AlephaReactHead: alepha30.Service<alepha30.Module>;
|
|
1800
1064
|
//#endregion
|
|
1801
|
-
export { $head, AlephaReactHead, Head,
|
|
1065
|
+
export { $head, AlephaReactHead, Head, HeadPrimitive, HeadPrimitiveOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
|
|
1802
1066
|
//# sourceMappingURL=index.d.ts.map
|