@alepha/react 0.12.1 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.browser.js +4 -1642
- package/dist/auth/index.browser.js.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +4 -1642
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.d.ts +83 -83
- package/dist/form/index.d.ts +1 -1
- package/dist/form/index.js +3 -1642
- package/dist/form/index.js.map +1 -1
- package/dist/head/index.browser.js +3 -1654
- package/dist/head/index.browser.js.map +1 -1
- package/dist/head/index.d.ts +149 -885
- package/dist/head/index.js +4 -1654
- package/dist/head/index.js.map +1 -1
- package/dist/i18n/index.js +3 -1653
- package/dist/i18n/index.js.map +1 -1
- package/dist/websocket/index.d.ts +159 -3
- package/dist/websocket/index.js +2 -1654
- package/dist/websocket/index.js.map +1 -1
- package/package.json +9 -15
- 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/core/index.d.cts
DELETED
|
@@ -1,2763 +0,0 @@
|
|
|
1
|
-
import * as alepha139 from "alepha";
|
|
2
|
-
import { Alepha, AlephaError, Async, Atom, Descriptor, FileLike, Hook, Hooks, InstantiableClass, KIND, LogLevel, LoggerInterface, Service, State, Static, StreamLike, TArray, TAtomObject, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
|
|
3
|
-
import { IncomingMessage, Server, ServerResponse } from "node:http";
|
|
4
|
-
import dayjsDuration from "dayjs/plugin/duration.js";
|
|
5
|
-
import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
|
|
6
|
-
import { Readable } from "node:stream";
|
|
7
|
-
import { ReadableStream } from "node:stream/web";
|
|
8
|
-
import * as react1 from "react";
|
|
9
|
-
import React, { AnchorHTMLAttributes, CSSProperties, DependencyList, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
|
|
10
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
11
|
-
|
|
12
|
-
//#region ../alepha/src/logger/schemas/logEntrySchema.d.ts
|
|
13
|
-
declare const logEntrySchema: alepha139.TObject<{
|
|
14
|
-
level: alepha139.TUnsafe<"TRACE" | "SILENT" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
|
|
15
|
-
message: alepha139.TString;
|
|
16
|
-
service: alepha139.TString;
|
|
17
|
-
module: alepha139.TString;
|
|
18
|
-
context: alepha139.TOptional<alepha139.TString>;
|
|
19
|
-
app: alepha139.TOptional<alepha139.TString>;
|
|
20
|
-
data: alepha139.TOptional<alepha139.TAny>;
|
|
21
|
-
timestamp: alepha139.TNumber;
|
|
22
|
-
}>;
|
|
23
|
-
type LogEntry = Static<typeof logEntrySchema>;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region ../alepha/src/datetime/providers/DateTimeProvider.d.ts
|
|
26
|
-
type DateTime = DayjsApi.Dayjs;
|
|
27
|
-
type Duration = dayjsDuration.Duration;
|
|
28
|
-
type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
|
|
29
|
-
declare class DateTimeProvider {
|
|
30
|
-
static PLUGINS: Array<PluginFunc<any>>;
|
|
31
|
-
protected alepha: Alepha;
|
|
32
|
-
protected ref: DateTime | null;
|
|
33
|
-
protected readonly timeouts: Timeout[];
|
|
34
|
-
protected readonly intervals: Interval[];
|
|
35
|
-
constructor();
|
|
36
|
-
protected readonly onStart: alepha139.HookDescriptor<"start">;
|
|
37
|
-
protected readonly onStop: alepha139.HookDescriptor<"stop">;
|
|
38
|
-
setLocale(locale: string): void;
|
|
39
|
-
isDateTime(value: unknown): value is DateTime;
|
|
40
|
-
/**
|
|
41
|
-
* Create a new UTC DateTime instance.
|
|
42
|
-
*/
|
|
43
|
-
utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
44
|
-
/**
|
|
45
|
-
* Create a new DateTime instance.
|
|
46
|
-
*/
|
|
47
|
-
of(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
48
|
-
/**
|
|
49
|
-
* Get the current date as a string.
|
|
50
|
-
*/
|
|
51
|
-
toISOString(date?: Date | string | DateTime): string;
|
|
52
|
-
/**
|
|
53
|
-
* Get the current date.
|
|
54
|
-
*/
|
|
55
|
-
now(): DateTime;
|
|
56
|
-
/**
|
|
57
|
-
* Get the current date as a string.
|
|
58
|
-
*
|
|
59
|
-
* This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
|
|
60
|
-
*/
|
|
61
|
-
nowISOString(): string;
|
|
62
|
-
/**
|
|
63
|
-
* Get the current date as milliseconds since epoch.
|
|
64
|
-
*
|
|
65
|
-
* This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
|
|
66
|
-
*/
|
|
67
|
-
nowMillis(): number;
|
|
68
|
-
/**
|
|
69
|
-
* Get the current date as a string.
|
|
70
|
-
*
|
|
71
|
-
* @protected
|
|
72
|
-
*/
|
|
73
|
-
protected getCurrentDate(): DateTime;
|
|
74
|
-
/**
|
|
75
|
-
* Create a new Duration instance.
|
|
76
|
-
*/
|
|
77
|
-
duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
|
|
78
|
-
isDurationLike(value: unknown): value is DurationLike;
|
|
79
|
-
/**
|
|
80
|
-
* Return a promise that resolves after the next tick.
|
|
81
|
-
* It uses `setTimeout` with 0 ms delay.
|
|
82
|
-
*/
|
|
83
|
-
tick(): Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* Wait for a certain duration.
|
|
86
|
-
*
|
|
87
|
-
* You can clear the timeout by using the `AbortSignal` API.
|
|
88
|
-
* Aborted signal will resolve the promise immediately, it does not reject it.
|
|
89
|
-
*/
|
|
90
|
-
wait(duration: DurationLike, options?: {
|
|
91
|
-
signal?: AbortSignal;
|
|
92
|
-
now?: number;
|
|
93
|
-
}): Promise<void>;
|
|
94
|
-
createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
|
|
95
|
-
/**
|
|
96
|
-
* Run a callback after a certain duration.
|
|
97
|
-
*/
|
|
98
|
-
createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
|
|
99
|
-
clearTimeout(timeout: Timeout): void;
|
|
100
|
-
clearInterval(interval: Interval): void;
|
|
101
|
-
/**
|
|
102
|
-
* Run a function with a deadline.
|
|
103
|
-
*/
|
|
104
|
-
deadline<T$1>(fn: (signal: AbortSignal) => Promise<T$1>, duration: DurationLike): Promise<T$1>;
|
|
105
|
-
/**
|
|
106
|
-
* Add time to the current date.
|
|
107
|
-
*/
|
|
108
|
-
travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
|
|
109
|
-
/**
|
|
110
|
-
* Stop the time.
|
|
111
|
-
*/
|
|
112
|
-
pause(): DateTime;
|
|
113
|
-
/**
|
|
114
|
-
* Reset the reference date.
|
|
115
|
-
*/
|
|
116
|
-
reset(): void;
|
|
117
|
-
}
|
|
118
|
-
interface Interval {
|
|
119
|
-
timer?: any;
|
|
120
|
-
duration: number;
|
|
121
|
-
run: () => unknown;
|
|
122
|
-
}
|
|
123
|
-
interface Timeout {
|
|
124
|
-
now: number;
|
|
125
|
-
timer?: any;
|
|
126
|
-
duration: number;
|
|
127
|
-
callback: () => void;
|
|
128
|
-
clear: () => void;
|
|
129
|
-
}
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region ../alepha/src/logger/providers/LogDestinationProvider.d.ts
|
|
132
|
-
declare abstract class LogDestinationProvider {
|
|
133
|
-
abstract write(message: string, entry: LogEntry): void;
|
|
134
|
-
}
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region ../alepha/src/logger/providers/LogFormatterProvider.d.ts
|
|
137
|
-
declare abstract class LogFormatterProvider {
|
|
138
|
-
abstract format(entry: LogEntry): string;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region ../alepha/src/logger/services/Logger.d.ts
|
|
142
|
-
declare class Logger implements LoggerInterface {
|
|
143
|
-
protected readonly alepha: Alepha;
|
|
144
|
-
protected readonly formatter: LogFormatterProvider;
|
|
145
|
-
protected readonly destination: LogDestinationProvider;
|
|
146
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
147
|
-
protected readonly levels: Record<string, number>;
|
|
148
|
-
protected readonly service: string;
|
|
149
|
-
protected readonly module: string;
|
|
150
|
-
protected readonly app?: string;
|
|
151
|
-
protected appLogLevel: string;
|
|
152
|
-
protected logLevel: LogLevel;
|
|
153
|
-
constructor(service: string, module: string);
|
|
154
|
-
get context(): string | undefined;
|
|
155
|
-
get level(): string;
|
|
156
|
-
parseLevel(level: string, app: string): LogLevel;
|
|
157
|
-
private matchesPattern;
|
|
158
|
-
asLogLevel(something: string): LogLevel;
|
|
159
|
-
error(message: string, data?: unknown): void;
|
|
160
|
-
warn(message: string, data?: unknown): void;
|
|
161
|
-
info(message: string, data?: unknown): void;
|
|
162
|
-
debug(message: string, data?: unknown): void;
|
|
163
|
-
trace(message: string, data?: unknown): void;
|
|
164
|
-
protected log(level: LogLevel, message: string, data?: unknown): void;
|
|
165
|
-
protected emit(entry: LogEntry, message?: string): void;
|
|
166
|
-
}
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region ../alepha/src/logger/index.d.ts
|
|
169
|
-
declare const envSchema$6: alepha139.TObject<{
|
|
170
|
-
/**
|
|
171
|
-
* Default log level for the application.
|
|
172
|
-
*
|
|
173
|
-
* Default by environment:
|
|
174
|
-
* - dev = info
|
|
175
|
-
* - prod = info
|
|
176
|
-
* - test = error
|
|
177
|
-
*
|
|
178
|
-
* Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
|
|
179
|
-
*
|
|
180
|
-
* Level can be set for a specific module:
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
|
|
184
|
-
* LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
|
|
185
|
-
*/
|
|
186
|
-
LOG_LEVEL: alepha139.TOptional<alepha139.TString>;
|
|
187
|
-
/**
|
|
188
|
-
* Built-in log formats.
|
|
189
|
-
* - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
|
|
190
|
-
* - "pretty" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
|
|
191
|
-
* - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
|
|
192
|
-
*/
|
|
193
|
-
LOG_FORMAT: alepha139.TOptional<alepha139.TUnsafe<"json" | "pretty" | "raw">>;
|
|
194
|
-
}>;
|
|
195
|
-
declare module "alepha" {
|
|
196
|
-
interface Env extends Partial<Static<typeof envSchema$6>> {}
|
|
197
|
-
interface State {
|
|
198
|
-
/**
|
|
199
|
-
* Current log level for the application or specific modules.
|
|
200
|
-
*/
|
|
201
|
-
"alepha.logger.level"?: string;
|
|
202
|
-
}
|
|
203
|
-
interface Hooks {
|
|
204
|
-
log: {
|
|
205
|
-
message?: string;
|
|
206
|
-
entry: LogEntry;
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
//#endregion
|
|
211
|
-
//#region ../alepha/src/server/constants/routeMethods.d.ts
|
|
212
|
-
declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
|
|
213
|
-
type RouteMethod = (typeof routeMethods)[number];
|
|
214
|
-
//#endregion
|
|
215
|
-
//#region ../alepha/src/router/providers/RouterProvider.d.ts
|
|
216
|
-
declare abstract class RouterProvider<T$1 extends Route = Route> {
|
|
217
|
-
protected routePathRegex: RegExp;
|
|
218
|
-
protected tree: Tree<T$1>;
|
|
219
|
-
protected cache: Map<string, RouteMatch<T$1>>;
|
|
220
|
-
match(path: string): RouteMatch<T$1>;
|
|
221
|
-
protected test(path: string): void;
|
|
222
|
-
protected push(route: T$1): void;
|
|
223
|
-
protected createRouteMatch(path: string): RouteMatch<T$1>;
|
|
224
|
-
protected mapParams(match: RouteMatch<T$1>): RouteMatch<T$1>;
|
|
225
|
-
protected createParts(path: string): string[];
|
|
226
|
-
}
|
|
227
|
-
interface RouteMatch<T$1 extends Route> {
|
|
228
|
-
route?: T$1;
|
|
229
|
-
params?: Record<string, string>;
|
|
230
|
-
}
|
|
231
|
-
interface Route {
|
|
232
|
-
path: string;
|
|
233
|
-
/**
|
|
234
|
-
* Rename a param in the route.
|
|
235
|
-
* This is automatically filled when you have scenarios like:
|
|
236
|
-
* `/customers/:id` and `/customers/:userId/payments`
|
|
237
|
-
*
|
|
238
|
-
* In this case, `:id` will be renamed to `:userId` in the second route.
|
|
239
|
-
*/
|
|
240
|
-
mapParams?: Record<string, string>;
|
|
241
|
-
}
|
|
242
|
-
interface Tree<T$1 extends Route> {
|
|
243
|
-
route?: T$1;
|
|
244
|
-
children: {
|
|
245
|
-
[key: string]: Tree<T$1>;
|
|
246
|
-
};
|
|
247
|
-
param?: {
|
|
248
|
-
route?: T$1;
|
|
249
|
-
name: string;
|
|
250
|
-
children: {
|
|
251
|
-
[key: string]: Tree<T$1>;
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
wildcard?: {
|
|
255
|
-
route: T$1;
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region ../alepha/src/server/helpers/ServerReply.d.ts
|
|
260
|
-
/**
|
|
261
|
-
* Helper for building server replies.
|
|
262
|
-
*/
|
|
263
|
-
declare class ServerReply {
|
|
264
|
-
headers: Record<string, string> & {
|
|
265
|
-
"set-cookie"?: string[];
|
|
266
|
-
};
|
|
267
|
-
status?: number;
|
|
268
|
-
body?: any;
|
|
269
|
-
/**
|
|
270
|
-
* Redirect to a given URL with optional status code (default 302).
|
|
271
|
-
*/
|
|
272
|
-
redirect(url: string, status?: number): void;
|
|
273
|
-
/**
|
|
274
|
-
* Set the response status code.
|
|
275
|
-
*/
|
|
276
|
-
setStatus(status: number): this;
|
|
277
|
-
/**
|
|
278
|
-
* Set a response header.
|
|
279
|
-
*/
|
|
280
|
-
setHeader(name: string, value: string): this;
|
|
281
|
-
/**
|
|
282
|
-
* Set the response body.
|
|
283
|
-
*/
|
|
284
|
-
setBody(body: any): this;
|
|
285
|
-
}
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region ../alepha/src/server/services/UserAgentParser.d.ts
|
|
288
|
-
interface UserAgentInfo {
|
|
289
|
-
os: "Windows" | "Android" | "Ubuntu" | "MacOS" | "iOS" | "Linux" | "FreeBSD" | "OpenBSD" | "ChromeOS" | "BlackBerry" | "Symbian" | "Windows Phone";
|
|
290
|
-
browser: "Chrome" | "Firefox" | "Safari" | "Edge" | "Opera" | "Internet Explorer" | "Brave" | "Vivaldi" | "Samsung Browser" | "UC Browser" | "Yandex";
|
|
291
|
-
device: "MOBILE" | "DESKTOP" | "TABLET";
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Simple User-Agent parser to detect OS, browser, and device type.
|
|
295
|
-
* This parser is not exhaustive and may not cover all edge cases.
|
|
296
|
-
*
|
|
297
|
-
* Use result for non
|
|
298
|
-
*/
|
|
299
|
-
declare class UserAgentParser {
|
|
300
|
-
parse(userAgent?: string): UserAgentInfo;
|
|
301
|
-
}
|
|
302
|
-
//#endregion
|
|
303
|
-
//#region ../alepha/src/server/interfaces/ServerRequest.d.ts
|
|
304
|
-
type TRequestBody = TObject | TString | TArray | TRecord | TStream;
|
|
305
|
-
type TResponseBody = TObject | TString | TRecord | TFile | TArray | TStream | TVoid;
|
|
306
|
-
interface RequestConfigSchema {
|
|
307
|
-
body?: TRequestBody;
|
|
308
|
-
params?: TObject;
|
|
309
|
-
query?: TObject;
|
|
310
|
-
headers?: TObject;
|
|
311
|
-
response?: TResponseBody;
|
|
312
|
-
}
|
|
313
|
-
interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
|
|
314
|
-
body: TConfig["body"] extends TRequestBody ? Static<TConfig["body"]> : any;
|
|
315
|
-
headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
|
|
316
|
-
params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
|
|
317
|
-
query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, any>;
|
|
318
|
-
}
|
|
319
|
-
type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
|
|
320
|
-
interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
|
|
321
|
-
/**
|
|
322
|
-
* HTTP method used for this request.
|
|
323
|
-
*/
|
|
324
|
-
method: RouteMethod;
|
|
325
|
-
/**
|
|
326
|
-
* Full request URL.
|
|
327
|
-
*/
|
|
328
|
-
url: URL;
|
|
329
|
-
/**
|
|
330
|
-
* Unique request ID assigned to this request.
|
|
331
|
-
*/
|
|
332
|
-
requestId: string;
|
|
333
|
-
/**
|
|
334
|
-
* Client IP address.
|
|
335
|
-
* Will parse `X-Forwarded-For` header if present.
|
|
336
|
-
*/
|
|
337
|
-
ip?: string;
|
|
338
|
-
/**
|
|
339
|
-
* Value of the `Host` header sent by the client.
|
|
340
|
-
*/
|
|
341
|
-
host?: string;
|
|
342
|
-
/**
|
|
343
|
-
* Browser user agent information.
|
|
344
|
-
* Information are not guaranteed to be accurate. Use with caution.
|
|
345
|
-
*
|
|
346
|
-
* @see {@link UserAgentParser}
|
|
347
|
-
*/
|
|
348
|
-
userAgent: UserAgentInfo;
|
|
349
|
-
/**
|
|
350
|
-
* Arbitrary metadata attached to the request. Can be used by middlewares to store information.
|
|
351
|
-
*/
|
|
352
|
-
metadata: Record<string, any>;
|
|
353
|
-
/**
|
|
354
|
-
* Reply object to be used to send response.
|
|
355
|
-
*/
|
|
356
|
-
reply: ServerReply;
|
|
357
|
-
/**
|
|
358
|
-
* The raw underlying request object (Web Request).
|
|
359
|
-
*/
|
|
360
|
-
raw: ServerRawRequest;
|
|
361
|
-
}
|
|
362
|
-
interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
|
|
363
|
-
/**
|
|
364
|
-
* Handler function for this route.
|
|
365
|
-
*/
|
|
366
|
-
handler: ServerHandler<TConfig>;
|
|
367
|
-
/**
|
|
368
|
-
* HTTP method for this route.
|
|
369
|
-
*/
|
|
370
|
-
method?: RouteMethod;
|
|
371
|
-
/**
|
|
372
|
-
* Request/response schema for this route.
|
|
373
|
-
*
|
|
374
|
-
* Request schema contains:
|
|
375
|
-
* - body, for POST/PUT/PATCH requests
|
|
376
|
-
* - params, for URL parameters (e.g. /user/:id)
|
|
377
|
-
* - query, for URL query parameters (e.g. /user?id=123)
|
|
378
|
-
* - headers, for HTTP headers
|
|
379
|
-
*
|
|
380
|
-
* Response schema contains:
|
|
381
|
-
* - response
|
|
382
|
-
*
|
|
383
|
-
* Response schema is used to validate and serialize the response sent by the handler.
|
|
384
|
-
*/
|
|
385
|
-
schema?: TConfig;
|
|
386
|
-
/**
|
|
387
|
-
* @see ServerLoggerProvider
|
|
388
|
-
*/
|
|
389
|
-
silent?: boolean;
|
|
390
|
-
}
|
|
391
|
-
type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TResponseBody ? Static<TConfig["response"]> : ResponseBodyType;
|
|
392
|
-
type ResponseKind = "json" | "text" | "void" | "file" | "any";
|
|
393
|
-
type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
|
|
394
|
-
type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
|
|
395
|
-
interface ServerResponse$1 {
|
|
396
|
-
body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
|
|
397
|
-
headers: Record<string, string>;
|
|
398
|
-
status: number;
|
|
399
|
-
}
|
|
400
|
-
type ServerRouteRequestHandler = (request: ServerRequestData) => Promise<ServerResponse$1>;
|
|
401
|
-
interface ServerRouteMatcher extends Route {
|
|
402
|
-
handler: ServerRouteRequestHandler;
|
|
403
|
-
}
|
|
404
|
-
interface ServerRequestData {
|
|
405
|
-
method: RouteMethod;
|
|
406
|
-
url: URL;
|
|
407
|
-
headers: Record<string, string>;
|
|
408
|
-
query: Record<string, string>;
|
|
409
|
-
params: Record<string, string>;
|
|
410
|
-
raw: ServerRawRequest;
|
|
411
|
-
}
|
|
412
|
-
interface ServerRawRequest {
|
|
413
|
-
node?: NodeRequestEvent;
|
|
414
|
-
web?: WebRequestEvent;
|
|
415
|
-
}
|
|
416
|
-
interface NodeRequestEvent {
|
|
417
|
-
req: IncomingMessage;
|
|
418
|
-
res: ServerResponse;
|
|
419
|
-
}
|
|
420
|
-
interface WebRequestEvent {
|
|
421
|
-
req: Request;
|
|
422
|
-
res?: Response;
|
|
423
|
-
}
|
|
424
|
-
//#endregion
|
|
425
|
-
//#region ../alepha/src/server/services/ServerRequestParser.d.ts
|
|
426
|
-
declare class ServerRequestParser {
|
|
427
|
-
protected readonly alepha: Alepha;
|
|
428
|
-
protected readonly userAgentParser: UserAgentParser;
|
|
429
|
-
createServerRequest(rawRequest: ServerRequestData): ServerRequest;
|
|
430
|
-
getRequestId(request: ServerRequestData): string | undefined;
|
|
431
|
-
getRequestUserAgent(request: ServerRequestData): UserAgentInfo;
|
|
432
|
-
getRequestIp(request: ServerRequestData): string | undefined;
|
|
433
|
-
}
|
|
434
|
-
//#endregion
|
|
435
|
-
//#region ../alepha/src/server/providers/ServerTimingProvider.d.ts
|
|
436
|
-
type TimingMap = Record<string, [number, number]>;
|
|
437
|
-
declare class ServerTimingProvider {
|
|
438
|
-
protected readonly log: Logger;
|
|
439
|
-
protected readonly alepha: Alepha;
|
|
440
|
-
options: {
|
|
441
|
-
prefix: string;
|
|
442
|
-
disabled: boolean;
|
|
443
|
-
};
|
|
444
|
-
readonly onRequest: alepha139.HookDescriptor<"server:onRequest">;
|
|
445
|
-
readonly onResponse: alepha139.HookDescriptor<"server:onResponse">;
|
|
446
|
-
protected get handlerName(): string;
|
|
447
|
-
beginTiming(name: string): void;
|
|
448
|
-
endTiming(name: string): void;
|
|
449
|
-
protected setDuration(name: string, timing: TimingMap): void;
|
|
450
|
-
}
|
|
451
|
-
//#endregion
|
|
452
|
-
//#region ../alepha/src/server/providers/ServerRouterProvider.d.ts
|
|
453
|
-
/**
|
|
454
|
-
* Main router for all routes on the server side.
|
|
455
|
-
*
|
|
456
|
-
* - $route => generic route
|
|
457
|
-
* - $action => action route (for API calls)
|
|
458
|
-
* - $page => React route (for SSR)
|
|
459
|
-
*/
|
|
460
|
-
declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
|
|
461
|
-
protected readonly log: Logger;
|
|
462
|
-
protected readonly alepha: Alepha;
|
|
463
|
-
protected readonly routes: ServerRoute[];
|
|
464
|
-
protected readonly serverTimingProvider: ServerTimingProvider;
|
|
465
|
-
protected readonly serverRequestParser: ServerRequestParser;
|
|
466
|
-
/**
|
|
467
|
-
* Get all registered routes, optionally filtered by a pattern.
|
|
468
|
-
*
|
|
469
|
-
* Pattern accept simple wildcard '*' at the end.
|
|
470
|
-
* Example: '/api/*' will match all routes starting with '/api/' but '/api/' will match only that exact route.
|
|
471
|
-
*/
|
|
472
|
-
getRoutes(pattern?: string): ServerRoute[];
|
|
473
|
-
createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
|
|
474
|
-
protected getContextId(headers: Record<string, string>): string;
|
|
475
|
-
protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
|
|
476
|
-
status: number;
|
|
477
|
-
headers: Record<string, string> & {
|
|
478
|
-
"set-cookie"?: string[];
|
|
479
|
-
};
|
|
480
|
-
body: any;
|
|
481
|
-
}>;
|
|
482
|
-
protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
|
|
483
|
-
serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
|
|
484
|
-
protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
|
|
485
|
-
protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
|
|
486
|
-
validateRequest(route: {
|
|
487
|
-
schema?: RequestConfigSchema;
|
|
488
|
-
}, request: ServerRequestConfig): void;
|
|
489
|
-
}
|
|
490
|
-
//#endregion
|
|
491
|
-
//#region ../alepha/src/server/providers/ServerProvider.d.ts
|
|
492
|
-
/**
|
|
493
|
-
* Base server provider to handle incoming requests and route them.
|
|
494
|
-
*
|
|
495
|
-
* This is the default implementation for serverless environments.
|
|
496
|
-
*
|
|
497
|
-
* ServerProvider supports both Node.js HTTP requests and Web (Fetch API) requests.
|
|
498
|
-
*/
|
|
499
|
-
declare class ServerProvider {
|
|
500
|
-
protected readonly log: Logger;
|
|
501
|
-
protected readonly alepha: Alepha;
|
|
502
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
503
|
-
protected readonly router: ServerRouterProvider;
|
|
504
|
-
protected readonly internalServerErrorMessage = "Internal Server Error";
|
|
505
|
-
get hostname(): string;
|
|
506
|
-
/**
|
|
507
|
-
* When a Node.js HTTP request is received from outside. (Vercel, AWS Lambda, etc.)
|
|
508
|
-
*/
|
|
509
|
-
protected readonly onNodeRequest: alepha139.HookDescriptor<"node:request">;
|
|
510
|
-
/**
|
|
511
|
-
* When a Web (Fetch API) request is received from outside. (Netlify, Cloudflare Workers, etc.)
|
|
512
|
-
*/
|
|
513
|
-
protected readonly onWebRequest: alepha139.HookDescriptor<"web:request">;
|
|
514
|
-
/**
|
|
515
|
-
* Handle Node.js HTTP request event.
|
|
516
|
-
*
|
|
517
|
-
* Technically, we just convert Node.js request to Web Standard Request.
|
|
518
|
-
*/
|
|
519
|
-
handleNodeRequest(nodeRequestEvent: NodeRequestEvent): Promise<void>;
|
|
520
|
-
/**
|
|
521
|
-
* Handle Web (Fetch API) request event.
|
|
522
|
-
*/
|
|
523
|
-
handleWebRequest(ev: WebRequestEvent): Promise<void>;
|
|
524
|
-
/**
|
|
525
|
-
* Helper for Vite development mode to let Vite handle (or not) 404.
|
|
526
|
-
*/
|
|
527
|
-
protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
|
|
528
|
-
}
|
|
529
|
-
//#endregion
|
|
530
|
-
//#region ../alepha/src/cache/providers/CacheProvider.d.ts
|
|
531
|
-
/**
|
|
532
|
-
* Cache provider interface.
|
|
533
|
-
*
|
|
534
|
-
* All methods are asynchronous and return promises.
|
|
535
|
-
* Values are stored as Uint8Array.
|
|
536
|
-
*/
|
|
537
|
-
declare abstract class CacheProvider {
|
|
538
|
-
/**
|
|
539
|
-
* Get the value of a key.
|
|
540
|
-
*
|
|
541
|
-
* @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
|
|
542
|
-
* @param key The key of the value to get.
|
|
543
|
-
*
|
|
544
|
-
* @return The value of the key, or undefined if the key does not exist.
|
|
545
|
-
*/
|
|
546
|
-
abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
|
|
547
|
-
/**
|
|
548
|
-
* Set the string value of a key.
|
|
549
|
-
*
|
|
550
|
-
* @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
|
|
551
|
-
* @param key The key of the value to set.
|
|
552
|
-
* @param value The value to set.
|
|
553
|
-
* @param ttl The time-to-live of the key, in milliseconds.
|
|
554
|
-
*
|
|
555
|
-
* @return The value of the key.
|
|
556
|
-
*/
|
|
557
|
-
abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
|
|
558
|
-
/**
|
|
559
|
-
* Remove the specified keys.
|
|
560
|
-
*
|
|
561
|
-
* @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
|
|
562
|
-
* @param keys The keys to delete.
|
|
563
|
-
*/
|
|
564
|
-
abstract del(name: string, ...keys: string[]): Promise<void>;
|
|
565
|
-
abstract has(name: string, key: string): Promise<boolean>;
|
|
566
|
-
abstract keys(name: string, filter?: string): Promise<string[]>;
|
|
567
|
-
/**
|
|
568
|
-
* Remove all keys from all cache names.
|
|
569
|
-
*/
|
|
570
|
-
abstract clear(): Promise<void>;
|
|
571
|
-
}
|
|
572
|
-
//#endregion
|
|
573
|
-
//#region ../alepha/src/cache/descriptors/$cache.d.ts
|
|
574
|
-
interface CacheDescriptorOptions<TReturn = any, TParameter extends any[] = any[]> {
|
|
575
|
-
/**
|
|
576
|
-
* The cache name. This is useful for invalidating multiple caches at once.
|
|
577
|
-
*
|
|
578
|
-
* Store key as `cache:$name:$key`.
|
|
579
|
-
*
|
|
580
|
-
* @default Name of the key of the class.
|
|
581
|
-
*/
|
|
582
|
-
name?: string;
|
|
583
|
-
/**
|
|
584
|
-
* Function which returns cached data.
|
|
585
|
-
*/
|
|
586
|
-
handler?: (...args: TParameter) => TReturn;
|
|
587
|
-
/**
|
|
588
|
-
* The key generator for the cache.
|
|
589
|
-
* If not provided, the arguments will be json.stringify().
|
|
590
|
-
*/
|
|
591
|
-
key?: (...args: TParameter) => string;
|
|
592
|
-
/**
|
|
593
|
-
* The store provider for the cache.
|
|
594
|
-
* If not provided, the default store provider will be used.
|
|
595
|
-
*/
|
|
596
|
-
provider?: InstantiableClass<CacheProvider> | "memory";
|
|
597
|
-
/**
|
|
598
|
-
* The time-to-live for the cache in seconds.
|
|
599
|
-
* Set 0 to skip expiration.
|
|
600
|
-
*
|
|
601
|
-
* @default 300 (5 minutes).
|
|
602
|
-
*/
|
|
603
|
-
ttl?: DurationLike;
|
|
604
|
-
/**
|
|
605
|
-
* If the cache is disabled.
|
|
606
|
-
*/
|
|
607
|
-
disabled?: boolean;
|
|
608
|
-
}
|
|
609
|
-
declare class CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> extends Descriptor<CacheDescriptorOptions<TReturn, TParameter>> {
|
|
610
|
-
protected readonly env: {
|
|
611
|
-
CACHE_ENABLED: boolean;
|
|
612
|
-
CACHE_DEFAULT_TTL: number;
|
|
613
|
-
};
|
|
614
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
615
|
-
protected readonly provider: CacheProvider;
|
|
616
|
-
protected encoder: TextEncoder;
|
|
617
|
-
protected decoder: TextDecoder;
|
|
618
|
-
protected codes: {
|
|
619
|
-
BINARY: number;
|
|
620
|
-
JSON: number;
|
|
621
|
-
STRING: number;
|
|
622
|
-
};
|
|
623
|
-
get container(): string;
|
|
624
|
-
run(...args: TParameter): Promise<TReturn>;
|
|
625
|
-
key(...args: TParameter): string;
|
|
626
|
-
invalidate(...keys: string[]): Promise<void>;
|
|
627
|
-
set(key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
|
|
628
|
-
get(key: string): Promise<TReturn | undefined>;
|
|
629
|
-
protected serialize<TReturn>(value: TReturn): Uint8Array;
|
|
630
|
-
protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
|
|
631
|
-
protected $provider(): CacheProvider;
|
|
632
|
-
}
|
|
633
|
-
interface CacheDescriptorFn<TReturn = any, TParameter extends any[] = any[]> extends CacheDescriptor<TReturn, TParameter> {
|
|
634
|
-
/**
|
|
635
|
-
* Run the cache descriptor with the provided arguments.
|
|
636
|
-
*/
|
|
637
|
-
(...args: TParameter): Promise<TReturn>;
|
|
638
|
-
}
|
|
639
|
-
//#endregion
|
|
640
|
-
//#region ../alepha/src/server/services/HttpClient.d.ts
|
|
641
|
-
declare class HttpClient {
|
|
642
|
-
protected readonly log: Logger;
|
|
643
|
-
protected readonly alepha: Alepha;
|
|
644
|
-
readonly cache: CacheDescriptorFn<HttpClientCache, any[]>;
|
|
645
|
-
protected readonly pendingRequests: HttpClientPendingRequests;
|
|
646
|
-
fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
|
|
647
|
-
fetch<T$1 extends TSchema>(url: string, request?: RequestInitWithOptions<T$1>): Promise<FetchResponse<Static<T$1>>>;
|
|
648
|
-
protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
|
|
649
|
-
protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
|
|
650
|
-
protected responseData(response: Response, options: FetchOptions): Promise<any>;
|
|
651
|
-
protected isMaybeFile(response: Response): boolean;
|
|
652
|
-
protected createFileLike(response: Response, defaultFileName?: string): FileLike;
|
|
653
|
-
pathVariables(url: string, action: {
|
|
654
|
-
schema?: {
|
|
655
|
-
params?: TObject;
|
|
656
|
-
};
|
|
657
|
-
}, args?: ServerRequestConfigEntry): string;
|
|
658
|
-
queryParams(url: string, action: {
|
|
659
|
-
schema?: {
|
|
660
|
-
query?: TObject;
|
|
661
|
-
};
|
|
662
|
-
}, args?: ServerRequestConfigEntry): string;
|
|
663
|
-
}
|
|
664
|
-
interface FetchOptions<T$1 extends TSchema = TSchema> {
|
|
665
|
-
/**
|
|
666
|
-
* Key to identify the request in the pending requests.
|
|
667
|
-
*/
|
|
668
|
-
key?: string;
|
|
669
|
-
/**
|
|
670
|
-
* The schema to validate the response against.
|
|
671
|
-
*/
|
|
672
|
-
schema?: {
|
|
673
|
-
response?: T$1;
|
|
674
|
-
};
|
|
675
|
-
/**
|
|
676
|
-
* Built-in cache options.
|
|
677
|
-
*/
|
|
678
|
-
localCache?: boolean | number | DurationLike;
|
|
679
|
-
}
|
|
680
|
-
type RequestInitWithOptions<T$1 extends TSchema = TSchema> = RequestInit & FetchOptions<T$1>;
|
|
681
|
-
interface FetchResponse<T$1 = any> {
|
|
682
|
-
data: T$1;
|
|
683
|
-
status: number;
|
|
684
|
-
statusText: string;
|
|
685
|
-
headers: Headers;
|
|
686
|
-
raw?: Response;
|
|
687
|
-
}
|
|
688
|
-
type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
|
|
689
|
-
interface HttpClientCache {
|
|
690
|
-
data: any;
|
|
691
|
-
etag?: string;
|
|
692
|
-
}
|
|
693
|
-
interface FetchActionArgs {
|
|
694
|
-
action: HttpAction;
|
|
695
|
-
host?: string;
|
|
696
|
-
config?: ServerRequestConfigEntry;
|
|
697
|
-
options?: ClientRequestOptions;
|
|
698
|
-
}
|
|
699
|
-
interface HttpAction {
|
|
700
|
-
method?: string;
|
|
701
|
-
prefix?: string;
|
|
702
|
-
path: string;
|
|
703
|
-
requestBodyType?: string;
|
|
704
|
-
schema?: {
|
|
705
|
-
params?: TObject;
|
|
706
|
-
query?: TObject;
|
|
707
|
-
body?: TRequestBody;
|
|
708
|
-
response?: TResponseBody;
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
//#endregion
|
|
712
|
-
//#region ../alepha/src/server/descriptors/$action.d.ts
|
|
713
|
-
interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
|
|
714
|
-
/**
|
|
715
|
-
* Name of the action.
|
|
716
|
-
*
|
|
717
|
-
* - It will be used to generate the route path if `path` is not provided.
|
|
718
|
-
* - It will be used to generate the permission name if `security` is enabled.
|
|
719
|
-
*/
|
|
720
|
-
name?: string;
|
|
721
|
-
/**
|
|
722
|
-
* Group actions together.
|
|
723
|
-
*
|
|
724
|
-
* - If not provided, the service name containing the route will be used.
|
|
725
|
-
* - It will be used as Tag for documentation purposes.
|
|
726
|
-
* - It will be used for permission name generation if `security` is enabled.
|
|
727
|
-
*
|
|
728
|
-
* @example
|
|
729
|
-
* ```ts
|
|
730
|
-
* // group = "MyController"
|
|
731
|
-
* class MyController {
|
|
732
|
-
* hello = $action({ handler: () => "Hello World" });
|
|
733
|
-
* }
|
|
734
|
-
*
|
|
735
|
-
* // group = "users"
|
|
736
|
-
* class MyOtherController {
|
|
737
|
-
* group = "users";
|
|
738
|
-
* a1 = $action({ handler: () => "Action 1", group: this.group });
|
|
739
|
-
* a2 = $action({ handler: () => "Action 2", group: this.group });
|
|
740
|
-
* }
|
|
741
|
-
* ```
|
|
742
|
-
*/
|
|
743
|
-
group?: string;
|
|
744
|
-
/**
|
|
745
|
-
* Pathname of the route. If not provided, property key is used.
|
|
746
|
-
*/
|
|
747
|
-
path?: string;
|
|
748
|
-
/**
|
|
749
|
-
* The route method.
|
|
750
|
-
*
|
|
751
|
-
* - If not provided, it will be set to "GET" by default.
|
|
752
|
-
* - If not provider and a body is provided, it will be set to "POST".
|
|
753
|
-
*
|
|
754
|
-
* Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
|
|
755
|
-
*/
|
|
756
|
-
method?: RouteMethod;
|
|
757
|
-
/**
|
|
758
|
-
* The config schema of the route.
|
|
759
|
-
* - body: The request body schema.
|
|
760
|
-
* - params: Path variables schema.
|
|
761
|
-
* - query: The request query-params schema.
|
|
762
|
-
* - response: The response schema.
|
|
763
|
-
*/
|
|
764
|
-
schema?: TConfig;
|
|
765
|
-
/**
|
|
766
|
-
* A short description of the action. Used for documentation purposes.
|
|
767
|
-
*/
|
|
768
|
-
description?: string;
|
|
769
|
-
/**
|
|
770
|
-
* Disable the route. Useful with env variables do disable one specific route.
|
|
771
|
-
* Route won't be available in the API but can still be called locally!
|
|
772
|
-
*/
|
|
773
|
-
disabled?: boolean;
|
|
774
|
-
/**
|
|
775
|
-
* Main route handler. This is where the route logic is implemented.
|
|
776
|
-
*/
|
|
777
|
-
handler: ServerActionHandler<TConfig>;
|
|
778
|
-
}
|
|
779
|
-
declare class ActionDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<ActionDescriptorOptions<TConfig>> {
|
|
780
|
-
protected readonly log: Logger;
|
|
781
|
-
protected readonly env: {
|
|
782
|
-
SERVER_API_PREFIX: string;
|
|
783
|
-
};
|
|
784
|
-
protected readonly httpClient: HttpClient;
|
|
785
|
-
protected readonly serverProvider: ServerProvider;
|
|
786
|
-
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
787
|
-
protected onInit(): void;
|
|
788
|
-
get prefix(): string;
|
|
789
|
-
get route(): ServerRoute;
|
|
790
|
-
/**
|
|
791
|
-
* Returns the name of the action.
|
|
792
|
-
*/
|
|
793
|
-
get name(): string;
|
|
794
|
-
/**
|
|
795
|
-
* Returns the group of the action. (e.g. "orders", "admin", etc.)
|
|
796
|
-
*/
|
|
797
|
-
get group(): string;
|
|
798
|
-
/**
|
|
799
|
-
* Returns the HTTP method of the action.
|
|
800
|
-
*/
|
|
801
|
-
get method(): RouteMethod;
|
|
802
|
-
/**
|
|
803
|
-
* Returns the path of the action.
|
|
804
|
-
*
|
|
805
|
-
* Path is prefixed by `/api` by default.
|
|
806
|
-
*/
|
|
807
|
-
get path(): string;
|
|
808
|
-
get schema(): TConfig | undefined;
|
|
809
|
-
getBodyContentType(): string | undefined;
|
|
810
|
-
/**
|
|
811
|
-
* Call the action handler directly.
|
|
812
|
-
* There is no HTTP layer involved.
|
|
813
|
-
*/
|
|
814
|
-
run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
|
|
815
|
-
/**
|
|
816
|
-
* Works like `run`, but always fetches (http request) the route.
|
|
817
|
-
*/
|
|
818
|
-
fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
|
|
819
|
-
}
|
|
820
|
-
type ClientRequestEntry<TConfig extends RequestConfigSchema, T$1 = ClientRequestEntryContainer<TConfig>> = { [K in keyof T$1 as T$1[K] extends undefined ? never : K]: T$1[K] };
|
|
821
|
-
type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
|
|
822
|
-
body: TConfig["body"] extends TObject ? Static<TConfig["body"]> : undefined;
|
|
823
|
-
params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : undefined;
|
|
824
|
-
headers?: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : undefined;
|
|
825
|
-
query?: TConfig["query"] extends TObject ? Partial<Static<TConfig["query"]>> : undefined;
|
|
826
|
-
};
|
|
827
|
-
interface ClientRequestOptions extends FetchOptions {
|
|
828
|
-
/**
|
|
829
|
-
* Standard request fetch options.
|
|
830
|
-
*/
|
|
831
|
-
request?: RequestInit;
|
|
832
|
-
}
|
|
833
|
-
type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
|
|
834
|
-
/**
|
|
835
|
-
* Specific handler for server actions.
|
|
836
|
-
*/
|
|
837
|
-
type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
|
|
838
|
-
/**
|
|
839
|
-
* Server Action Request Interface
|
|
840
|
-
*
|
|
841
|
-
* Can be extended with module augmentation to add custom properties (like `user` in Server Security).
|
|
842
|
-
*
|
|
843
|
-
* This is NOT Server Request, but a specific type for actions.
|
|
844
|
-
*/
|
|
845
|
-
interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
|
|
846
|
-
//#endregion
|
|
847
|
-
//#region ../alepha/src/server/schemas/errorSchema.d.ts
|
|
848
|
-
declare const errorSchema: alepha139.TObject<{
|
|
849
|
-
error: alepha139.TString;
|
|
850
|
-
status: alepha139.TInteger;
|
|
851
|
-
message: alepha139.TString;
|
|
852
|
-
details: alepha139.TOptional<alepha139.TString>;
|
|
853
|
-
requestId: alepha139.TOptional<alepha139.TString>;
|
|
854
|
-
cause: alepha139.TOptional<alepha139.TObject<{
|
|
855
|
-
name: alepha139.TString;
|
|
856
|
-
message: alepha139.TString;
|
|
857
|
-
}>>;
|
|
858
|
-
}>;
|
|
859
|
-
type ErrorSchema = Static<typeof errorSchema>;
|
|
860
|
-
//#endregion
|
|
861
|
-
//#region ../alepha/src/server/errors/HttpError.d.ts
|
|
862
|
-
declare class HttpError extends AlephaError {
|
|
863
|
-
name: string;
|
|
864
|
-
static is: (error: unknown, status?: number) => error is HttpErrorLike;
|
|
865
|
-
static toJSON(error: HttpError): ErrorSchema;
|
|
866
|
-
readonly error: string;
|
|
867
|
-
readonly status: number;
|
|
868
|
-
readonly requestId?: string;
|
|
869
|
-
readonly details?: string;
|
|
870
|
-
readonly reason?: {
|
|
871
|
-
name: string;
|
|
872
|
-
message: string;
|
|
873
|
-
};
|
|
874
|
-
constructor(options: Partial<ErrorSchema>, cause?: unknown);
|
|
875
|
-
}
|
|
876
|
-
interface HttpErrorLike extends Error {
|
|
877
|
-
status: number;
|
|
878
|
-
}
|
|
879
|
-
//#endregion
|
|
880
|
-
//#region ../alepha/src/server/providers/BunHttpServerProvider.d.ts
|
|
881
|
-
declare const envSchema$5: alepha139.TObject<{
|
|
882
|
-
SERVER_PORT: alepha139.TInteger;
|
|
883
|
-
SERVER_HOST: alepha139.TString;
|
|
884
|
-
}>;
|
|
885
|
-
declare module "alepha" {
|
|
886
|
-
interface Env extends Partial<Static<typeof envSchema$5>> {}
|
|
887
|
-
}
|
|
888
|
-
//#endregion
|
|
889
|
-
//#region ../alepha/src/server/providers/NodeHttpServerProvider.d.ts
|
|
890
|
-
declare const envSchema$4: alepha139.TObject<{
|
|
891
|
-
SERVER_PORT: alepha139.TInteger;
|
|
892
|
-
SERVER_HOST: alepha139.TString;
|
|
893
|
-
}>;
|
|
894
|
-
declare module "alepha" {
|
|
895
|
-
interface Env extends Partial<Static<typeof envSchema$4>> {}
|
|
896
|
-
}
|
|
897
|
-
//#endregion
|
|
898
|
-
//#region ../alepha/src/server/index.d.ts
|
|
899
|
-
declare module "alepha" {
|
|
900
|
-
interface State {
|
|
901
|
-
"alepha.node.server"?: Server;
|
|
902
|
-
}
|
|
903
|
-
interface Hooks {
|
|
904
|
-
"action:onRequest": {
|
|
905
|
-
action: ActionDescriptor<RequestConfigSchema>;
|
|
906
|
-
request: ServerRequest;
|
|
907
|
-
options: ClientRequestOptions;
|
|
908
|
-
};
|
|
909
|
-
"action:onResponse": {
|
|
910
|
-
action: ActionDescriptor<RequestConfigSchema>;
|
|
911
|
-
request: ServerRequest;
|
|
912
|
-
options: ClientRequestOptions;
|
|
913
|
-
response: any;
|
|
914
|
-
};
|
|
915
|
-
"server:onRequest": {
|
|
916
|
-
route: ServerRoute;
|
|
917
|
-
request: ServerRequest;
|
|
918
|
-
};
|
|
919
|
-
"server:onError": {
|
|
920
|
-
route: ServerRoute;
|
|
921
|
-
request: ServerRequest;
|
|
922
|
-
error: Error;
|
|
923
|
-
};
|
|
924
|
-
"server:onSend": {
|
|
925
|
-
route: ServerRoute;
|
|
926
|
-
request: ServerRequest;
|
|
927
|
-
};
|
|
928
|
-
"server:onResponse": {
|
|
929
|
-
route: ServerRoute;
|
|
930
|
-
request: ServerRequest;
|
|
931
|
-
response: ServerResponse$1;
|
|
932
|
-
};
|
|
933
|
-
"client:onRequest": {
|
|
934
|
-
route: HttpAction;
|
|
935
|
-
config: ServerRequestConfigEntry;
|
|
936
|
-
options: ClientRequestOptions;
|
|
937
|
-
headers: Record<string, string>;
|
|
938
|
-
request: RequestInit;
|
|
939
|
-
};
|
|
940
|
-
"client:beforeFetch": {
|
|
941
|
-
url: string;
|
|
942
|
-
options: FetchOptions;
|
|
943
|
-
request: RequestInit;
|
|
944
|
-
};
|
|
945
|
-
"client:onError": {
|
|
946
|
-
route?: HttpAction;
|
|
947
|
-
error: HttpError;
|
|
948
|
-
};
|
|
949
|
-
"node:request": NodeRequestEvent;
|
|
950
|
-
"web:request": WebRequestEvent;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
//#endregion
|
|
954
|
-
//#region ../alepha/src/server-cache/providers/ServerCacheProvider.d.ts
|
|
955
|
-
declare module "alepha/server" {
|
|
956
|
-
interface ServerRoute {
|
|
957
|
-
/**
|
|
958
|
-
* Enable caching for this route.
|
|
959
|
-
* - If true: enables both store and etag
|
|
960
|
-
* - If object: fine-grained control over store, etag, and cache-control headers
|
|
961
|
-
*
|
|
962
|
-
* @default false
|
|
963
|
-
*/
|
|
964
|
-
cache?: ServerRouteCache;
|
|
965
|
-
}
|
|
966
|
-
interface ActionDescriptor<TConfig extends RequestConfigSchema> {
|
|
967
|
-
invalidate: () => Promise<void>;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
type ServerRouteCache =
|
|
971
|
-
/**
|
|
972
|
-
* If true, enables caching with:
|
|
973
|
-
* - store: true
|
|
974
|
-
* - etag: true
|
|
975
|
-
*/
|
|
976
|
-
boolean
|
|
977
|
-
/**
|
|
978
|
-
* Object configuration for fine-grained cache control.
|
|
979
|
-
*
|
|
980
|
-
* If empty, no caching will be applied.
|
|
981
|
-
*/ | {
|
|
982
|
-
/**
|
|
983
|
-
* If true, enables storing cached responses. (in-memory, Redis, @see alepha/cache for other providers)
|
|
984
|
-
* If a DurationLike is provided, it will be used as the TTL for the cache.
|
|
985
|
-
* If CacheDescriptorOptions is provided, it will be used to configure the cache storage.
|
|
986
|
-
*
|
|
987
|
-
* @default false
|
|
988
|
-
*/
|
|
989
|
-
store?: true | DurationLike | CacheDescriptorOptions;
|
|
990
|
-
/**
|
|
991
|
-
* If true, enables ETag support for the cached responses.
|
|
992
|
-
*/
|
|
993
|
-
etag?: true;
|
|
994
|
-
/**
|
|
995
|
-
* - If true, sets Cache-Control to "public, max-age=300" (5 minutes).
|
|
996
|
-
* - If string, sets Cache-Control to the provided value directly.
|
|
997
|
-
* - If object, configures Cache-Control directives.
|
|
998
|
-
*/
|
|
999
|
-
control?: true
|
|
1000
|
-
/**
|
|
1001
|
-
* If string, sets Cache-Control to the provided value directly.
|
|
1002
|
-
*/ | string
|
|
1003
|
-
/**
|
|
1004
|
-
* If object, configures Cache-Control directives.
|
|
1005
|
-
*/ | {
|
|
1006
|
-
/**
|
|
1007
|
-
* Indicates that the response may be cached by any cache.
|
|
1008
|
-
*/
|
|
1009
|
-
public?: boolean;
|
|
1010
|
-
/**
|
|
1011
|
-
* Indicates that the response is intended for a single user and must not be stored by a shared cache.
|
|
1012
|
-
*/
|
|
1013
|
-
private?: boolean;
|
|
1014
|
-
/**
|
|
1015
|
-
* Forces caches to submit the request to the origin server for validation before releasing a cached copy.
|
|
1016
|
-
*/
|
|
1017
|
-
noCache?: boolean;
|
|
1018
|
-
/**
|
|
1019
|
-
* Instructs caches not to store the response.
|
|
1020
|
-
*/
|
|
1021
|
-
noStore?: boolean;
|
|
1022
|
-
/**
|
|
1023
|
-
* Maximum amount of time a resource is considered fresh.
|
|
1024
|
-
* Can be specified as a number (seconds) or as a DurationLike object.
|
|
1025
|
-
*
|
|
1026
|
-
* @example 300 // 5 minutes in seconds
|
|
1027
|
-
* @example { minutes: 5 } // 5 minutes
|
|
1028
|
-
* @example { hours: 1 } // 1 hour
|
|
1029
|
-
*/
|
|
1030
|
-
maxAge?: number | DurationLike;
|
|
1031
|
-
/**
|
|
1032
|
-
* Overrides max-age for shared caches (e.g., CDNs).
|
|
1033
|
-
* Can be specified as a number (seconds) or as a DurationLike object.
|
|
1034
|
-
*/
|
|
1035
|
-
sMaxAge?: number | DurationLike;
|
|
1036
|
-
/**
|
|
1037
|
-
* Indicates that once a resource becomes stale, caches must not use it without successful validation.
|
|
1038
|
-
*/
|
|
1039
|
-
mustRevalidate?: boolean;
|
|
1040
|
-
/**
|
|
1041
|
-
* Similar to must-revalidate, but only for shared caches.
|
|
1042
|
-
*/
|
|
1043
|
-
proxyRevalidate?: boolean;
|
|
1044
|
-
/**
|
|
1045
|
-
* Indicates that the response can be stored but must be revalidated before each use.
|
|
1046
|
-
*/
|
|
1047
|
-
immutable?: boolean;
|
|
1048
|
-
};
|
|
1049
|
-
};
|
|
1050
|
-
//#endregion
|
|
1051
|
-
//#region src/core/components/ClientOnly.d.ts
|
|
1052
|
-
interface ClientOnlyProps {
|
|
1053
|
-
fallback?: ReactNode;
|
|
1054
|
-
disabled?: boolean;
|
|
1055
|
-
}
|
|
1056
|
-
/**
|
|
1057
|
-
* A small utility component that renders its children only on the client side.
|
|
1058
|
-
*
|
|
1059
|
-
* Optionally, you can provide a fallback React node that will be rendered.
|
|
1060
|
-
*
|
|
1061
|
-
* You should use this component when
|
|
1062
|
-
* - you have code that relies on browser-specific APIs
|
|
1063
|
-
* - you want to avoid server-side rendering for a specific part of your application
|
|
1064
|
-
* - you want to prevent pre-rendering of a component
|
|
1065
|
-
*/
|
|
1066
|
-
declare const ClientOnly: (props: PropsWithChildren<ClientOnlyProps>) => ReactNode;
|
|
1067
|
-
//#endregion
|
|
1068
|
-
//#region src/core/errors/Redirection.d.ts
|
|
1069
|
-
/**
|
|
1070
|
-
* Used for Redirection during the page loading.
|
|
1071
|
-
*
|
|
1072
|
-
* Depends on the context, it can be thrown or just returned.
|
|
1073
|
-
*/
|
|
1074
|
-
declare class Redirection extends Error {
|
|
1075
|
-
readonly redirect: string;
|
|
1076
|
-
constructor(redirect: string);
|
|
1077
|
-
}
|
|
1078
|
-
//#endregion
|
|
1079
|
-
//#region src/core/providers/ReactPageProvider.d.ts
|
|
1080
|
-
declare const envSchema$3: alepha139.TObject<{
|
|
1081
|
-
REACT_STRICT_MODE: alepha139.TBoolean;
|
|
1082
|
-
}>;
|
|
1083
|
-
declare module "alepha" {
|
|
1084
|
-
interface Env extends Partial<Static<typeof envSchema$3>> {}
|
|
1085
|
-
}
|
|
1086
|
-
declare class ReactPageProvider {
|
|
1087
|
-
protected readonly log: Logger;
|
|
1088
|
-
protected readonly env: {
|
|
1089
|
-
REACT_STRICT_MODE: boolean;
|
|
1090
|
-
};
|
|
1091
|
-
protected readonly alepha: Alepha;
|
|
1092
|
-
protected readonly pages: PageRoute[];
|
|
1093
|
-
getPages(): PageRoute[];
|
|
1094
|
-
getConcretePages(): PageRoute[];
|
|
1095
|
-
page(name: string): PageRoute;
|
|
1096
|
-
pathname(name: string, options?: {
|
|
1097
|
-
params?: Record<string, string>;
|
|
1098
|
-
query?: Record<string, string>;
|
|
1099
|
-
}): string;
|
|
1100
|
-
url(name: string, options?: {
|
|
1101
|
-
params?: Record<string, string>;
|
|
1102
|
-
host?: string;
|
|
1103
|
-
}): URL;
|
|
1104
|
-
root(state: ReactRouterState): ReactNode;
|
|
1105
|
-
protected convertStringObjectToObject: (schema?: TSchema, value?: any) => any;
|
|
1106
|
-
/**
|
|
1107
|
-
* Create a new RouterState based on a given route and request.
|
|
1108
|
-
* This method resolves the layers for the route, applying any query and params schemas defined in the route.
|
|
1109
|
-
* It also handles errors and redirects.
|
|
1110
|
-
*/
|
|
1111
|
-
createLayers(route: PageRoute, state: ReactRouterState, previous?: PreviousLayerData[]): Promise<CreateLayersResult>;
|
|
1112
|
-
protected createRedirectionLayer(redirect: string): CreateLayersResult;
|
|
1113
|
-
protected getErrorHandler(route: PageRoute): ErrorHandler | undefined;
|
|
1114
|
-
protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
|
|
1115
|
-
renderError(error: Error): ReactNode;
|
|
1116
|
-
renderEmptyView(): ReactNode;
|
|
1117
|
-
href(page: {
|
|
1118
|
-
options: {
|
|
1119
|
-
name?: string;
|
|
1120
|
-
};
|
|
1121
|
-
}, params?: Record<string, any>): string;
|
|
1122
|
-
compile(path: string, params?: Record<string, string>): string;
|
|
1123
|
-
protected renderView(index: number, path: string, view: ReactNode | undefined, page: PageRoute): ReactNode;
|
|
1124
|
-
protected readonly configure: alepha139.HookDescriptor<"configure">;
|
|
1125
|
-
protected map(pages: Array<PageDescriptor>, target: PageDescriptor): PageRouteEntry;
|
|
1126
|
-
add(entry: PageRouteEntry): void;
|
|
1127
|
-
protected createMatch(page: PageRoute): string;
|
|
1128
|
-
protected _next: number;
|
|
1129
|
-
protected nextId(): string;
|
|
1130
|
-
}
|
|
1131
|
-
declare const isPageRoute: (it: any) => it is PageRoute;
|
|
1132
|
-
interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
|
|
1133
|
-
children?: PageRouteEntry[];
|
|
1134
|
-
}
|
|
1135
|
-
interface PageRoute extends PageRouteEntry {
|
|
1136
|
-
type: "page";
|
|
1137
|
-
name: string;
|
|
1138
|
-
parent?: PageRoute;
|
|
1139
|
-
match: string;
|
|
1140
|
-
}
|
|
1141
|
-
interface Layer {
|
|
1142
|
-
config?: {
|
|
1143
|
-
query?: Record<string, any>;
|
|
1144
|
-
params?: Record<string, any>;
|
|
1145
|
-
context?: Record<string, any>;
|
|
1146
|
-
};
|
|
1147
|
-
name: string;
|
|
1148
|
-
props?: Record<string, any>;
|
|
1149
|
-
error?: Error;
|
|
1150
|
-
part?: string;
|
|
1151
|
-
element: ReactNode;
|
|
1152
|
-
index: number;
|
|
1153
|
-
path: string;
|
|
1154
|
-
route?: PageRoute;
|
|
1155
|
-
cache?: boolean;
|
|
1156
|
-
}
|
|
1157
|
-
type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
|
|
1158
|
-
interface AnchorProps {
|
|
1159
|
-
href: string;
|
|
1160
|
-
onClick: (ev?: any) => any;
|
|
1161
|
-
}
|
|
1162
|
-
interface ReactRouterState {
|
|
1163
|
-
/**
|
|
1164
|
-
* Stack of layers for the current page.
|
|
1165
|
-
*/
|
|
1166
|
-
layers: Array<Layer>;
|
|
1167
|
-
/**
|
|
1168
|
-
* URL of the current page.
|
|
1169
|
-
*/
|
|
1170
|
-
url: URL;
|
|
1171
|
-
/**
|
|
1172
|
-
* Error handler for the current page.
|
|
1173
|
-
*/
|
|
1174
|
-
onError: ErrorHandler;
|
|
1175
|
-
/**
|
|
1176
|
-
* Params extracted from the URL for the current page.
|
|
1177
|
-
*/
|
|
1178
|
-
params: Record<string, any>;
|
|
1179
|
-
/**
|
|
1180
|
-
* Query parameters extracted from the URL for the current page.
|
|
1181
|
-
*/
|
|
1182
|
-
query: Record<string, string>;
|
|
1183
|
-
/**
|
|
1184
|
-
* Optional meta information associated with the current page.
|
|
1185
|
-
*/
|
|
1186
|
-
meta: Record<string, any>;
|
|
1187
|
-
}
|
|
1188
|
-
interface RouterStackItem {
|
|
1189
|
-
route: PageRoute;
|
|
1190
|
-
config?: Record<string, any>;
|
|
1191
|
-
props?: Record<string, any>;
|
|
1192
|
-
error?: Error;
|
|
1193
|
-
cache?: boolean;
|
|
1194
|
-
}
|
|
1195
|
-
interface TransitionOptions {
|
|
1196
|
-
previous?: PreviousLayerData[];
|
|
1197
|
-
}
|
|
1198
|
-
interface CreateLayersResult {
|
|
1199
|
-
redirect?: string;
|
|
1200
|
-
state?: ReactRouterState;
|
|
1201
|
-
}
|
|
1202
|
-
//#endregion
|
|
1203
|
-
//#region src/core/services/ReactPageService.d.ts
|
|
1204
|
-
declare class ReactPageService {
|
|
1205
|
-
fetch(pathname: string, options?: PageDescriptorRenderOptions): Promise<{
|
|
1206
|
-
html: string;
|
|
1207
|
-
response: Response;
|
|
1208
|
-
}>;
|
|
1209
|
-
render(name: string, options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
|
|
1210
|
-
}
|
|
1211
|
-
//#endregion
|
|
1212
|
-
//#region src/core/descriptors/$page.d.ts
|
|
1213
|
-
/**
|
|
1214
|
-
* Main descriptor for defining a React route in the application.
|
|
1215
|
-
*
|
|
1216
|
-
* The $page descriptor is the core building block for creating type-safe, SSR-enabled React routes.
|
|
1217
|
-
* It provides a declarative way to define pages with powerful features:
|
|
1218
|
-
*
|
|
1219
|
-
* **Routing & Navigation**
|
|
1220
|
-
* - URL pattern matching with parameters (e.g., `/users/:id`)
|
|
1221
|
-
* - Nested routing with parent-child relationships
|
|
1222
|
-
* - Type-safe URL parameter and query string validation
|
|
1223
|
-
*
|
|
1224
|
-
* **Data Loading**
|
|
1225
|
-
* - Server-side data fetching with the `resolve` function
|
|
1226
|
-
* - Automatic serialization and hydration for SSR
|
|
1227
|
-
* - Access to request context, URL params, and parent data
|
|
1228
|
-
*
|
|
1229
|
-
* **Component Loading**
|
|
1230
|
-
* - Direct component rendering or lazy loading for code splitting
|
|
1231
|
-
* - Client-only rendering when browser APIs are needed
|
|
1232
|
-
* - Automatic fallback handling during hydration
|
|
1233
|
-
*
|
|
1234
|
-
* **Performance Optimization**
|
|
1235
|
-
* - Static generation for pre-rendered pages at build time
|
|
1236
|
-
* - Server-side caching with configurable TTL and providers
|
|
1237
|
-
* - Code splitting through lazy component loading
|
|
1238
|
-
*
|
|
1239
|
-
* **Error Handling**
|
|
1240
|
-
* - Custom error handlers with support for redirects
|
|
1241
|
-
* - Hierarchical error handling (child → parent)
|
|
1242
|
-
* - HTTP status code handling (404, 401, etc.)
|
|
1243
|
-
*
|
|
1244
|
-
* **Page Animations**
|
|
1245
|
-
* - CSS-based enter/exit animations
|
|
1246
|
-
* - Dynamic animations based on page state
|
|
1247
|
-
* - Custom timing and easing functions
|
|
1248
|
-
*
|
|
1249
|
-
* **Lifecycle Management**
|
|
1250
|
-
* - Server response hooks for headers and status codes
|
|
1251
|
-
* - Page leave handlers for cleanup (browser only)
|
|
1252
|
-
* - Permission-based access control
|
|
1253
|
-
*
|
|
1254
|
-
* @example Simple page with data fetching
|
|
1255
|
-
* ```typescript
|
|
1256
|
-
* const userProfile = $page({
|
|
1257
|
-
* path: "/users/:id",
|
|
1258
|
-
* schema: {
|
|
1259
|
-
* params: t.object({ id: t.integer() }),
|
|
1260
|
-
* query: t.object({ tab: t.optional(t.text()) })
|
|
1261
|
-
* },
|
|
1262
|
-
* resolve: async ({ params }) => {
|
|
1263
|
-
* const user = await userApi.getUser(params.id);
|
|
1264
|
-
* return { user };
|
|
1265
|
-
* },
|
|
1266
|
-
* lazy: () => import("./UserProfile.tsx")
|
|
1267
|
-
* });
|
|
1268
|
-
* ```
|
|
1269
|
-
*
|
|
1270
|
-
* @example Nested routing with error handling
|
|
1271
|
-
* ```typescript
|
|
1272
|
-
* const projectSection = $page({
|
|
1273
|
-
* path: "/projects/:id",
|
|
1274
|
-
* children: () => [projectBoard, projectSettings],
|
|
1275
|
-
* resolve: async ({ params }) => {
|
|
1276
|
-
* const project = await projectApi.get(params.id);
|
|
1277
|
-
* return { project };
|
|
1278
|
-
* },
|
|
1279
|
-
* errorHandler: (error) => {
|
|
1280
|
-
* if (HttpError.is(error, 404)) {
|
|
1281
|
-
* return <ProjectNotFound />;
|
|
1282
|
-
* }
|
|
1283
|
-
* }
|
|
1284
|
-
* });
|
|
1285
|
-
* ```
|
|
1286
|
-
*
|
|
1287
|
-
* @example Static generation with caching
|
|
1288
|
-
* ```typescript
|
|
1289
|
-
* const blogPost = $page({
|
|
1290
|
-
* path: "/blog/:slug",
|
|
1291
|
-
* static: {
|
|
1292
|
-
* entries: posts.map(p => ({ params: { slug: p.slug } }))
|
|
1293
|
-
* },
|
|
1294
|
-
* resolve: async ({ params }) => {
|
|
1295
|
-
* const post = await loadPost(params.slug);
|
|
1296
|
-
* return { post };
|
|
1297
|
-
* }
|
|
1298
|
-
* });
|
|
1299
|
-
* ```
|
|
1300
|
-
*/
|
|
1301
|
-
declare const $page: {
|
|
1302
|
-
<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = TPropsParentDefault>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
|
|
1303
|
-
[KIND]: typeof PageDescriptor;
|
|
1304
|
-
};
|
|
1305
|
-
interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
|
|
1306
|
-
/**
|
|
1307
|
-
* Identifier name for the page. Must be unique.
|
|
1308
|
-
*
|
|
1309
|
-
* @default Descriptor key
|
|
1310
|
-
*/
|
|
1311
|
-
name?: string;
|
|
1312
|
-
/**
|
|
1313
|
-
* Add a pathname to the page.
|
|
1314
|
-
*
|
|
1315
|
-
* Pathname can contain parameters, like `/post/:slug`.
|
|
1316
|
-
*
|
|
1317
|
-
* @default ""
|
|
1318
|
-
*/
|
|
1319
|
-
path?: string;
|
|
1320
|
-
/**
|
|
1321
|
-
* Add an input schema to define:
|
|
1322
|
-
* - `params`: parameters from the pathname.
|
|
1323
|
-
* - `query`: query parameters from the URL.
|
|
1324
|
-
*/
|
|
1325
|
-
schema?: TConfig;
|
|
1326
|
-
/**
|
|
1327
|
-
* Load data before rendering the page.
|
|
1328
|
-
*
|
|
1329
|
-
* This function receives
|
|
1330
|
-
* - the request context and
|
|
1331
|
-
* - the parent props (if page has a parent)
|
|
1332
|
-
*
|
|
1333
|
-
* In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.
|
|
1334
|
-
*
|
|
1335
|
-
* Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.
|
|
1336
|
-
* It's common to throw a `NotFoundError` to display a 404 page.
|
|
1337
|
-
*
|
|
1338
|
-
* RedirectError can be thrown to redirect the user to another page.
|
|
1339
|
-
*/
|
|
1340
|
-
resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;
|
|
1341
|
-
/**
|
|
1342
|
-
* The component to render when the page is loaded.
|
|
1343
|
-
*
|
|
1344
|
-
* If `lazy` is defined, this will be ignored.
|
|
1345
|
-
* Prefer using `lazy` to improve the initial loading time.
|
|
1346
|
-
*/
|
|
1347
|
-
component?: FC<TProps & TPropsParent>;
|
|
1348
|
-
/**
|
|
1349
|
-
* Lazy load the component when the page is loaded.
|
|
1350
|
-
*
|
|
1351
|
-
* It's recommended to use this for components to improve the initial loading time
|
|
1352
|
-
* and enable code-splitting.
|
|
1353
|
-
*/
|
|
1354
|
-
lazy?: () => Promise<{
|
|
1355
|
-
default: FC<TProps & TPropsParent>;
|
|
1356
|
-
}>;
|
|
1357
|
-
/**
|
|
1358
|
-
* Attach child pages to create nested routes.
|
|
1359
|
-
* This will make the page a parent route.
|
|
1360
|
-
*/
|
|
1361
|
-
children?: Array<PageDescriptor> | (() => Array<PageDescriptor>);
|
|
1362
|
-
/**
|
|
1363
|
-
* Define a parent page for nested routing.
|
|
1364
|
-
*/
|
|
1365
|
-
parent?: PageDescriptor<PageConfigSchema, TPropsParent, any>;
|
|
1366
|
-
can?: () => boolean;
|
|
1367
|
-
/**
|
|
1368
|
-
* Catch any error from the `resolve` function or during `rendering`.
|
|
1369
|
-
*
|
|
1370
|
-
* Expected to return one of the following:
|
|
1371
|
-
* - a ReactNode to render an error page
|
|
1372
|
-
* - a Redirection to redirect the user
|
|
1373
|
-
* - undefined to let the error propagate
|
|
1374
|
-
*
|
|
1375
|
-
* If not defined, the error will be thrown and handled by the server or client error handler.
|
|
1376
|
-
* If a leaf $page does not define an error handler, the error can be caught by parent pages.
|
|
1377
|
-
*
|
|
1378
|
-
* @example Catch a 404 from API and render a custom not found component:
|
|
1379
|
-
* ```ts
|
|
1380
|
-
* resolve: async ({ params, query }) => {
|
|
1381
|
-
* api.fetch("/api/resource", { params, query });
|
|
1382
|
-
* },
|
|
1383
|
-
* errorHandler: (error, context) => {
|
|
1384
|
-
* if (HttpError.is(error, 404)) {
|
|
1385
|
-
* return <ResourceNotFound />;
|
|
1386
|
-
* }
|
|
1387
|
-
* }
|
|
1388
|
-
* ```
|
|
1389
|
-
*
|
|
1390
|
-
* @example Catch an 401 error and redirect the user to the login page:
|
|
1391
|
-
* ```ts
|
|
1392
|
-
* resolve: async ({ params, query }) => {
|
|
1393
|
-
* // but the user is not authenticated
|
|
1394
|
-
* api.fetch("/api/resource", { params, query });
|
|
1395
|
-
* },
|
|
1396
|
-
* errorHandler: (error, context) => {
|
|
1397
|
-
* if (HttpError.is(error, 401)) {
|
|
1398
|
-
* // throwing a Redirection is also valid!
|
|
1399
|
-
* return new Redirection("/login");
|
|
1400
|
-
* }
|
|
1401
|
-
* }
|
|
1402
|
-
* ```
|
|
1403
|
-
*/
|
|
1404
|
-
errorHandler?: ErrorHandler;
|
|
1405
|
-
/**
|
|
1406
|
-
* If true, the page will be considered as a static page, immutable and cacheable.
|
|
1407
|
-
* Replace boolean by an object to define static entries. (e.g. list of params/query)
|
|
1408
|
-
*
|
|
1409
|
-
* Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.
|
|
1410
|
-
*
|
|
1411
|
-
* Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.
|
|
1412
|
-
*/
|
|
1413
|
-
static?: boolean | {
|
|
1414
|
-
entries?: Array<Partial<PageRequestConfig<TConfig>>>;
|
|
1415
|
-
};
|
|
1416
|
-
cache?: ServerRouteCache;
|
|
1417
|
-
/**
|
|
1418
|
-
* If true, force the page to be rendered only on the client-side (browser).
|
|
1419
|
-
* It uses the `<ClientOnly/>` component to render the page.
|
|
1420
|
-
*/
|
|
1421
|
-
client?: boolean | ClientOnlyProps;
|
|
1422
|
-
/**
|
|
1423
|
-
* Called before the server response is sent to the client. (server only)
|
|
1424
|
-
*/
|
|
1425
|
-
onServerResponse?: (request: ServerRequest) => unknown;
|
|
1426
|
-
/**
|
|
1427
|
-
* Called when user leaves the page. (browser only)
|
|
1428
|
-
*/
|
|
1429
|
-
onLeave?: () => void;
|
|
1430
|
-
/**
|
|
1431
|
-
* @experimental
|
|
1432
|
-
*
|
|
1433
|
-
* Add a css animation when the page is loaded or unloaded.
|
|
1434
|
-
* It uses CSS animations, so you need to define the keyframes in your CSS.
|
|
1435
|
-
*
|
|
1436
|
-
* @example Simple animation name
|
|
1437
|
-
* ```ts
|
|
1438
|
-
* animation: "fadeIn"
|
|
1439
|
-
* ```
|
|
1440
|
-
*
|
|
1441
|
-
* CSS example:
|
|
1442
|
-
* ```css
|
|
1443
|
-
* @keyframes fadeIn {
|
|
1444
|
-
* from { opacity: 0; }
|
|
1445
|
-
* to { opacity: 1; }
|
|
1446
|
-
* }
|
|
1447
|
-
* ```
|
|
1448
|
-
*
|
|
1449
|
-
* @example Detailed animation
|
|
1450
|
-
* ```ts
|
|
1451
|
-
* animation: {
|
|
1452
|
-
* enter: { name: "fadeIn", duration: 300 },
|
|
1453
|
-
* exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
|
|
1454
|
-
* }
|
|
1455
|
-
* ```
|
|
1456
|
-
*
|
|
1457
|
-
* @example Only exit animation
|
|
1458
|
-
* ```ts
|
|
1459
|
-
* animation: {
|
|
1460
|
-
* exit: "fadeOut"
|
|
1461
|
-
* }
|
|
1462
|
-
* ```
|
|
1463
|
-
*
|
|
1464
|
-
* @example With custom timing function
|
|
1465
|
-
* ```ts
|
|
1466
|
-
* animation: {
|
|
1467
|
-
* enter: { name: "fadeIn", duration: 300, timing: "cubic-bezier(0.4, 0, 0.2, 1)" },
|
|
1468
|
-
* exit: { name: "fadeOut", duration: 200, timing: "ease-in-out" },
|
|
1469
|
-
* }
|
|
1470
|
-
* ```
|
|
1471
|
-
*/
|
|
1472
|
-
animation?: PageAnimation;
|
|
1473
|
-
}
|
|
1474
|
-
type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
|
|
1475
|
-
declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Descriptor<PageDescriptorOptions<TConfig, TProps, TPropsParent>> {
|
|
1476
|
-
protected readonly reactPageService: ReactPageService;
|
|
1477
|
-
protected onInit(): void;
|
|
1478
|
-
get name(): string;
|
|
1479
|
-
/**
|
|
1480
|
-
* For testing or build purposes.
|
|
1481
|
-
*
|
|
1482
|
-
* This will render the page (HTML layout included or not) and return the HTML + context.
|
|
1483
|
-
* Only valid for server-side rendering, it will throw an error if called on the client-side.
|
|
1484
|
-
*/
|
|
1485
|
-
render(options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
|
|
1486
|
-
fetch(options?: PageDescriptorRenderOptions): Promise<{
|
|
1487
|
-
html: string;
|
|
1488
|
-
response: Response;
|
|
1489
|
-
}>;
|
|
1490
|
-
match(url: string): boolean;
|
|
1491
|
-
pathname(config: any): string;
|
|
1492
|
-
}
|
|
1493
|
-
interface PageConfigSchema {
|
|
1494
|
-
query?: TSchema;
|
|
1495
|
-
params?: TSchema;
|
|
1496
|
-
}
|
|
1497
|
-
type TPropsDefault = any;
|
|
1498
|
-
type TPropsParentDefault = {};
|
|
1499
|
-
interface PageDescriptorRenderOptions {
|
|
1500
|
-
params?: Record<string, string>;
|
|
1501
|
-
query?: Record<string, string>;
|
|
1502
|
-
/**
|
|
1503
|
-
* If true, the HTML layout will be included in the response.
|
|
1504
|
-
* If false, only the page content will be returned.
|
|
1505
|
-
*
|
|
1506
|
-
* @default true
|
|
1507
|
-
*/
|
|
1508
|
-
html?: boolean;
|
|
1509
|
-
hydration?: boolean;
|
|
1510
|
-
}
|
|
1511
|
-
interface PageDescriptorRenderResult {
|
|
1512
|
-
html: string;
|
|
1513
|
-
state: ReactRouterState;
|
|
1514
|
-
redirect?: string;
|
|
1515
|
-
}
|
|
1516
|
-
interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
|
|
1517
|
-
params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
|
|
1518
|
-
query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
|
|
1519
|
-
}
|
|
1520
|
-
type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
|
|
1521
|
-
type PageAnimation = PageAnimationObject | ((state: ReactRouterState) => PageAnimationObject | undefined);
|
|
1522
|
-
type PageAnimationObject = CssAnimationName | {
|
|
1523
|
-
enter?: CssAnimation | CssAnimationName;
|
|
1524
|
-
exit?: CssAnimation | CssAnimationName;
|
|
1525
|
-
};
|
|
1526
|
-
type CssAnimationName = string;
|
|
1527
|
-
type CssAnimation = {
|
|
1528
|
-
name: string;
|
|
1529
|
-
duration?: number;
|
|
1530
|
-
timing?: string;
|
|
1531
|
-
};
|
|
1532
|
-
//#endregion
|
|
1533
|
-
//#region ../alepha/src/security/schemas/userAccountInfoSchema.d.ts
|
|
1534
|
-
declare const userAccountInfoSchema: alepha139.TObject<{
|
|
1535
|
-
id: alepha139.TString;
|
|
1536
|
-
name: alepha139.TOptional<alepha139.TString>;
|
|
1537
|
-
email: alepha139.TOptional<alepha139.TString>;
|
|
1538
|
-
username: alepha139.TOptional<alepha139.TString>;
|
|
1539
|
-
picture: alepha139.TOptional<alepha139.TString>;
|
|
1540
|
-
sessionId: alepha139.TOptional<alepha139.TString>;
|
|
1541
|
-
organizations: alepha139.TOptional<alepha139.TArray<alepha139.TString>>;
|
|
1542
|
-
roles: alepha139.TOptional<alepha139.TArray<alepha139.TString>>;
|
|
1543
|
-
}>;
|
|
1544
|
-
type UserAccount = Static<typeof userAccountInfoSchema>;
|
|
1545
|
-
//#endregion
|
|
1546
|
-
//#region ../alepha/src/security/interfaces/UserAccountToken.d.ts
|
|
1547
|
-
/**
|
|
1548
|
-
* Add contextual metadata to a user account info.
|
|
1549
|
-
* E.g. UserAccountToken is a UserAccountInfo during a request.
|
|
1550
|
-
*/
|
|
1551
|
-
interface UserAccountToken extends UserAccount {
|
|
1552
|
-
/**
|
|
1553
|
-
* Access token for the user.
|
|
1554
|
-
*/
|
|
1555
|
-
token?: string;
|
|
1556
|
-
/**
|
|
1557
|
-
* Realm name of the user.
|
|
1558
|
-
*/
|
|
1559
|
-
realm?: string;
|
|
1560
|
-
/**
|
|
1561
|
-
* Is user dedicated to his own resources for this scope ?
|
|
1562
|
-
* Mostly, Admin is false and Customer is true.
|
|
1563
|
-
*/
|
|
1564
|
-
ownership?: string | boolean;
|
|
1565
|
-
}
|
|
1566
|
-
//#endregion
|
|
1567
|
-
//#region ../alepha/src/security/providers/SecurityProvider.d.ts
|
|
1568
|
-
declare const envSchema$2: alepha139.TObject<{
|
|
1569
|
-
APP_SECRET: alepha139.TString;
|
|
1570
|
-
}>;
|
|
1571
|
-
declare module "alepha" {
|
|
1572
|
-
interface Env extends Partial<Static<typeof envSchema$2>> {}
|
|
1573
|
-
}
|
|
1574
|
-
//#endregion
|
|
1575
|
-
//#region ../alepha/src/security/index.d.ts
|
|
1576
|
-
declare module "alepha" {
|
|
1577
|
-
interface Hooks {
|
|
1578
|
-
"security:user:created": {
|
|
1579
|
-
realm: string;
|
|
1580
|
-
user: UserAccount;
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* Provides comprehensive authentication and authorization capabilities with JWT tokens, role-based access control, and user management.
|
|
1586
|
-
*
|
|
1587
|
-
* The security module enables building secure applications using descriptors like `$realm`, `$role`, and `$permission`
|
|
1588
|
-
* on class properties. It offers JWT-based authentication, fine-grained permissions, service accounts, and seamless
|
|
1589
|
-
* integration with various authentication providers and user management systems.
|
|
1590
|
-
*
|
|
1591
|
-
* @see {@link $realm}
|
|
1592
|
-
* @see {@link $role}
|
|
1593
|
-
* @see {@link $permission}
|
|
1594
|
-
* @module alepha.security
|
|
1595
|
-
*/
|
|
1596
|
-
//#endregion
|
|
1597
|
-
//#region ../alepha/src/server-security/providers/ServerBasicAuthProvider.d.ts
|
|
1598
|
-
interface BasicAuthOptions {
|
|
1599
|
-
username: string;
|
|
1600
|
-
password: string;
|
|
1601
|
-
}
|
|
1602
|
-
//#endregion
|
|
1603
|
-
//#region ../alepha/src/server-security/providers/ServerSecurityProvider.d.ts
|
|
1604
|
-
type ServerRouteSecure = {
|
|
1605
|
-
realm?: string;
|
|
1606
|
-
basic?: BasicAuthOptions;
|
|
1607
|
-
};
|
|
1608
|
-
//#endregion
|
|
1609
|
-
//#region ../alepha/src/server-security/index.d.ts
|
|
1610
|
-
declare module "alepha" {
|
|
1611
|
-
interface State {
|
|
1612
|
-
/**
|
|
1613
|
-
* Real (or fake) user account, used for internal actions.
|
|
1614
|
-
*
|
|
1615
|
-
* If you define this, you assume that all actions are executed by this user by default.
|
|
1616
|
-
* > To force a different user, you need to pass it explicitly in the options.
|
|
1617
|
-
*/
|
|
1618
|
-
"alepha.server.security.system.user"?: UserAccountToken;
|
|
1619
|
-
/**
|
|
1620
|
-
* The authenticated user account attached to the server request state.
|
|
1621
|
-
*
|
|
1622
|
-
* @internal
|
|
1623
|
-
*/
|
|
1624
|
-
"alepha.server.request.user"?: UserAccount;
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
declare module "alepha/server" {
|
|
1628
|
-
interface ServerRequest<TConfig> {
|
|
1629
|
-
user?: UserAccountToken;
|
|
1630
|
-
}
|
|
1631
|
-
interface ServerActionRequest<TConfig> {
|
|
1632
|
-
user: UserAccountToken;
|
|
1633
|
-
}
|
|
1634
|
-
interface ServerRoute {
|
|
1635
|
-
/**
|
|
1636
|
-
* If true, the route will be protected by the security provider.
|
|
1637
|
-
* All actions are secure by default, but you can disable it for specific actions.
|
|
1638
|
-
*/
|
|
1639
|
-
secure?: boolean | ServerRouteSecure;
|
|
1640
|
-
}
|
|
1641
|
-
interface ClientRequestOptions extends FetchOptions {
|
|
1642
|
-
/**
|
|
1643
|
-
* Forward user from the previous request.
|
|
1644
|
-
* If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
|
|
1645
|
-
* If "context", use the user from the current context (e.g. request).
|
|
1646
|
-
*
|
|
1647
|
-
* @default "system" if provided, else "context" if available.
|
|
1648
|
-
*/
|
|
1649
|
-
user?: UserAccountToken | "system" | "context";
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Plugin for Alepha Server that provides security features. Based on the Alepha Security module.
|
|
1654
|
-
*
|
|
1655
|
-
* By default, all $action will be guarded by a permission check.
|
|
1656
|
-
*
|
|
1657
|
-
* @see {@link ServerSecurityProvider}
|
|
1658
|
-
* @module alepha.server.security
|
|
1659
|
-
*/
|
|
1660
|
-
//#endregion
|
|
1661
|
-
//#region ../alepha/src/server-links/schemas/apiLinksResponseSchema.d.ts
|
|
1662
|
-
declare const apiLinkSchema: alepha139.TObject<{
|
|
1663
|
-
name: alepha139.TString;
|
|
1664
|
-
group: alepha139.TOptional<alepha139.TString>;
|
|
1665
|
-
path: alepha139.TString;
|
|
1666
|
-
method: alepha139.TOptional<alepha139.TString>;
|
|
1667
|
-
requestBodyType: alepha139.TOptional<alepha139.TString>;
|
|
1668
|
-
service: alepha139.TOptional<alepha139.TString>;
|
|
1669
|
-
}>;
|
|
1670
|
-
declare const apiLinksResponseSchema: alepha139.TObject<{
|
|
1671
|
-
prefix: alepha139.TOptional<alepha139.TString>;
|
|
1672
|
-
links: alepha139.TArray<alepha139.TObject<{
|
|
1673
|
-
name: alepha139.TString;
|
|
1674
|
-
group: alepha139.TOptional<alepha139.TString>;
|
|
1675
|
-
path: alepha139.TString;
|
|
1676
|
-
method: alepha139.TOptional<alepha139.TString>;
|
|
1677
|
-
requestBodyType: alepha139.TOptional<alepha139.TString>;
|
|
1678
|
-
service: alepha139.TOptional<alepha139.TString>;
|
|
1679
|
-
}>>;
|
|
1680
|
-
}>;
|
|
1681
|
-
type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
|
|
1682
|
-
type ApiLink = Static<typeof apiLinkSchema>;
|
|
1683
|
-
//#endregion
|
|
1684
|
-
//#region ../alepha/src/server-links/providers/LinkProvider.d.ts
|
|
1685
|
-
/**
|
|
1686
|
-
* Browser, SSR friendly, service to handle links.
|
|
1687
|
-
*/
|
|
1688
|
-
declare class LinkProvider {
|
|
1689
|
-
static path: {
|
|
1690
|
-
apiLinks: string;
|
|
1691
|
-
apiSchema: string;
|
|
1692
|
-
};
|
|
1693
|
-
protected readonly log: Logger;
|
|
1694
|
-
protected readonly alepha: Alepha;
|
|
1695
|
-
protected readonly httpClient: HttpClient;
|
|
1696
|
-
protected serverLinks: Array<HttpClientLink>;
|
|
1697
|
-
/**
|
|
1698
|
-
* Get applicative links registered on the server.
|
|
1699
|
-
* This does not include lazy-loaded remote links.
|
|
1700
|
-
*/
|
|
1701
|
-
getServerLinks(): HttpClientLink[];
|
|
1702
|
-
/**
|
|
1703
|
-
* Register a new link for the application.
|
|
1704
|
-
*/
|
|
1705
|
-
registerLink(link: HttpClientLink): void;
|
|
1706
|
-
get links(): HttpClientLink[];
|
|
1707
|
-
/**
|
|
1708
|
-
* Force browser to refresh links from the server.
|
|
1709
|
-
*/
|
|
1710
|
-
fetchLinks(): Promise<HttpClientLink[]>;
|
|
1711
|
-
/**
|
|
1712
|
-
* Create a virtual client that can be used to call actions.
|
|
1713
|
-
*
|
|
1714
|
-
* Use js Proxy under the hood.
|
|
1715
|
-
*/
|
|
1716
|
-
client<T$1 extends object>(scope?: ClientScope): HttpVirtualClient<T$1>;
|
|
1717
|
-
/**
|
|
1718
|
-
* Check if a link with the given name exists.
|
|
1719
|
-
* @param name
|
|
1720
|
-
*/
|
|
1721
|
-
can(name: string): boolean;
|
|
1722
|
-
/**
|
|
1723
|
-
* Resolve a link by its name and call it.
|
|
1724
|
-
* - If link is local, it will call the local handler.
|
|
1725
|
-
* - If link is remote, it will make a fetch request to the remote server.
|
|
1726
|
-
*/
|
|
1727
|
-
follow(name: string, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions & ClientScope): Promise<any>;
|
|
1728
|
-
protected createVirtualAction<T$1 extends RequestConfigSchema>(name: string, scope?: ClientScope): VirtualAction<T$1>;
|
|
1729
|
-
protected followRemote(link: HttpClientLink, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions): Promise<FetchResponse>;
|
|
1730
|
-
protected getLinkByName(name: string, options?: ClientScope): Promise<HttpClientLink>;
|
|
1731
|
-
}
|
|
1732
|
-
interface HttpClientLink extends ApiLink {
|
|
1733
|
-
secured?: boolean | ServerRouteSecure;
|
|
1734
|
-
prefix?: string;
|
|
1735
|
-
host?: string;
|
|
1736
|
-
service?: string;
|
|
1737
|
-
schema?: RequestConfigSchema;
|
|
1738
|
-
handler?: (request: ServerRequest, options: ClientRequestOptions) => Async<ServerResponseBody>;
|
|
1739
|
-
}
|
|
1740
|
-
interface ClientScope {
|
|
1741
|
-
group?: string;
|
|
1742
|
-
service?: string;
|
|
1743
|
-
hostname?: string;
|
|
1744
|
-
}
|
|
1745
|
-
type HttpVirtualClient<T$1> = { [K in keyof T$1 as T$1[K] extends ActionDescriptor<RequestConfigSchema> ? K : never]: T$1[K] extends ActionDescriptor<infer Schema> ? VirtualAction<Schema> : never };
|
|
1746
|
-
interface VirtualAction<T$1 extends RequestConfigSchema> extends Pick<ActionDescriptor<T$1>, "name" | "run" | "fetch"> {
|
|
1747
|
-
(config?: ClientRequestEntry<T$1>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<T$1>>;
|
|
1748
|
-
can: () => boolean;
|
|
1749
|
-
}
|
|
1750
|
-
//#endregion
|
|
1751
|
-
//#region ../alepha/src/server-links/index.d.ts
|
|
1752
|
-
declare module "alepha" {
|
|
1753
|
-
interface State {
|
|
1754
|
-
/**
|
|
1755
|
-
* API links attached to the server request state.
|
|
1756
|
-
*
|
|
1757
|
-
* @see {@link ApiLinksResponse}
|
|
1758
|
-
* @internal
|
|
1759
|
-
*/
|
|
1760
|
-
"alepha.server.request.apiLinks"?: ApiLinksResponse;
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
/**
|
|
1764
|
-
* Provides server-side link management and remote capabilities for client-server interactions.
|
|
1765
|
-
*
|
|
1766
|
-
* The server-links module enables declarative link definitions using `$remote` and `$client` descriptors,
|
|
1767
|
-
* facilitating seamless API endpoint management and client-server communication. It integrates with server
|
|
1768
|
-
* security features to ensure safe and controlled access to resources.
|
|
1769
|
-
*
|
|
1770
|
-
* @see {@link $remote}
|
|
1771
|
-
* @see {@link $client}
|
|
1772
|
-
* @module alepha.server.links
|
|
1773
|
-
*/
|
|
1774
|
-
//#endregion
|
|
1775
|
-
//#region src/core/providers/ReactBrowserRouterProvider.d.ts
|
|
1776
|
-
interface BrowserRoute extends Route {
|
|
1777
|
-
page: PageRoute;
|
|
1778
|
-
}
|
|
1779
|
-
declare class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
1780
|
-
protected readonly log: Logger;
|
|
1781
|
-
protected readonly alepha: Alepha;
|
|
1782
|
-
protected readonly pageApi: ReactPageProvider;
|
|
1783
|
-
add(entry: PageRouteEntry): void;
|
|
1784
|
-
protected readonly configure: alepha139.HookDescriptor<"configure">;
|
|
1785
|
-
transition(url: URL, previous?: PreviousLayerData[], meta?: {}): Promise<string | void>;
|
|
1786
|
-
root(state: ReactRouterState): ReactNode;
|
|
1787
|
-
}
|
|
1788
|
-
//#endregion
|
|
1789
|
-
//#region src/core/providers/ReactBrowserProvider.d.ts
|
|
1790
|
-
declare const envSchema$1: alepha139.TObject<{
|
|
1791
|
-
REACT_ROOT_ID: alepha139.TString;
|
|
1792
|
-
}>;
|
|
1793
|
-
declare module "alepha" {
|
|
1794
|
-
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
1795
|
-
}
|
|
1796
|
-
/**
|
|
1797
|
-
* React browser renderer configuration atom
|
|
1798
|
-
*/
|
|
1799
|
-
declare const reactBrowserOptions: alepha139.Atom<alepha139.TObject<{
|
|
1800
|
-
scrollRestoration: alepha139.TUnsafe<"top" | "manual">;
|
|
1801
|
-
}>, "alepha.react.browser.options">;
|
|
1802
|
-
type ReactBrowserRendererOptions = Static<typeof reactBrowserOptions.schema>;
|
|
1803
|
-
declare module "alepha" {
|
|
1804
|
-
interface State {
|
|
1805
|
-
[reactBrowserOptions.key]: ReactBrowserRendererOptions;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
declare class ReactBrowserProvider {
|
|
1809
|
-
protected readonly env: {
|
|
1810
|
-
REACT_ROOT_ID: string;
|
|
1811
|
-
};
|
|
1812
|
-
protected readonly log: Logger;
|
|
1813
|
-
protected readonly client: LinkProvider;
|
|
1814
|
-
protected readonly alepha: Alepha;
|
|
1815
|
-
protected readonly router: ReactBrowserRouterProvider;
|
|
1816
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
1817
|
-
protected readonly options: Readonly<{
|
|
1818
|
-
scrollRestoration: "top" | "manual";
|
|
1819
|
-
}>;
|
|
1820
|
-
protected getRootElement(): HTMLElement;
|
|
1821
|
-
transitioning?: {
|
|
1822
|
-
to: string;
|
|
1823
|
-
from?: string;
|
|
1824
|
-
};
|
|
1825
|
-
get state(): ReactRouterState;
|
|
1826
|
-
/**
|
|
1827
|
-
* Accessor for Document DOM API.
|
|
1828
|
-
*/
|
|
1829
|
-
get document(): Document;
|
|
1830
|
-
/**
|
|
1831
|
-
* Accessor for History DOM API.
|
|
1832
|
-
*/
|
|
1833
|
-
get history(): History;
|
|
1834
|
-
/**
|
|
1835
|
-
* Accessor for Location DOM API.
|
|
1836
|
-
*/
|
|
1837
|
-
get location(): Location;
|
|
1838
|
-
get base(): string;
|
|
1839
|
-
get url(): string;
|
|
1840
|
-
pushState(path: string, replace?: boolean): void;
|
|
1841
|
-
invalidate(props?: Record<string, any>): Promise<void>;
|
|
1842
|
-
go(url: string, options?: RouterGoOptions): Promise<void>;
|
|
1843
|
-
protected render(options?: RouterRenderOptions): Promise<void>;
|
|
1844
|
-
/**
|
|
1845
|
-
* Get embedded layers from the server.
|
|
1846
|
-
*/
|
|
1847
|
-
protected getHydrationState(): ReactHydrationState | undefined;
|
|
1848
|
-
protected readonly onTransitionEnd: alepha139.HookDescriptor<"react:transition:end">;
|
|
1849
|
-
readonly ready: alepha139.HookDescriptor<"ready">;
|
|
1850
|
-
}
|
|
1851
|
-
interface RouterGoOptions {
|
|
1852
|
-
replace?: boolean;
|
|
1853
|
-
match?: TransitionOptions;
|
|
1854
|
-
params?: Record<string, string>;
|
|
1855
|
-
query?: Record<string, string>;
|
|
1856
|
-
meta?: Record<string, any>;
|
|
1857
|
-
/**
|
|
1858
|
-
* Recreate the whole page, ignoring the current state.
|
|
1859
|
-
*/
|
|
1860
|
-
force?: boolean;
|
|
1861
|
-
}
|
|
1862
|
-
type ReactHydrationState = {
|
|
1863
|
-
layers?: Array<PreviousLayerData>;
|
|
1864
|
-
} & {
|
|
1865
|
-
[key: string]: any;
|
|
1866
|
-
};
|
|
1867
|
-
interface RouterRenderOptions {
|
|
1868
|
-
url?: string;
|
|
1869
|
-
previous?: PreviousLayerData[];
|
|
1870
|
-
meta?: Record<string, any>;
|
|
1871
|
-
}
|
|
1872
|
-
//#endregion
|
|
1873
|
-
//#region src/core/contexts/AlephaContext.d.ts
|
|
1874
|
-
declare const AlephaContext: react1.Context<Alepha | undefined>;
|
|
1875
|
-
//#endregion
|
|
1876
|
-
//#region src/core/hooks/useAction.d.ts
|
|
1877
|
-
/**
|
|
1878
|
-
* Hook for handling async actions with automatic error handling and event emission.
|
|
1879
|
-
*
|
|
1880
|
-
* By default, prevents concurrent executions - if an action is running and you call it again,
|
|
1881
|
-
* the second call will be ignored. Use `debounce` option to delay execution instead.
|
|
1882
|
-
*
|
|
1883
|
-
* Emits lifecycle events:
|
|
1884
|
-
* - `react:action:begin` - When action starts
|
|
1885
|
-
* - `react:action:success` - When action completes successfully
|
|
1886
|
-
* - `react:action:error` - When action throws an error
|
|
1887
|
-
* - `react:action:end` - Always emitted at the end
|
|
1888
|
-
*
|
|
1889
|
-
* @example Basic usage
|
|
1890
|
-
* ```tsx
|
|
1891
|
-
* const action = useAction({
|
|
1892
|
-
* handler: async (data) => {
|
|
1893
|
-
* await api.save(data);
|
|
1894
|
-
* }
|
|
1895
|
-
* }, []);
|
|
1896
|
-
*
|
|
1897
|
-
* <button onClick={() => action.run(data)} disabled={action.loading}>
|
|
1898
|
-
* Save
|
|
1899
|
-
* </button>
|
|
1900
|
-
* ```
|
|
1901
|
-
*
|
|
1902
|
-
* @example With debounce (search input)
|
|
1903
|
-
* ```tsx
|
|
1904
|
-
* const search = useAction({
|
|
1905
|
-
* handler: async (query: string) => {
|
|
1906
|
-
* await api.search(query);
|
|
1907
|
-
* },
|
|
1908
|
-
* debounce: 300 // Wait 300ms after last call
|
|
1909
|
-
* }, []);
|
|
1910
|
-
*
|
|
1911
|
-
* <input onChange={(e) => search.run(e.target.value)} />
|
|
1912
|
-
* ```
|
|
1913
|
-
*
|
|
1914
|
-
* @example Run on component mount
|
|
1915
|
-
* ```tsx
|
|
1916
|
-
* const fetchData = useAction({
|
|
1917
|
-
* handler: async () => {
|
|
1918
|
-
* const data = await api.getData();
|
|
1919
|
-
* return data;
|
|
1920
|
-
* },
|
|
1921
|
-
* runOnInit: true // Runs once when component mounts
|
|
1922
|
-
* }, []);
|
|
1923
|
-
* ```
|
|
1924
|
-
*
|
|
1925
|
-
* @example Run periodically (polling)
|
|
1926
|
-
* ```tsx
|
|
1927
|
-
* const pollStatus = useAction({
|
|
1928
|
-
* handler: async () => {
|
|
1929
|
-
* const status = await api.getStatus();
|
|
1930
|
-
* return status;
|
|
1931
|
-
* },
|
|
1932
|
-
* runEvery: 5000 // Run every 5 seconds
|
|
1933
|
-
* }, []);
|
|
1934
|
-
*
|
|
1935
|
-
* // Or with duration tuple
|
|
1936
|
-
* const pollStatus = useAction({
|
|
1937
|
-
* handler: async () => {
|
|
1938
|
-
* const status = await api.getStatus();
|
|
1939
|
-
* return status;
|
|
1940
|
-
* },
|
|
1941
|
-
* runEvery: [30, 'seconds'] // Run every 30 seconds
|
|
1942
|
-
* }, []);
|
|
1943
|
-
* ```
|
|
1944
|
-
*
|
|
1945
|
-
* @example With AbortController
|
|
1946
|
-
* ```tsx
|
|
1947
|
-
* const fetch = useAction({
|
|
1948
|
-
* handler: async (url, { signal }) => {
|
|
1949
|
-
* const response = await fetch(url, { signal });
|
|
1950
|
-
* return response.json();
|
|
1951
|
-
* }
|
|
1952
|
-
* }, []);
|
|
1953
|
-
* // Automatically cancelled on unmount or when new request starts
|
|
1954
|
-
* ```
|
|
1955
|
-
*
|
|
1956
|
-
* @example With error handling
|
|
1957
|
-
* ```tsx
|
|
1958
|
-
* const deleteAction = useAction({
|
|
1959
|
-
* handler: async (id: string) => {
|
|
1960
|
-
* await api.delete(id);
|
|
1961
|
-
* },
|
|
1962
|
-
* onError: (error) => {
|
|
1963
|
-
* if (error.code === 'NOT_FOUND') {
|
|
1964
|
-
* // Custom error handling
|
|
1965
|
-
* }
|
|
1966
|
-
* }
|
|
1967
|
-
* }, []);
|
|
1968
|
-
*
|
|
1969
|
-
* {deleteAction.error && <div>Error: {deleteAction.error.message}</div>}
|
|
1970
|
-
* ```
|
|
1971
|
-
*
|
|
1972
|
-
* @example Global error handling
|
|
1973
|
-
* ```tsx
|
|
1974
|
-
* // In your root app setup
|
|
1975
|
-
* alepha.events.on("react:action:error", ({ error }) => {
|
|
1976
|
-
* toast.danger(error.message);
|
|
1977
|
-
* Sentry.captureException(error);
|
|
1978
|
-
* });
|
|
1979
|
-
* ```
|
|
1980
|
-
*/
|
|
1981
|
-
declare function useAction<Args extends any[], Result = void>(options: UseActionOptions<Args, Result>, deps: DependencyList): UseActionReturn<Args, Result>;
|
|
1982
|
-
/**
|
|
1983
|
-
* Context object passed as the last argument to action handlers.
|
|
1984
|
-
* Contains an AbortSignal that can be used to cancel the request.
|
|
1985
|
-
*/
|
|
1986
|
-
interface ActionContext {
|
|
1987
|
-
/**
|
|
1988
|
-
* AbortSignal that can be passed to fetch or other async operations.
|
|
1989
|
-
* The signal will be aborted when:
|
|
1990
|
-
* - The component unmounts
|
|
1991
|
-
* - A new action is triggered (cancels previous)
|
|
1992
|
-
* - The cancel() method is called
|
|
1993
|
-
*
|
|
1994
|
-
* @example
|
|
1995
|
-
* ```tsx
|
|
1996
|
-
* const action = useAction({
|
|
1997
|
-
* handler: async (url, { signal }) => {
|
|
1998
|
-
* const response = await fetch(url, { signal });
|
|
1999
|
-
* return response.json();
|
|
2000
|
-
* }
|
|
2001
|
-
* }, []);
|
|
2002
|
-
* ```
|
|
2003
|
-
*/
|
|
2004
|
-
signal: AbortSignal;
|
|
2005
|
-
}
|
|
2006
|
-
interface UseActionOptions<Args extends any[] = any[], Result = any> {
|
|
2007
|
-
/**
|
|
2008
|
-
* The async action handler function.
|
|
2009
|
-
* Receives the action arguments plus an ActionContext as the last parameter.
|
|
2010
|
-
*/
|
|
2011
|
-
handler: (...args: [...Args, ActionContext]) => Promise<Result>;
|
|
2012
|
-
/**
|
|
2013
|
-
* Custom error handler. If provided, prevents default error re-throw.
|
|
2014
|
-
*/
|
|
2015
|
-
onError?: (error: Error) => void | Promise<void>;
|
|
2016
|
-
/**
|
|
2017
|
-
* Custom success handler.
|
|
2018
|
-
*/
|
|
2019
|
-
onSuccess?: (result: Result) => void | Promise<void>;
|
|
2020
|
-
/**
|
|
2021
|
-
* Optional identifier for this action (useful for debugging/analytics)
|
|
2022
|
-
*/
|
|
2023
|
-
id?: string;
|
|
2024
|
-
/**
|
|
2025
|
-
* Debounce delay in milliseconds. If specified, the action will only execute
|
|
2026
|
-
* after the specified delay has passed since the last call. Useful for search inputs
|
|
2027
|
-
* or other high-frequency events.
|
|
2028
|
-
*
|
|
2029
|
-
* @example
|
|
2030
|
-
* ```tsx
|
|
2031
|
-
* // Execute search 300ms after user stops typing
|
|
2032
|
-
* const search = useAction({ handler: search, debounce: 300 }, [])
|
|
2033
|
-
* ```
|
|
2034
|
-
*/
|
|
2035
|
-
debounce?: number;
|
|
2036
|
-
/**
|
|
2037
|
-
* If true, the action will be executed once when the component mounts.
|
|
2038
|
-
*
|
|
2039
|
-
* @example
|
|
2040
|
-
* ```tsx
|
|
2041
|
-
* const fetchData = useAction({
|
|
2042
|
-
* handler: async () => await api.getData(),
|
|
2043
|
-
* runOnInit: true
|
|
2044
|
-
* }, []);
|
|
2045
|
-
* ```
|
|
2046
|
-
*/
|
|
2047
|
-
runOnInit?: boolean;
|
|
2048
|
-
/**
|
|
2049
|
-
* If specified, the action will be executed periodically at the given interval.
|
|
2050
|
-
* The interval is specified as a DurationLike value (number in ms, Duration object, or [number, unit] tuple).
|
|
2051
|
-
*
|
|
2052
|
-
* @example
|
|
2053
|
-
* ```tsx
|
|
2054
|
-
* // Run every 5 seconds
|
|
2055
|
-
* const poll = useAction({
|
|
2056
|
-
* handler: async () => await api.poll(),
|
|
2057
|
-
* runEvery: 5000
|
|
2058
|
-
* }, []);
|
|
2059
|
-
* ```
|
|
2060
|
-
*
|
|
2061
|
-
* @example
|
|
2062
|
-
* ```tsx
|
|
2063
|
-
* // Run every 1 minute
|
|
2064
|
-
* const poll = useAction({
|
|
2065
|
-
* handler: async () => await api.poll(),
|
|
2066
|
-
* runEvery: [1, 'minute']
|
|
2067
|
-
* }, []);
|
|
2068
|
-
* ```
|
|
2069
|
-
*/
|
|
2070
|
-
runEvery?: DurationLike;
|
|
2071
|
-
}
|
|
2072
|
-
interface UseActionReturn<Args extends any[], Result> {
|
|
2073
|
-
/**
|
|
2074
|
-
* Execute the action with the provided arguments.
|
|
2075
|
-
*
|
|
2076
|
-
* @example
|
|
2077
|
-
* ```tsx
|
|
2078
|
-
* const action = useAction({ handler: async (data) => { ... } }, []);
|
|
2079
|
-
* action.run(data);
|
|
2080
|
-
* ```
|
|
2081
|
-
*/
|
|
2082
|
-
run: (...args: Args) => Promise<Result | undefined>;
|
|
2083
|
-
/**
|
|
2084
|
-
* Loading state - true when action is executing.
|
|
2085
|
-
*/
|
|
2086
|
-
loading: boolean;
|
|
2087
|
-
/**
|
|
2088
|
-
* Error state - contains error if action failed, undefined otherwise.
|
|
2089
|
-
*/
|
|
2090
|
-
error?: Error;
|
|
2091
|
-
/**
|
|
2092
|
-
* Cancel any pending debounced action or abort the current in-flight request.
|
|
2093
|
-
*
|
|
2094
|
-
* @example
|
|
2095
|
-
* ```tsx
|
|
2096
|
-
* const action = useAction({ ... }, []);
|
|
2097
|
-
*
|
|
2098
|
-
* <button onClick={action.cancel} disabled={!action.loading}>
|
|
2099
|
-
* Cancel
|
|
2100
|
-
* </button>
|
|
2101
|
-
* ```
|
|
2102
|
-
*/
|
|
2103
|
-
cancel: () => void;
|
|
2104
|
-
}
|
|
2105
|
-
//#endregion
|
|
2106
|
-
//#region src/core/hooks/useAlepha.d.ts
|
|
2107
|
-
/**
|
|
2108
|
-
* Main Alepha hook.
|
|
2109
|
-
*
|
|
2110
|
-
* It provides access to the Alepha instance within a React component.
|
|
2111
|
-
*
|
|
2112
|
-
* With Alepha, you can access the core functionalities of the framework:
|
|
2113
|
-
*
|
|
2114
|
-
* - alepha.state() for state management
|
|
2115
|
-
* - alepha.inject() for dependency injection
|
|
2116
|
-
* - alepha.events.emit() for event handling
|
|
2117
|
-
* etc...
|
|
2118
|
-
*/
|
|
2119
|
-
declare const useAlepha: () => Alepha;
|
|
2120
|
-
//#endregion
|
|
2121
|
-
//#region src/core/hooks/useClient.d.ts
|
|
2122
|
-
/**
|
|
2123
|
-
* Hook to get a virtual client for the specified scope.
|
|
2124
|
-
*
|
|
2125
|
-
* It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
|
|
2126
|
-
*/
|
|
2127
|
-
declare const useClient: <T$1 extends object>(scope?: ClientScope) => HttpVirtualClient<T$1>;
|
|
2128
|
-
//#endregion
|
|
2129
|
-
//#region src/core/hooks/useEvents.d.ts
|
|
2130
|
-
/**
|
|
2131
|
-
* Allow subscribing to multiple Alepha events. See {@link Hooks} for available events.
|
|
2132
|
-
*
|
|
2133
|
-
* useEvents is fully typed to ensure correct event callback signatures.
|
|
2134
|
-
*
|
|
2135
|
-
* @example
|
|
2136
|
-
* ```tsx
|
|
2137
|
-
* useEvents(
|
|
2138
|
-
* {
|
|
2139
|
-
* "react:transition:begin": (ev) => {
|
|
2140
|
-
* console.log("Transition began to:", ev.to);
|
|
2141
|
-
* },
|
|
2142
|
-
* "react:transition:error": {
|
|
2143
|
-
* priority: "first",
|
|
2144
|
-
* callback: (ev) => {
|
|
2145
|
-
* console.error("Transition error:", ev.error);
|
|
2146
|
-
* },
|
|
2147
|
-
* },
|
|
2148
|
-
* },
|
|
2149
|
-
* [],
|
|
2150
|
-
* );
|
|
2151
|
-
* ```
|
|
2152
|
-
*/
|
|
2153
|
-
declare const useEvents: (opts: UseEvents, deps: DependencyList) => void;
|
|
2154
|
-
type UseEvents = { [T in keyof Hooks]?: Hook<T> | ((payload: Hooks[T]) => Async<void>) };
|
|
2155
|
-
//#endregion
|
|
2156
|
-
//#region src/core/hooks/useInject.d.ts
|
|
2157
|
-
/**
|
|
2158
|
-
* Hook to inject a service instance.
|
|
2159
|
-
* It's a wrapper of `useAlepha().inject(service)` with a memoization.
|
|
2160
|
-
*/
|
|
2161
|
-
declare const useInject: <T$1 extends object>(service: Service<T$1>) => T$1;
|
|
2162
|
-
//#endregion
|
|
2163
|
-
//#region src/core/hooks/useSchema.d.ts
|
|
2164
|
-
declare const useSchema: <TConfig extends RequestConfigSchema>(action: VirtualAction<TConfig>) => UseSchemaReturn<TConfig>;
|
|
2165
|
-
type UseSchemaReturn<TConfig extends RequestConfigSchema> = TConfig & {
|
|
2166
|
-
loading: boolean;
|
|
2167
|
-
};
|
|
2168
|
-
/**
|
|
2169
|
-
* Get an action schema during server-side rendering (SSR) or client-side rendering (CSR).
|
|
2170
|
-
*/
|
|
2171
|
-
declare const ssrSchemaLoading: (alepha: Alepha, name: string) => RequestConfigSchema | {
|
|
2172
|
-
loading: boolean;
|
|
2173
|
-
};
|
|
2174
|
-
//#endregion
|
|
2175
|
-
//#region src/core/hooks/useStore.d.ts
|
|
2176
|
-
/**
|
|
2177
|
-
* Hook to access and mutate the Alepha state.
|
|
2178
|
-
*/
|
|
2179
|
-
declare function useStore<T$1 extends TAtomObject>(target: Atom<T$1>, defaultValue?: Static<T$1>): UseStoreReturn<Static<T$1>>;
|
|
2180
|
-
declare function useStore<Key extends keyof State>(target: Key, defaultValue?: State[Key]): UseStoreReturn<State[Key]>;
|
|
2181
|
-
type UseStoreReturn<T$1> = [T$1, (value: T$1) => void];
|
|
2182
|
-
//#endregion
|
|
2183
|
-
//#region src/core/components/ErrorBoundary.d.ts
|
|
2184
|
-
/**
|
|
2185
|
-
* Props for the ErrorBoundary component.
|
|
2186
|
-
*/
|
|
2187
|
-
interface ErrorBoundaryProps {
|
|
2188
|
-
/**
|
|
2189
|
-
* Fallback React node to render when an error is caught.
|
|
2190
|
-
* If not provided, a default error message will be shown.
|
|
2191
|
-
*/
|
|
2192
|
-
fallback: (error: Error) => ReactNode;
|
|
2193
|
-
/**
|
|
2194
|
-
* Optional callback that receives the error and error info.
|
|
2195
|
-
* Use this to log errors to a monitoring service.
|
|
2196
|
-
*/
|
|
2197
|
-
onError?: (error: Error, info: ErrorInfo) => void;
|
|
2198
|
-
}
|
|
2199
|
-
/**
|
|
2200
|
-
* State of the ErrorBoundary component.
|
|
2201
|
-
*/
|
|
2202
|
-
interface ErrorBoundaryState {
|
|
2203
|
-
error?: Error;
|
|
2204
|
-
}
|
|
2205
|
-
/**
|
|
2206
|
-
* A reusable error boundary for catching rendering errors
|
|
2207
|
-
* in any part of the React component tree.
|
|
2208
|
-
*/
|
|
2209
|
-
declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
|
|
2210
|
-
constructor(props: ErrorBoundaryProps);
|
|
2211
|
-
/**
|
|
2212
|
-
* Update state so the next render shows the fallback UI.
|
|
2213
|
-
*/
|
|
2214
|
-
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
2215
|
-
/**
|
|
2216
|
-
* Lifecycle method called when an error is caught.
|
|
2217
|
-
* You can log the error or perform side effects here.
|
|
2218
|
-
*/
|
|
2219
|
-
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
2220
|
-
render(): ReactNode;
|
|
2221
|
-
}
|
|
2222
|
-
//#endregion
|
|
2223
|
-
//#region src/core/components/ErrorViewer.d.ts
|
|
2224
|
-
interface ErrorViewerProps {
|
|
2225
|
-
error: Error;
|
|
2226
|
-
alepha: Alepha;
|
|
2227
|
-
}
|
|
2228
|
-
declare const ErrorViewer: ({
|
|
2229
|
-
error,
|
|
2230
|
-
alepha
|
|
2231
|
-
}: ErrorViewerProps) => react_jsx_runtime0.JSX.Element;
|
|
2232
|
-
//#endregion
|
|
2233
|
-
//#region src/core/components/Link.d.ts
|
|
2234
|
-
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
2235
|
-
href: string;
|
|
2236
|
-
}
|
|
2237
|
-
declare const Link: (props: LinkProps) => react_jsx_runtime0.JSX.Element;
|
|
2238
|
-
//#endregion
|
|
2239
|
-
//#region src/core/components/NestedView.d.ts
|
|
2240
|
-
interface NestedViewProps {
|
|
2241
|
-
children?: ReactNode;
|
|
2242
|
-
errorBoundary?: false | ((error: Error) => ReactNode);
|
|
2243
|
-
}
|
|
2244
|
-
declare const _default: react1.MemoExoticComponent<(props: NestedViewProps) => react_jsx_runtime0.JSX.Element>;
|
|
2245
|
-
//#endregion
|
|
2246
|
-
//#region src/core/components/NotFound.d.ts
|
|
2247
|
-
declare function NotFoundPage(props: {
|
|
2248
|
-
style?: CSSProperties;
|
|
2249
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
2250
|
-
//#endregion
|
|
2251
|
-
//#region src/core/contexts/RouterLayerContext.d.ts
|
|
2252
|
-
interface RouterLayerContextValue {
|
|
2253
|
-
index: number;
|
|
2254
|
-
path: string;
|
|
2255
|
-
}
|
|
2256
|
-
declare const RouterLayerContext: react1.Context<RouterLayerContextValue | undefined>;
|
|
2257
|
-
//#endregion
|
|
2258
|
-
//#region src/core/hooks/useActive.d.ts
|
|
2259
|
-
interface UseActiveOptions {
|
|
2260
|
-
href: string;
|
|
2261
|
-
startWith?: boolean;
|
|
2262
|
-
}
|
|
2263
|
-
declare const useActive: (args: string | UseActiveOptions) => UseActiveHook;
|
|
2264
|
-
interface UseActiveHook {
|
|
2265
|
-
isActive: boolean;
|
|
2266
|
-
anchorProps: AnchorProps;
|
|
2267
|
-
isPending: boolean;
|
|
2268
|
-
}
|
|
2269
|
-
//#endregion
|
|
2270
|
-
//#region src/core/hooks/useQueryParams.d.ts
|
|
2271
|
-
/**
|
|
2272
|
-
* Not well tested. Use with caution.
|
|
2273
|
-
*/
|
|
2274
|
-
declare const useQueryParams: <T$1 extends TObject>(schema: T$1, options?: UseQueryParamsHookOptions) => [Partial<Static<T$1>>, (data: Static<T$1>) => void];
|
|
2275
|
-
interface UseQueryParamsHookOptions {
|
|
2276
|
-
format?: "base64" | "querystring";
|
|
2277
|
-
key?: string;
|
|
2278
|
-
push?: boolean;
|
|
2279
|
-
}
|
|
2280
|
-
//#endregion
|
|
2281
|
-
//#region src/core/services/ReactRouter.d.ts
|
|
2282
|
-
declare class ReactRouter<T$1 extends object> {
|
|
2283
|
-
protected readonly alepha: Alepha;
|
|
2284
|
-
protected readonly pageApi: ReactPageProvider;
|
|
2285
|
-
get state(): ReactRouterState;
|
|
2286
|
-
get pages(): PageRoute[];
|
|
2287
|
-
get concretePages(): PageRoute[];
|
|
2288
|
-
get browser(): ReactBrowserProvider | undefined;
|
|
2289
|
-
isActive(href: string, options?: {
|
|
2290
|
-
startWith?: boolean;
|
|
2291
|
-
}): boolean;
|
|
2292
|
-
path(name: keyof VirtualRouter<T$1> | string, config?: {
|
|
2293
|
-
params?: Record<string, any>;
|
|
2294
|
-
query?: Record<string, any>;
|
|
2295
|
-
}): string;
|
|
2296
|
-
/**
|
|
2297
|
-
* Reload the current page.
|
|
2298
|
-
* This is equivalent to calling `go()` with the current pathname and search.
|
|
2299
|
-
*/
|
|
2300
|
-
reload(): Promise<void>;
|
|
2301
|
-
getURL(): URL;
|
|
2302
|
-
get location(): Location;
|
|
2303
|
-
get current(): ReactRouterState;
|
|
2304
|
-
get pathname(): string;
|
|
2305
|
-
get query(): Record<string, string>;
|
|
2306
|
-
back(): Promise<void>;
|
|
2307
|
-
forward(): Promise<void>;
|
|
2308
|
-
invalidate(props?: Record<string, any>): Promise<void>;
|
|
2309
|
-
go(path: string, options?: RouterGoOptions): Promise<void>;
|
|
2310
|
-
go(path: keyof VirtualRouter<T$1>, options?: RouterGoOptions): Promise<void>;
|
|
2311
|
-
anchor(path: string, options?: RouterGoOptions): AnchorProps;
|
|
2312
|
-
anchor(path: keyof VirtualRouter<T$1>, options?: RouterGoOptions): AnchorProps;
|
|
2313
|
-
base(path: string): string;
|
|
2314
|
-
/**
|
|
2315
|
-
* Set query params.
|
|
2316
|
-
*
|
|
2317
|
-
* @param record
|
|
2318
|
-
* @param options
|
|
2319
|
-
*/
|
|
2320
|
-
setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
|
|
2321
|
-
/**
|
|
2322
|
-
* If true, this will add a new entry to the history stack.
|
|
2323
|
-
*/
|
|
2324
|
-
push?: boolean;
|
|
2325
|
-
}): void;
|
|
2326
|
-
}
|
|
2327
|
-
type VirtualRouter<T$1> = { [K in keyof T$1 as T$1[K] extends PageDescriptor ? K : never]: T$1[K] };
|
|
2328
|
-
//#endregion
|
|
2329
|
-
//#region src/core/hooks/useRouter.d.ts
|
|
2330
|
-
/**
|
|
2331
|
-
* Use this hook to access the React Router instance.
|
|
2332
|
-
*
|
|
2333
|
-
* You can add a type parameter to specify the type of your application.
|
|
2334
|
-
* This will allow you to use the router in a typesafe way.
|
|
2335
|
-
*
|
|
2336
|
-
* @example
|
|
2337
|
-
* class App {
|
|
2338
|
-
* home = $page();
|
|
2339
|
-
* }
|
|
2340
|
-
*
|
|
2341
|
-
* const router = useRouter<App>();
|
|
2342
|
-
* router.go("home"); // typesafe
|
|
2343
|
-
*/
|
|
2344
|
-
declare const useRouter: <T$1 extends object = any>() => ReactRouter<T$1>;
|
|
2345
|
-
//#endregion
|
|
2346
|
-
//#region src/core/hooks/useRouterState.d.ts
|
|
2347
|
-
declare const useRouterState: () => ReactRouterState;
|
|
2348
|
-
//#endregion
|
|
2349
|
-
//#region ../alepha/src/server-static/descriptors/$serve.d.ts
|
|
2350
|
-
interface ServeDescriptorOptions {
|
|
2351
|
-
/**
|
|
2352
|
-
* Prefix for the served path.
|
|
2353
|
-
*
|
|
2354
|
-
* @default "/"
|
|
2355
|
-
*/
|
|
2356
|
-
path?: string;
|
|
2357
|
-
/**
|
|
2358
|
-
* Path to the directory to serve.
|
|
2359
|
-
*
|
|
2360
|
-
* @default process.cwd()
|
|
2361
|
-
*/
|
|
2362
|
-
root?: string;
|
|
2363
|
-
/**
|
|
2364
|
-
* If true, descriptor will be ignored.
|
|
2365
|
-
*
|
|
2366
|
-
* @default false
|
|
2367
|
-
*/
|
|
2368
|
-
disabled?: boolean;
|
|
2369
|
-
/**
|
|
2370
|
-
* Whether to keep dot files (e.g. `.gitignore`, `.env`) in the served directory.
|
|
2371
|
-
*
|
|
2372
|
-
* @default true
|
|
2373
|
-
*/
|
|
2374
|
-
ignoreDotEnvFiles?: boolean;
|
|
2375
|
-
/**
|
|
2376
|
-
* Whether to use the index.html file when the path is a directory.
|
|
2377
|
-
*
|
|
2378
|
-
* @default true
|
|
2379
|
-
*/
|
|
2380
|
-
indexFallback?: boolean;
|
|
2381
|
-
/**
|
|
2382
|
-
* Force all requests "not found" to be served with the index.html file.
|
|
2383
|
-
* This is useful for single-page applications (SPAs) that use client-side only routing.
|
|
2384
|
-
*/
|
|
2385
|
-
historyApiFallback?: boolean;
|
|
2386
|
-
/**
|
|
2387
|
-
* Optional name of the descriptor.
|
|
2388
|
-
* This is used for logging and debugging purposes.
|
|
2389
|
-
*
|
|
2390
|
-
* @default Key name.
|
|
2391
|
-
*/
|
|
2392
|
-
name?: string;
|
|
2393
|
-
/**
|
|
2394
|
-
* Whether to use cache control headers.
|
|
2395
|
-
*
|
|
2396
|
-
* @default {}
|
|
2397
|
-
*/
|
|
2398
|
-
cacheControl?: Partial<CacheControlOptions> | false;
|
|
2399
|
-
}
|
|
2400
|
-
interface CacheControlOptions {
|
|
2401
|
-
/**
|
|
2402
|
-
* Whether to use cache control headers.
|
|
2403
|
-
*
|
|
2404
|
-
* @default [.js, .css]
|
|
2405
|
-
*/
|
|
2406
|
-
fileTypes: string[];
|
|
2407
|
-
/**
|
|
2408
|
-
* The maximum age of the cache in seconds.
|
|
2409
|
-
*
|
|
2410
|
-
* @default 60 * 60 * 24 * 2 // 2 days
|
|
2411
|
-
*/
|
|
2412
|
-
maxAge: DurationLike;
|
|
2413
|
-
/**
|
|
2414
|
-
* Whether to use immutable cache control headers.
|
|
2415
|
-
*
|
|
2416
|
-
* @default true
|
|
2417
|
-
*/
|
|
2418
|
-
immutable: boolean;
|
|
2419
|
-
}
|
|
2420
|
-
//#endregion
|
|
2421
|
-
//#region ../alepha/src/file/services/FileDetector.d.ts
|
|
2422
|
-
interface FileTypeResult {
|
|
2423
|
-
/**
|
|
2424
|
-
* The detected MIME type
|
|
2425
|
-
*/
|
|
2426
|
-
mimeType: string;
|
|
2427
|
-
/**
|
|
2428
|
-
* The detected file extension
|
|
2429
|
-
*/
|
|
2430
|
-
extension: string;
|
|
2431
|
-
/**
|
|
2432
|
-
* Whether the file type was verified by magic bytes
|
|
2433
|
-
*/
|
|
2434
|
-
verified: boolean;
|
|
2435
|
-
/**
|
|
2436
|
-
* The stream (potentially wrapped to allow re-reading)
|
|
2437
|
-
*/
|
|
2438
|
-
stream: Readable;
|
|
2439
|
-
}
|
|
2440
|
-
/**
|
|
2441
|
-
* Service for detecting file types and getting content types.
|
|
2442
|
-
*
|
|
2443
|
-
* @example
|
|
2444
|
-
* ```typescript
|
|
2445
|
-
* const detector = alepha.inject(FileDetector);
|
|
2446
|
-
*
|
|
2447
|
-
* // Get content type from filename
|
|
2448
|
-
* const mimeType = detector.getContentType("image.png"); // "image/png"
|
|
2449
|
-
*
|
|
2450
|
-
* // Detect file type by magic bytes
|
|
2451
|
-
* const stream = createReadStream('image.png');
|
|
2452
|
-
* const result = await detector.detectFileType(stream, 'image.png');
|
|
2453
|
-
* console.log(result.mimeType); // 'image/png'
|
|
2454
|
-
* console.log(result.verified); // true if magic bytes match
|
|
2455
|
-
* ```
|
|
2456
|
-
*/
|
|
2457
|
-
declare class FileDetector {
|
|
2458
|
-
/**
|
|
2459
|
-
* Magic byte signatures for common file formats.
|
|
2460
|
-
* Each signature is represented as an array of bytes or null (wildcard).
|
|
2461
|
-
*/
|
|
2462
|
-
protected static readonly MAGIC_BYTES: Record<string, {
|
|
2463
|
-
signature: (number | null)[];
|
|
2464
|
-
mimeType: string;
|
|
2465
|
-
}[]>;
|
|
2466
|
-
/**
|
|
2467
|
-
* All possible format signatures for checking against actual file content
|
|
2468
|
-
*/
|
|
2469
|
-
protected static readonly ALL_SIGNATURES: {
|
|
2470
|
-
signature: (number | null)[];
|
|
2471
|
-
mimeType: string;
|
|
2472
|
-
ext: string;
|
|
2473
|
-
}[];
|
|
2474
|
-
/**
|
|
2475
|
-
* MIME type map for file extensions.
|
|
2476
|
-
*
|
|
2477
|
-
* Can be used to get the content type of file based on its extension.
|
|
2478
|
-
* Feel free to add more mime types in your project!
|
|
2479
|
-
*/
|
|
2480
|
-
static readonly mimeMap: Record<string, string>;
|
|
2481
|
-
/**
|
|
2482
|
-
* Reverse MIME type map for looking up extensions from MIME types.
|
|
2483
|
-
* Prefers shorter, more common extensions when multiple exist.
|
|
2484
|
-
*/
|
|
2485
|
-
protected static readonly reverseMimeMap: Record<string, string>;
|
|
2486
|
-
/**
|
|
2487
|
-
* Returns the file extension for a given MIME type.
|
|
2488
|
-
*
|
|
2489
|
-
* @param mimeType - The MIME type to look up
|
|
2490
|
-
* @returns The file extension (without dot), or "bin" if not found
|
|
2491
|
-
*
|
|
2492
|
-
* @example
|
|
2493
|
-
* ```typescript
|
|
2494
|
-
* const detector = alepha.inject(FileDetector);
|
|
2495
|
-
* const ext = detector.getExtensionFromMimeType("image/png"); // "png"
|
|
2496
|
-
* const ext2 = detector.getExtensionFromMimeType("application/octet-stream"); // "bin"
|
|
2497
|
-
* ```
|
|
2498
|
-
*/
|
|
2499
|
-
getExtensionFromMimeType(mimeType: string): string;
|
|
2500
|
-
/**
|
|
2501
|
-
* Returns the content type of file based on its filename.
|
|
2502
|
-
*
|
|
2503
|
-
* @param filename - The filename to check
|
|
2504
|
-
* @returns The MIME type
|
|
2505
|
-
*
|
|
2506
|
-
* @example
|
|
2507
|
-
* ```typescript
|
|
2508
|
-
* const detector = alepha.inject(FileDetector);
|
|
2509
|
-
* const mimeType = detector.getContentType("image.png"); // "image/png"
|
|
2510
|
-
* ```
|
|
2511
|
-
*/
|
|
2512
|
-
getContentType(filename: string): string;
|
|
2513
|
-
/**
|
|
2514
|
-
* Detects the file type by checking magic bytes against the stream content.
|
|
2515
|
-
*
|
|
2516
|
-
* @param stream - The readable stream to check
|
|
2517
|
-
* @param filename - The filename (used to get the extension)
|
|
2518
|
-
* @returns File type information including MIME type, extension, and verification status
|
|
2519
|
-
*
|
|
2520
|
-
* @example
|
|
2521
|
-
* ```typescript
|
|
2522
|
-
* const detector = alepha.inject(FileDetector);
|
|
2523
|
-
* const stream = createReadStream('image.png');
|
|
2524
|
-
* const result = await detector.detectFileType(stream, 'image.png');
|
|
2525
|
-
* console.log(result.mimeType); // 'image/png'
|
|
2526
|
-
* console.log(result.verified); // true if magic bytes match
|
|
2527
|
-
* ```
|
|
2528
|
-
*/
|
|
2529
|
-
detectFileType(stream: Readable, filename: string): Promise<FileTypeResult>;
|
|
2530
|
-
/**
|
|
2531
|
-
* Reads all bytes from a stream and returns the first N bytes along with a new stream containing all data.
|
|
2532
|
-
* This approach reads the entire stream upfront to avoid complex async handling issues.
|
|
2533
|
-
*
|
|
2534
|
-
* @protected
|
|
2535
|
-
*/
|
|
2536
|
-
protected peekBytes(stream: Readable, numBytes: number): Promise<{
|
|
2537
|
-
buffer: Buffer;
|
|
2538
|
-
stream: Readable;
|
|
2539
|
-
}>;
|
|
2540
|
-
/**
|
|
2541
|
-
* Checks if a buffer matches a magic byte signature.
|
|
2542
|
-
*
|
|
2543
|
-
* @protected
|
|
2544
|
-
*/
|
|
2545
|
-
protected matchesSignature(buffer: Buffer, signature: (number | null)[]): boolean;
|
|
2546
|
-
}
|
|
2547
|
-
//#endregion
|
|
2548
|
-
//#region ../alepha/src/server-static/providers/ServerStaticProvider.d.ts
|
|
2549
|
-
declare class ServerStaticProvider {
|
|
2550
|
-
protected readonly alepha: Alepha;
|
|
2551
|
-
protected readonly routerProvider: ServerRouterProvider;
|
|
2552
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
2553
|
-
protected readonly fileDetector: FileDetector;
|
|
2554
|
-
protected readonly log: Logger;
|
|
2555
|
-
protected readonly directories: ServeDirectory[];
|
|
2556
|
-
protected readonly configure: alepha139.HookDescriptor<"configure">;
|
|
2557
|
-
createStaticServer(options: ServeDescriptorOptions): Promise<void>;
|
|
2558
|
-
createFileHandler(filepath: string, options: ServeDescriptorOptions): Promise<ServerHandler>;
|
|
2559
|
-
protected getCacheFileTypes(): string[];
|
|
2560
|
-
protected getCacheControl(filename: string, options: ServeDescriptorOptions): {
|
|
2561
|
-
maxAge: number;
|
|
2562
|
-
immutable: boolean;
|
|
2563
|
-
} | undefined;
|
|
2564
|
-
getAllFiles(dir: string, ignoreDotEnvFiles?: boolean): Promise<string[]>;
|
|
2565
|
-
}
|
|
2566
|
-
interface ServeDirectory {
|
|
2567
|
-
options: ServeDescriptorOptions;
|
|
2568
|
-
files: string[];
|
|
2569
|
-
}
|
|
2570
|
-
//#endregion
|
|
2571
|
-
//#region src/core/providers/ReactServerProvider.d.ts
|
|
2572
|
-
declare const envSchema: alepha139.TObject<{
|
|
2573
|
-
REACT_SSR_ENABLED: alepha139.TOptional<alepha139.TBoolean>;
|
|
2574
|
-
REACT_ROOT_ID: alepha139.TString;
|
|
2575
|
-
REACT_SERVER_TEMPLATE: alepha139.TOptional<alepha139.TString>;
|
|
2576
|
-
}>;
|
|
2577
|
-
declare module "alepha" {
|
|
2578
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
2579
|
-
interface State {
|
|
2580
|
-
"alepha.react.server.ssr"?: boolean;
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
/**
|
|
2584
|
-
* React server provider configuration atom
|
|
2585
|
-
*/
|
|
2586
|
-
declare const reactServerOptions: alepha139.Atom<alepha139.TObject<{
|
|
2587
|
-
publicDir: alepha139.TString;
|
|
2588
|
-
staticServer: alepha139.TObject<{
|
|
2589
|
-
disabled: alepha139.TBoolean;
|
|
2590
|
-
path: alepha139.TString;
|
|
2591
|
-
}>;
|
|
2592
|
-
}>, "alepha.react.server.options">;
|
|
2593
|
-
type ReactServerProviderOptions = Static<typeof reactServerOptions.schema>;
|
|
2594
|
-
declare module "alepha" {
|
|
2595
|
-
interface State {
|
|
2596
|
-
[reactServerOptions.key]: ReactServerProviderOptions;
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
declare class ReactServerProvider {
|
|
2600
|
-
protected readonly log: Logger;
|
|
2601
|
-
protected readonly alepha: Alepha;
|
|
2602
|
-
protected readonly env: {
|
|
2603
|
-
REACT_SSR_ENABLED?: boolean | undefined;
|
|
2604
|
-
REACT_SERVER_TEMPLATE?: string | undefined;
|
|
2605
|
-
REACT_ROOT_ID: string;
|
|
2606
|
-
};
|
|
2607
|
-
protected readonly pageApi: ReactPageProvider;
|
|
2608
|
-
protected readonly serverProvider: ServerProvider;
|
|
2609
|
-
protected readonly serverStaticProvider: ServerStaticProvider;
|
|
2610
|
-
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
2611
|
-
protected readonly serverTimingProvider: ServerTimingProvider;
|
|
2612
|
-
readonly ROOT_DIV_REGEX: RegExp;
|
|
2613
|
-
protected preprocessedTemplate: PreprocessedTemplate | null;
|
|
2614
|
-
protected readonly options: Readonly<{
|
|
2615
|
-
publicDir: string;
|
|
2616
|
-
staticServer: {
|
|
2617
|
-
disabled: boolean;
|
|
2618
|
-
path: string;
|
|
2619
|
-
};
|
|
2620
|
-
}>;
|
|
2621
|
-
/**
|
|
2622
|
-
* Configure the React server provider.
|
|
2623
|
-
*/
|
|
2624
|
-
readonly onConfigure: alepha139.HookDescriptor<"configure">;
|
|
2625
|
-
get template(): string;
|
|
2626
|
-
protected registerPages(templateLoader: TemplateLoader): Promise<void>;
|
|
2627
|
-
/**
|
|
2628
|
-
* Get the public directory path where static files are located.
|
|
2629
|
-
*/
|
|
2630
|
-
protected getPublicDirectory(): string;
|
|
2631
|
-
/**
|
|
2632
|
-
* Configure the static file server to serve files from the given root directory.
|
|
2633
|
-
*/
|
|
2634
|
-
protected configureStaticServer(root: string): Promise<void>;
|
|
2635
|
-
/**
|
|
2636
|
-
* Configure Vite for SSR.
|
|
2637
|
-
*/
|
|
2638
|
-
protected configureVite(ssrEnabled: boolean): Promise<void>;
|
|
2639
|
-
/**
|
|
2640
|
-
* For testing purposes, creates a render function that can be used.
|
|
2641
|
-
*/
|
|
2642
|
-
render(name: string, options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
|
|
2643
|
-
protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
|
|
2644
|
-
renderToHtml(template: string, state: ReactRouterState, hydration?: boolean): string | Redirection;
|
|
2645
|
-
protected preprocessTemplate(template: string): PreprocessedTemplate;
|
|
2646
|
-
protected fillTemplate(response: {
|
|
2647
|
-
html: string;
|
|
2648
|
-
}, app: string, script: string): void;
|
|
2649
|
-
}
|
|
2650
|
-
type TemplateLoader = () => Promise<string | undefined>;
|
|
2651
|
-
interface PreprocessedTemplate {
|
|
2652
|
-
beforeApp: string;
|
|
2653
|
-
afterApp: string;
|
|
2654
|
-
beforeScript: string;
|
|
2655
|
-
afterScript: string;
|
|
2656
|
-
}
|
|
2657
|
-
//#endregion
|
|
2658
|
-
//#region src/core/index.d.ts
|
|
2659
|
-
declare module "alepha" {
|
|
2660
|
-
interface State {
|
|
2661
|
-
"alepha.react.router.state"?: ReactRouterState;
|
|
2662
|
-
}
|
|
2663
|
-
interface Hooks {
|
|
2664
|
-
/**
|
|
2665
|
-
* Fires when the React application is starting to be rendered on the server.
|
|
2666
|
-
*/
|
|
2667
|
-
"react:server:render:begin": {
|
|
2668
|
-
request?: ServerRequest;
|
|
2669
|
-
state: ReactRouterState;
|
|
2670
|
-
};
|
|
2671
|
-
/**
|
|
2672
|
-
* Fires when the React application has been rendered on the server.
|
|
2673
|
-
*/
|
|
2674
|
-
"react:server:render:end": {
|
|
2675
|
-
request?: ServerRequest;
|
|
2676
|
-
state: ReactRouterState;
|
|
2677
|
-
html: string;
|
|
2678
|
-
};
|
|
2679
|
-
/**
|
|
2680
|
-
* Fires when the React application is being rendered on the browser.
|
|
2681
|
-
*/
|
|
2682
|
-
"react:browser:render": {
|
|
2683
|
-
root: HTMLElement;
|
|
2684
|
-
element: ReactNode;
|
|
2685
|
-
state: ReactRouterState;
|
|
2686
|
-
hydration?: ReactHydrationState;
|
|
2687
|
-
};
|
|
2688
|
-
/**
|
|
2689
|
-
* Fires when a user action is starting.
|
|
2690
|
-
* Action can be a form submission, a route transition, or a custom action.
|
|
2691
|
-
*/
|
|
2692
|
-
"react:action:begin": {
|
|
2693
|
-
type: string;
|
|
2694
|
-
id?: string;
|
|
2695
|
-
};
|
|
2696
|
-
/**
|
|
2697
|
-
* Fires when a user action has succeeded.
|
|
2698
|
-
* Action can be a form submission, a route transition, or a custom action.
|
|
2699
|
-
*/
|
|
2700
|
-
"react:action:success": {
|
|
2701
|
-
type: string;
|
|
2702
|
-
id?: string;
|
|
2703
|
-
};
|
|
2704
|
-
/**
|
|
2705
|
-
* Fires when a user action has failed.
|
|
2706
|
-
* Action can be a form submission, a route transition, or a custom action.
|
|
2707
|
-
*/
|
|
2708
|
-
"react:action:error": {
|
|
2709
|
-
type: string;
|
|
2710
|
-
id?: string;
|
|
2711
|
-
error: Error;
|
|
2712
|
-
};
|
|
2713
|
-
/**
|
|
2714
|
-
* Fires when a user action has completed, regardless of success or failure.
|
|
2715
|
-
* Action can be a form submission, a route transition, or a custom action.
|
|
2716
|
-
*/
|
|
2717
|
-
"react:action:end": {
|
|
2718
|
-
type: string;
|
|
2719
|
-
id?: string;
|
|
2720
|
-
};
|
|
2721
|
-
/**
|
|
2722
|
-
* Fires when a route transition is starting.
|
|
2723
|
-
*/
|
|
2724
|
-
"react:transition:begin": {
|
|
2725
|
-
previous: ReactRouterState;
|
|
2726
|
-
state: ReactRouterState;
|
|
2727
|
-
animation?: PageAnimation;
|
|
2728
|
-
};
|
|
2729
|
-
/**
|
|
2730
|
-
* Fires when a route transition has succeeded.
|
|
2731
|
-
*/
|
|
2732
|
-
"react:transition:success": {
|
|
2733
|
-
state: ReactRouterState;
|
|
2734
|
-
};
|
|
2735
|
-
/**
|
|
2736
|
-
* Fires when a route transition has failed.
|
|
2737
|
-
*/
|
|
2738
|
-
"react:transition:error": {
|
|
2739
|
-
state: ReactRouterState;
|
|
2740
|
-
error: Error;
|
|
2741
|
-
};
|
|
2742
|
-
/**
|
|
2743
|
-
* Fires when a route transition has completed, regardless of success or failure.
|
|
2744
|
-
*/
|
|
2745
|
-
"react:transition:end": {
|
|
2746
|
-
state: ReactRouterState;
|
|
2747
|
-
};
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
/**
|
|
2751
|
-
* Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
|
|
2752
|
-
*
|
|
2753
|
-
* The React module enables building modern React applications using the `$page` descriptor on class properties.
|
|
2754
|
-
* It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
|
|
2755
|
-
* type safety and schema validation for route parameters and data.
|
|
2756
|
-
*
|
|
2757
|
-
* @see {@link $page}
|
|
2758
|
-
* @module alepha.react
|
|
2759
|
-
*/
|
|
2760
|
-
declare const AlephaReact: alepha139.Service<alepha139.Module>;
|
|
2761
|
-
//#endregion
|
|
2762
|
-
export { $page, ActionContext, AlephaContext, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, ErrorHandler, ErrorViewer, Layer, Link, type LinkProps, _default as NestedView, NotFoundPage as NotFound, PageAnimation, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactBrowserRendererOptions, ReactHydrationState, ReactPageProvider, ReactRouter, ReactRouterState, ReactServerProvider, ReactServerProviderOptions, Redirection, RouterGoOptions, RouterLayerContext, RouterLayerContextValue, RouterRenderOptions, RouterStackItem, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActionOptions, UseActionReturn, UseActiveHook, UseActiveOptions, UseQueryParamsHookOptions, UseSchemaReturn, UseStoreReturn, VirtualRouter, isPageRoute, reactBrowserOptions, reactServerOptions, ssrSchemaLoading, useAction, useActive, useAlepha, useClient, useEvents, useInject, useQueryParams, useRouter, useRouterState, useSchema, useStore };
|
|
2763
|
-
//# sourceMappingURL=index.d.cts.map
|