@alepha/react 0.13.7 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,7 @@
1
1
  import { PageConfigSchema, PageRoute, ReactRouterState, TPropsDefault, TPropsParentDefault } from "@alepha/react";
2
- import * as alepha22 from "alepha";
3
- import { Alepha, AlephaError, Async, FileLike, InstantiableClass, KIND, LogLevel, LoggerInterface, Primitive, Static, StreamLike, TArray, TFile, TObject, TRecord, TSchema, TStream, TString, TVoid } from "alepha";
4
- import { IncomingMessage, Server, ServerResponse } from "node:http";
5
- import { Readable } from "node:stream";
6
- import { ReadableStream } from "node:stream/web";
7
- import dayjsDuration from "dayjs/plugin/duration.js";
8
- import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
2
+ import * as alepha1 from "alepha";
3
+ import { KIND, Primitive } from "alepha";
4
+ import { ServerTimingProvider } from "alepha/server";
9
5
 
10
6
  //#region ../../src/head/interfaces/Head.d.ts
11
7
  interface Head extends SimpleHead {
@@ -95,953 +91,11 @@ declare const useHead: (options?: UseHeadOptions) => UseHeadReturn;
95
91
  type UseHeadOptions = Head | ((previous?: Head) => Head);
96
92
  type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
97
93
  //#endregion
98
- //#region ../../../alepha/src/server/schemas/errorSchema.d.ts
99
- declare const errorSchema: alepha22.TObject<{
100
- error: alepha22.TString;
101
- status: alepha22.TInteger;
102
- message: alepha22.TString;
103
- details: alepha22.TOptional<alepha22.TString>;
104
- requestId: alepha22.TOptional<alepha22.TString>;
105
- cause: alepha22.TOptional<alepha22.TObject<{
106
- name: alepha22.TString;
107
- message: alepha22.TString;
108
- }>>;
109
- }>;
110
- type ErrorSchema = Static<typeof errorSchema>;
111
- //#endregion
112
- //#region ../../../alepha/src/server/errors/HttpError.d.ts
113
- declare class HttpError extends AlephaError {
114
- name: string;
115
- static is: (error: unknown, status?: number) => error is HttpErrorLike;
116
- static toJSON(error: HttpError): ErrorSchema;
117
- readonly error: string;
118
- readonly status: number;
119
- readonly requestId?: string;
120
- readonly details?: string;
121
- readonly reason?: {
122
- name: string;
123
- message: string;
124
- };
125
- constructor(options: Partial<ErrorSchema>, cause?: unknown);
126
- }
127
- interface HttpErrorLike extends Error {
128
- status: number;
129
- }
130
- //#endregion
131
- //#region ../../../alepha/src/router/providers/RouterProvider.d.ts
132
- declare abstract class RouterProvider<T extends Route = Route> {
133
- protected routePathRegex: RegExp;
134
- protected tree: Tree<T>;
135
- protected cache: Map<string, RouteMatch<T>>;
136
- match(path: string): RouteMatch<T>;
137
- protected test(path: string): void;
138
- protected push(route: T): void;
139
- protected createRouteMatch(path: string): RouteMatch<T>;
140
- protected mapParams(match: RouteMatch<T>): RouteMatch<T>;
141
- protected createParts(path: string): string[];
142
- }
143
- interface RouteMatch<T extends Route> {
144
- route?: T;
145
- params?: Record<string, string>;
146
- }
147
- interface Route {
148
- path: string;
149
- /**
150
- * Rename a param in the route.
151
- * This is automatically filled when you have scenarios like:
152
- * `/customers/:id` and `/customers/:userId/payments`
153
- *
154
- * In this case, `:id` will be renamed to `:userId` in the second route.
155
- */
156
- mapParams?: Record<string, string>;
157
- }
158
- interface Tree<T extends Route> {
159
- route?: T;
160
- children: {
161
- [key: string]: Tree<T>;
162
- };
163
- param?: {
164
- route?: T;
165
- name: string;
166
- children: {
167
- [key: string]: Tree<T>;
168
- };
169
- };
170
- wildcard?: {
171
- route: T;
172
- };
173
- }
174
- //#endregion
175
- //#region ../../../alepha/src/server/constants/routeMethods.d.ts
176
- declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
177
- type RouteMethod = (typeof routeMethods)[number];
178
- //#endregion
179
- //#region ../../../alepha/src/server/helpers/ServerReply.d.ts
180
- /**
181
- * Helper for building server replies.
182
- */
183
- declare class ServerReply {
184
- headers: Record<string, string> & {
185
- "set-cookie"?: string[];
186
- };
187
- status?: number;
188
- body?: any;
189
- /**
190
- * Redirect to a given URL with optional status code (default 302).
191
- */
192
- redirect(url: string, status?: number): void;
193
- /**
194
- * Set the response status code.
195
- */
196
- setStatus(status: number): this;
197
- /**
198
- * Set a response header.
199
- */
200
- setHeader(name: string, value: string): this;
201
- /**
202
- * Set the response body.
203
- */
204
- setBody(body: any): this;
205
- }
206
- //#endregion
207
- //#region ../../../alepha/src/server/services/UserAgentParser.d.ts
208
- interface UserAgentInfo {
209
- os: "Windows" | "Android" | "Ubuntu" | "MacOS" | "iOS" | "Linux" | "FreeBSD" | "OpenBSD" | "ChromeOS" | "BlackBerry" | "Symbian" | "Windows Phone";
210
- browser: "Chrome" | "Firefox" | "Safari" | "Edge" | "Opera" | "Internet Explorer" | "Brave" | "Vivaldi" | "Samsung Browser" | "UC Browser" | "Yandex";
211
- device: "MOBILE" | "DESKTOP" | "TABLET";
212
- }
213
- /**
214
- * Simple User-Agent parser to detect OS, browser, and device type.
215
- * This parser is not exhaustive and may not cover all edge cases.
216
- *
217
- * Use result for non
218
- */
219
- declare class UserAgentParser {
220
- parse(userAgent?: string): UserAgentInfo;
221
- }
222
- //#endregion
223
- //#region ../../../alepha/src/server/interfaces/ServerRequest.d.ts
224
- type TRequestBody = TObject | TString | TArray | TRecord | TStream;
225
- type TResponseBody = TObject | TString | TRecord | TFile | TArray | TStream | TVoid;
226
- interface RequestConfigSchema {
227
- body?: TRequestBody;
228
- params?: TObject;
229
- query?: TObject;
230
- headers?: TObject;
231
- response?: TResponseBody;
232
- }
233
- interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
234
- body: TConfig["body"] extends TRequestBody ? Static<TConfig["body"]> : any;
235
- headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
236
- params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
237
- query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, any>;
238
- }
239
- type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
240
- interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
241
- /**
242
- * HTTP method used for this request.
243
- */
244
- method: RouteMethod;
245
- /**
246
- * Full request URL.
247
- */
248
- url: URL;
249
- /**
250
- * Unique request ID assigned to this request.
251
- */
252
- requestId: string;
253
- /**
254
- * Client IP address.
255
- * Will parse `X-Forwarded-For` header if present.
256
- */
257
- ip?: string;
258
- /**
259
- * Value of the `Host` header sent by the client.
260
- */
261
- host?: string;
262
- /**
263
- * Browser user agent information.
264
- * Information are not guaranteed to be accurate. Use with caution.
265
- *
266
- * @see {@link UserAgentParser}
267
- */
268
- userAgent: UserAgentInfo;
269
- /**
270
- * Arbitrary metadata attached to the request. Can be used by middlewares to store information.
271
- */
272
- metadata: Record<string, any>;
273
- /**
274
- * Reply object to be used to send response.
275
- */
276
- reply: ServerReply;
277
- /**
278
- * The raw underlying request object (Web Request).
279
- */
280
- raw: ServerRawRequest;
281
- }
282
- interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
283
- /**
284
- * Handler function for this route.
285
- */
286
- handler: ServerHandler<TConfig>;
287
- /**
288
- * HTTP method for this route.
289
- */
290
- method?: RouteMethod;
291
- /**
292
- * Request/response schema for this route.
293
- *
294
- * Request schema contains:
295
- * - body, for POST/PUT/PATCH requests
296
- * - params, for URL parameters (e.g. /user/:id)
297
- * - query, for URL query parameters (e.g. /user?id=123)
298
- * - headers, for HTTP headers
299
- *
300
- * Response schema contains:
301
- * - response
302
- *
303
- * Response schema is used to validate and serialize the response sent by the handler.
304
- */
305
- schema?: TConfig;
306
- /**
307
- * @see ServerLoggerProvider
308
- */
309
- silent?: boolean;
310
- }
311
- type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TResponseBody ? Static<TConfig["response"]> : ResponseBodyType;
312
- type ResponseKind = "json" | "text" | "void" | "file" | "any";
313
- type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
314
- type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
315
- interface ServerResponse$1 {
316
- body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
317
- headers: Record<string, string>;
318
- status: number;
319
- }
320
- type ServerRouteRequestHandler = (request: ServerRequestData) => Promise<ServerResponse$1>;
321
- interface ServerRouteMatcher extends Route {
322
- handler: ServerRouteRequestHandler;
323
- }
324
- interface ServerRequestData {
325
- method: RouteMethod;
326
- url: URL;
327
- headers: Record<string, string>;
328
- query: Record<string, string>;
329
- params: Record<string, string>;
330
- raw: ServerRawRequest;
331
- }
332
- interface ServerRawRequest {
333
- node?: NodeRequestEvent;
334
- web?: WebRequestEvent;
335
- }
336
- interface NodeRequestEvent {
337
- req: IncomingMessage;
338
- res: ServerResponse;
339
- }
340
- interface WebRequestEvent {
341
- req: Request;
342
- res?: Response;
343
- }
344
- //#endregion
345
- //#region ../../../alepha/src/logger/schemas/logEntrySchema.d.ts
346
- declare const logEntrySchema: alepha22.TObject<{
347
- level: alepha22.TUnsafe<"TRACE" | "SILENT" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
348
- message: alepha22.TString;
349
- service: alepha22.TString;
350
- module: alepha22.TString;
351
- context: alepha22.TOptional<alepha22.TString>;
352
- app: alepha22.TOptional<alepha22.TString>;
353
- data: alepha22.TOptional<alepha22.TAny>;
354
- timestamp: alepha22.TNumber;
355
- }>;
356
- type LogEntry = Static<typeof logEntrySchema>;
357
- //#endregion
358
- //#region ../../../alepha/src/datetime/providers/DateTimeProvider.d.ts
359
- type DateTime = DayjsApi.Dayjs;
360
- type Duration = dayjsDuration.Duration;
361
- type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
362
- declare class DateTimeProvider {
363
- static PLUGINS: Array<PluginFunc<any>>;
364
- protected alepha: Alepha;
365
- protected ref: DateTime | null;
366
- protected readonly timeouts: Timeout[];
367
- protected readonly intervals: Interval[];
368
- constructor();
369
- protected readonly onStart: alepha22.HookPrimitive<"start">;
370
- protected readonly onStop: alepha22.HookPrimitive<"stop">;
371
- setLocale(locale: string): void;
372
- isDateTime(value: unknown): value is DateTime;
373
- /**
374
- * Create a new UTC DateTime instance.
375
- */
376
- utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
377
- /**
378
- * Create a new DateTime instance.
379
- */
380
- of(date: string | number | Date | Dayjs | null | undefined): DateTime;
381
- /**
382
- * Get the current date as a string.
383
- */
384
- toISOString(date?: Date | string | DateTime): string;
385
- /**
386
- * Get the current date.
387
- */
388
- now(): DateTime;
389
- /**
390
- * Get the current date as a string.
391
- *
392
- * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
393
- */
394
- nowISOString(): string;
395
- /**
396
- * Get the current date as milliseconds since epoch.
397
- *
398
- * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
399
- */
400
- nowMillis(): number;
401
- /**
402
- * Get the current date as a string.
403
- *
404
- * @protected
405
- */
406
- protected getCurrentDate(): DateTime;
407
- /**
408
- * Create a new Duration instance.
409
- */
410
- duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
411
- isDurationLike(value: unknown): value is DurationLike;
412
- /**
413
- * Return a promise that resolves after the next tick.
414
- * It uses `setTimeout` with 0 ms delay.
415
- */
416
- tick(): Promise<void>;
417
- /**
418
- * Wait for a certain duration.
419
- *
420
- * You can clear the timeout by using the `AbortSignal` API.
421
- * Aborted signal will resolve the promise immediately, it does not reject it.
422
- */
423
- wait(duration: DurationLike, options?: {
424
- signal?: AbortSignal;
425
- now?: number;
426
- }): Promise<void>;
427
- createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
428
- /**
429
- * Run a callback after a certain duration.
430
- */
431
- createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
432
- clearTimeout(timeout: Timeout): void;
433
- clearInterval(interval: Interval): void;
434
- /**
435
- * Run a function with a deadline.
436
- */
437
- deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
438
- /**
439
- * Add time to the current date.
440
- */
441
- travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
442
- /**
443
- * Stop the time.
444
- */
445
- pause(): DateTime;
446
- /**
447
- * Reset the reference date.
448
- */
449
- reset(): void;
450
- }
451
- interface Interval {
452
- timer?: any;
453
- duration: number;
454
- run: () => unknown;
455
- }
456
- interface Timeout {
457
- now: number;
458
- timer?: any;
459
- duration: number;
460
- callback: () => void;
461
- clear: () => void;
462
- }
463
- //#endregion
464
- //#region ../../../alepha/src/logger/providers/LogDestinationProvider.d.ts
465
- declare abstract class LogDestinationProvider {
466
- abstract write(message: string, entry: LogEntry): void;
467
- }
468
- //#endregion
469
- //#region ../../../alepha/src/logger/providers/LogFormatterProvider.d.ts
470
- declare abstract class LogFormatterProvider {
471
- abstract format(entry: LogEntry): string;
472
- }
473
- //#endregion
474
- //#region ../../../alepha/src/logger/services/Logger.d.ts
475
- declare class Logger implements LoggerInterface {
476
- protected readonly alepha: Alepha;
477
- protected readonly formatter: LogFormatterProvider;
478
- protected readonly destination: LogDestinationProvider;
479
- protected readonly dateTimeProvider: DateTimeProvider;
480
- protected readonly levels: Record<string, number>;
481
- protected readonly service: string;
482
- protected readonly module: string;
483
- protected readonly app?: string;
484
- protected appLogLevel: string;
485
- protected logLevel: LogLevel;
486
- constructor(service: string, module: string);
487
- get context(): string | undefined;
488
- get level(): string;
489
- parseLevel(level: string, app: string): LogLevel;
490
- private matchesPattern;
491
- asLogLevel(something: string): LogLevel;
492
- error(message: string, data?: unknown): void;
493
- warn(message: string, data?: unknown): void;
494
- info(message: string, data?: unknown): void;
495
- debug(message: string, data?: unknown): void;
496
- trace(message: string, data?: unknown): void;
497
- protected log(level: LogLevel, message: string, data?: unknown): void;
498
- protected emit(entry: LogEntry, message?: string): void;
499
- }
500
- //#endregion
501
- //#region ../../../alepha/src/logger/index.d.ts
502
- declare const envSchema$2: alepha22.TObject<{
503
- /**
504
- * Default log level for the application.
505
- *
506
- * Default by environment:
507
- * - dev = info
508
- * - prod = info
509
- * - test = error
510
- *
511
- * Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
512
- *
513
- * Level can be set for a specific module:
514
- *
515
- * @example
516
- * LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
517
- * LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
518
- */
519
- LOG_LEVEL: alepha22.TOptional<alepha22.TString>;
520
- /**
521
- * Built-in log formats.
522
- * - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
523
- * - "pretty" - Simple text format, human-readable, with colors. {@link PrettyFormatterProvider}
524
- * - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
525
- */
526
- LOG_FORMAT: alepha22.TOptional<alepha22.TUnsafe<"json" | "pretty" | "raw">>;
527
- }>;
528
- declare module "alepha" {
529
- interface Env extends Partial<Static<typeof envSchema$2>> {}
530
- interface State {
531
- /**
532
- * Current log level for the application or specific modules.
533
- */
534
- "alepha.logger.level"?: string;
535
- }
536
- interface Hooks {
537
- log: {
538
- message?: string;
539
- entry: LogEntry;
540
- };
541
- }
542
- }
543
- //#endregion
544
- //#region ../../../alepha/src/server/services/ServerRequestParser.d.ts
545
- declare class ServerRequestParser {
546
- protected readonly alepha: Alepha;
547
- protected readonly userAgentParser: UserAgentParser;
548
- createServerRequest(rawRequest: ServerRequestData): ServerRequest;
549
- getRequestId(request: ServerRequestData): string | undefined;
550
- getRequestUserAgent(request: ServerRequestData): UserAgentInfo;
551
- getRequestIp(request: ServerRequestData): string | undefined;
552
- }
553
- //#endregion
554
- //#region ../../../alepha/src/server/providers/ServerTimingProvider.d.ts
555
- type TimingMap = Record<string, [number, number]>;
556
- declare class ServerTimingProvider {
557
- protected readonly log: Logger;
558
- protected readonly alepha: Alepha;
559
- options: {
560
- prefix: string;
561
- disabled: boolean;
562
- };
563
- readonly onRequest: alepha22.HookPrimitive<"server:onRequest">;
564
- readonly onResponse: alepha22.HookPrimitive<"server:onResponse">;
565
- protected get handlerName(): string;
566
- beginTiming(name: string): void;
567
- endTiming(name: string): void;
568
- protected setDuration(name: string, timing: TimingMap): void;
569
- }
570
- //#endregion
571
- //#region ../../../alepha/src/server/providers/ServerRouterProvider.d.ts
572
- /**
573
- * Main router for all routes on the server side.
574
- *
575
- * - $route => generic route
576
- * - $action => action route (for API calls)
577
- * - $page => React route (for SSR)
578
- */
579
- declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
580
- protected readonly log: Logger;
581
- protected readonly alepha: Alepha;
582
- protected readonly routes: ServerRoute[];
583
- protected readonly serverTimingProvider: ServerTimingProvider;
584
- protected readonly serverRequestParser: ServerRequestParser;
585
- /**
586
- * Get all registered routes, optionally filtered by a pattern.
587
- *
588
- * Pattern accept simple wildcard '*' at the end.
589
- * Example: '/api/*' will match all routes starting with '/api/' but '/api/' will match only that exact route.
590
- */
591
- getRoutes(pattern?: string): ServerRoute[];
592
- createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
593
- protected getContextId(headers: Record<string, string>): string;
594
- protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
595
- status: number;
596
- headers: Record<string, string> & {
597
- "set-cookie"?: string[];
598
- };
599
- body: any;
600
- }>;
601
- protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
602
- serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
603
- protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
604
- protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
605
- validateRequest(route: {
606
- schema?: RequestConfigSchema;
607
- }, request: ServerRequestConfig): void;
608
- }
609
- //#endregion
610
- //#region ../../../alepha/src/server/providers/ServerProvider.d.ts
611
- /**
612
- * Base server provider to handle incoming requests and route them.
613
- *
614
- * This is the default implementation for serverless environments.
615
- *
616
- * ServerProvider supports both Node.js HTTP requests and Web (Fetch API) requests.
617
- */
618
- declare class ServerProvider {
619
- protected readonly log: Logger;
620
- protected readonly alepha: Alepha;
621
- protected readonly dateTimeProvider: DateTimeProvider;
622
- protected readonly router: ServerRouterProvider;
623
- protected readonly internalServerErrorMessage = "Internal Server Error";
624
- get hostname(): string;
625
- /**
626
- * When a Node.js HTTP request is received from outside. (Vercel, AWS Lambda, etc.)
627
- */
628
- protected readonly onNodeRequest: alepha22.HookPrimitive<"node:request">;
629
- /**
630
- * When a Web (Fetch API) request is received from outside. (Netlify, Cloudflare Workers, etc.)
631
- */
632
- protected readonly onWebRequest: alepha22.HookPrimitive<"web:request">;
633
- /**
634
- * Handle Node.js HTTP request event.
635
- *
636
- * Technically, we just convert Node.js request to Web Standard Request.
637
- */
638
- handleNodeRequest(nodeRequestEvent: NodeRequestEvent): Promise<void>;
639
- /**
640
- * Handle Web (Fetch API) request event.
641
- */
642
- handleWebRequest(ev: WebRequestEvent): Promise<void>;
643
- /**
644
- * Helper for Vite development mode to let Vite handle (or not) 404.
645
- */
646
- protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
647
- }
648
- //#endregion
649
- //#region ../../../alepha/src/cache/providers/CacheProvider.d.ts
650
- /**
651
- * Cache provider interface.
652
- *
653
- * All methods are asynchronous and return promises.
654
- * Values are stored as Uint8Array.
655
- */
656
- declare abstract class CacheProvider {
657
- /**
658
- * Get the value of a key.
659
- *
660
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
661
- * @param key The key of the value to get.
662
- *
663
- * @return The value of the key, or undefined if the key does not exist.
664
- */
665
- abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
666
- /**
667
- * Set the string value of a key.
668
- *
669
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
670
- * @param key The key of the value to set.
671
- * @param value The value to set.
672
- * @param ttl The time-to-live of the key, in milliseconds.
673
- *
674
- * @return The value of the key.
675
- */
676
- abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
677
- /**
678
- * Remove the specified keys.
679
- *
680
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
681
- * @param keys The keys to delete.
682
- */
683
- abstract del(name: string, ...keys: string[]): Promise<void>;
684
- abstract has(name: string, key: string): Promise<boolean>;
685
- abstract keys(name: string, filter?: string): Promise<string[]>;
686
- /**
687
- * Remove all keys from all cache names.
688
- */
689
- abstract clear(): Promise<void>;
690
- }
691
- //#endregion
692
- //#region ../../../alepha/src/cache/primitives/$cache.d.ts
693
- interface CachePrimitiveOptions<TReturn = any, TParameter extends any[] = any[]> {
694
- /**
695
- * The cache name. This is useful for invalidating multiple caches at once.
696
- *
697
- * Store key as `cache:$name:$key`.
698
- *
699
- * @default Name of the key of the class.
700
- */
701
- name?: string;
702
- /**
703
- * Function which returns cached data.
704
- */
705
- handler?: (...args: TParameter) => TReturn;
706
- /**
707
- * The key generator for the cache.
708
- * If not provided, the arguments will be json.stringify().
709
- */
710
- key?: (...args: TParameter) => string;
711
- /**
712
- * The store provider for the cache.
713
- * If not provided, the default store provider will be used.
714
- */
715
- provider?: InstantiableClass<CacheProvider> | "memory";
716
- /**
717
- * The time-to-live for the cache in seconds.
718
- * Set 0 to skip expiration.
719
- *
720
- * @default 300 (5 minutes).
721
- */
722
- ttl?: DurationLike;
723
- /**
724
- * If the cache is disabled.
725
- */
726
- disabled?: boolean;
727
- }
728
- declare class CachePrimitive<TReturn = any, TParameter extends any[] = any[]> extends Primitive<CachePrimitiveOptions<TReturn, TParameter>> {
729
- protected readonly env: {
730
- CACHE_ENABLED: boolean;
731
- CACHE_DEFAULT_TTL: number;
732
- };
733
- protected readonly dateTimeProvider: DateTimeProvider;
734
- protected readonly provider: CacheProvider;
735
- protected encoder: TextEncoder;
736
- protected decoder: TextDecoder;
737
- protected codes: {
738
- BINARY: number;
739
- JSON: number;
740
- STRING: number;
741
- };
742
- get container(): string;
743
- run(...args: TParameter): Promise<TReturn>;
744
- key(...args: TParameter): string;
745
- invalidate(...keys: string[]): Promise<void>;
746
- set(key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
747
- get(key: string): Promise<TReturn | undefined>;
748
- protected serialize<TReturn>(value: TReturn): Uint8Array;
749
- protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
750
- protected $provider(): CacheProvider;
751
- }
752
- interface CachePrimitiveFn<TReturn = any, TParameter extends any[] = any[]> extends CachePrimitive<TReturn, TParameter> {
753
- /**
754
- * Run the cache primitive with the provided arguments.
755
- */
756
- (...args: TParameter): Promise<TReturn>;
757
- }
758
- //#endregion
759
- //#region ../../../alepha/src/server/services/HttpClient.d.ts
760
- declare class HttpClient {
761
- protected readonly log: Logger;
762
- protected readonly alepha: Alepha;
763
- readonly cache: CachePrimitiveFn<HttpClientCache, any[]>;
764
- protected readonly pendingRequests: HttpClientPendingRequests;
765
- fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
766
- fetch<T extends TSchema>(url: string, request?: RequestInitWithOptions<T>): Promise<FetchResponse<Static<T>>>;
767
- protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
768
- protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
769
- protected responseData(response: Response, options: FetchOptions): Promise<any>;
770
- protected isMaybeFile(response: Response): boolean;
771
- protected createFileLike(response: Response, defaultFileName?: string): FileLike;
772
- pathVariables(url: string, action: {
773
- schema?: {
774
- params?: TObject;
775
- };
776
- }, args?: ServerRequestConfigEntry): string;
777
- queryParams(url: string, action: {
778
- schema?: {
779
- query?: TObject;
780
- };
781
- }, args?: ServerRequestConfigEntry): string;
782
- }
783
- interface FetchOptions<T extends TSchema = TSchema> {
784
- /**
785
- * Key to identify the request in the pending requests.
786
- */
787
- key?: string;
788
- /**
789
- * The schema to validate the response against.
790
- */
791
- schema?: {
792
- response?: T;
793
- };
794
- /**
795
- * Built-in cache options.
796
- */
797
- localCache?: boolean | number | DurationLike;
798
- }
799
- type RequestInitWithOptions<T extends TSchema = TSchema> = RequestInit & FetchOptions<T>;
800
- interface FetchResponse<T = any> {
801
- data: T;
802
- status: number;
803
- statusText: string;
804
- headers: Headers;
805
- raw?: Response;
806
- }
807
- type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
808
- interface HttpClientCache {
809
- data: any;
810
- etag?: string;
811
- }
812
- interface FetchActionArgs {
813
- action: HttpAction;
814
- host?: string;
815
- config?: ServerRequestConfigEntry;
816
- options?: ClientRequestOptions;
817
- }
818
- interface HttpAction {
819
- method?: string;
820
- prefix?: string;
821
- path: string;
822
- requestBodyType?: string;
823
- schema?: {
824
- params?: TObject;
825
- query?: TObject;
826
- body?: TRequestBody;
827
- response?: TResponseBody;
828
- };
829
- }
830
- //#endregion
831
- //#region ../../../alepha/src/server/primitives/$action.d.ts
832
- interface ActionPrimitiveOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
833
- /**
834
- * Name of the action.
835
- *
836
- * - It will be used to generate the route path if `path` is not provided.
837
- * - It will be used to generate the permission name if `security` is enabled.
838
- */
839
- name?: string;
840
- /**
841
- * Group actions together.
842
- *
843
- * - If not provided, the service name containing the route will be used.
844
- * - It will be used as Tag for documentation purposes.
845
- * - It will be used for permission name generation if `security` is enabled.
846
- *
847
- * @example
848
- * ```ts
849
- * // group = "MyController"
850
- * class MyController {
851
- * hello = $action({ handler: () => "Hello World" });
852
- * }
853
- *
854
- * // group = "users"
855
- * class MyOtherController {
856
- * group = "users";
857
- * a1 = $action({ handler: () => "Action 1", group: this.group });
858
- * a2 = $action({ handler: () => "Action 2", group: this.group });
859
- * }
860
- * ```
861
- */
862
- group?: string;
863
- /**
864
- * Pathname of the route. If not provided, property key is used.
865
- */
866
- path?: string;
867
- /**
868
- * The route method.
869
- *
870
- * - If not provided, it will be set to "GET" by default.
871
- * - If not provider and a body is provided, it will be set to "POST".
872
- *
873
- * Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
874
- */
875
- method?: RouteMethod;
876
- /**
877
- * The config schema of the route.
878
- * - body: The request body schema.
879
- * - params: Path variables schema.
880
- * - query: The request query-params schema.
881
- * - response: The response schema.
882
- */
883
- schema?: TConfig;
884
- /**
885
- * A short description of the action. Used for documentation purposes.
886
- */
887
- description?: string;
888
- /**
889
- * Disable the route. Useful with env variables do disable one specific route.
890
- * Route won't be available in the API but can still be called locally!
891
- */
892
- disabled?: boolean;
893
- /**
894
- * Main route handler. This is where the route logic is implemented.
895
- */
896
- handler: ServerActionHandler<TConfig>;
897
- }
898
- declare class ActionPrimitive<TConfig extends RequestConfigSchema> extends Primitive<ActionPrimitiveOptions<TConfig>> {
899
- protected readonly log: Logger;
900
- protected readonly env: {
901
- SERVER_API_PREFIX: string;
902
- };
903
- protected readonly httpClient: HttpClient;
904
- protected readonly serverProvider: ServerProvider;
905
- protected readonly serverRouterProvider: ServerRouterProvider;
906
- protected onInit(): void;
907
- get prefix(): string;
908
- get route(): ServerRoute;
909
- /**
910
- * Returns the name of the action.
911
- */
912
- get name(): string;
913
- /**
914
- * Returns the group of the action. (e.g. "orders", "admin", etc.)
915
- */
916
- get group(): string;
917
- /**
918
- * Returns the HTTP method of the action.
919
- */
920
- get method(): RouteMethod;
921
- /**
922
- * Returns the path of the action.
923
- *
924
- * Path is prefixed by `/api` by default.
925
- */
926
- get path(): string;
927
- get schema(): TConfig | undefined;
928
- getBodyContentType(): string | undefined;
929
- /**
930
- * Call the action handler directly.
931
- * There is no HTTP layer involved.
932
- */
933
- run(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
934
- /**
935
- * Works like `run`, but always fetches (http request) the route.
936
- */
937
- fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
938
- }
939
- type ClientRequestEntry<TConfig extends RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
940
- type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
941
- body: TConfig["body"] extends TObject ? Static<TConfig["body"]> : undefined;
942
- params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : undefined;
943
- headers?: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : undefined;
944
- query?: TConfig["query"] extends TObject ? Partial<Static<TConfig["query"]>> : undefined;
945
- };
946
- interface ClientRequestOptions extends FetchOptions {
947
- /**
948
- * Standard request fetch options.
949
- */
950
- request?: RequestInit;
951
- }
952
- type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
953
- /**
954
- * Specific handler for server actions.
955
- */
956
- type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
957
- /**
958
- * Server Action Request Interface
959
- *
960
- * Can be extended with module augmentation to add custom properties (like `user` in Server Security).
961
- *
962
- * This is NOT Server Request, but a specific type for actions.
963
- */
964
- interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
965
- //#endregion
966
- //#region ../../../alepha/src/server/providers/BunHttpServerProvider.d.ts
967
- declare const envSchema$1: alepha22.TObject<{
968
- SERVER_PORT: alepha22.TInteger;
969
- SERVER_HOST: alepha22.TString;
970
- }>;
971
- declare module "alepha" {
972
- interface Env extends Partial<Static<typeof envSchema$1>> {}
973
- }
974
- //#endregion
975
- //#region ../../../alepha/src/server/providers/NodeHttpServerProvider.d.ts
976
- declare const envSchema: alepha22.TObject<{
977
- SERVER_PORT: alepha22.TInteger;
978
- SERVER_HOST: alepha22.TString;
979
- }>;
980
- declare module "alepha" {
981
- interface Env extends Partial<Static<typeof envSchema>> {}
982
- }
983
- //#endregion
984
- //#region ../../../alepha/src/server/index.d.ts
985
- declare module "alepha" {
986
- interface State {
987
- "alepha.node.server"?: Server;
988
- }
989
- interface Hooks {
990
- "action:onRequest": {
991
- action: ActionPrimitive<RequestConfigSchema>;
992
- request: ServerRequest;
993
- options: ClientRequestOptions;
994
- };
995
- "action:onResponse": {
996
- action: ActionPrimitive<RequestConfigSchema>;
997
- request: ServerRequest;
998
- options: ClientRequestOptions;
999
- response: any;
1000
- };
1001
- "server:onRequest": {
1002
- route: ServerRoute;
1003
- request: ServerRequest;
1004
- };
1005
- "server:onError": {
1006
- route: ServerRoute;
1007
- request: ServerRequest;
1008
- error: Error;
1009
- };
1010
- "server:onSend": {
1011
- route: ServerRoute;
1012
- request: ServerRequest;
1013
- };
1014
- "server:onResponse": {
1015
- route: ServerRoute;
1016
- request: ServerRequest;
1017
- response: ServerResponse$1;
1018
- };
1019
- "client:onRequest": {
1020
- route: HttpAction;
1021
- config: ServerRequestConfigEntry;
1022
- options: ClientRequestOptions;
1023
- headers: Record<string, string>;
1024
- request: RequestInit;
1025
- };
1026
- "client:beforeFetch": {
1027
- url: string;
1028
- options: FetchOptions;
1029
- request: RequestInit;
1030
- };
1031
- "client:onError": {
1032
- route?: HttpAction;
1033
- error: HttpError;
1034
- };
1035
- "node:request": NodeRequestEvent;
1036
- "web:request": WebRequestEvent;
1037
- }
1038
- }
1039
- //#endregion
1040
94
  //#region ../../src/head/providers/ServerHeadProvider.d.ts
1041
95
  declare class ServerHeadProvider {
1042
96
  protected readonly headProvider: HeadProvider;
1043
97
  protected readonly serverTimingProvider: ServerTimingProvider;
1044
- protected readonly onServerRenderEnd: alepha22.HookPrimitive<"react:server:render:end">;
98
+ protected readonly onServerRenderEnd: alepha1.HookPrimitive<"react:server:render:end">;
1045
99
  renderHead(template: string, head: SimpleHead): string;
1046
100
  protected mergeAttributes(existing: string, attrs: Record<string, string>): string;
1047
101
  protected parseAttributes(attrStr: string): Record<string, string>;
@@ -1063,7 +117,7 @@ declare module "@alepha/react" {
1063
117
  * @see {@link ServerHeadProvider}
1064
118
  * @module alepha.react.head
1065
119
  */
1066
- declare const AlephaReactHead: alepha22.Service<alepha22.Module>;
120
+ declare const AlephaReactHead: alepha1.Service<alepha1.Module>;
1067
121
  //#endregion
1068
122
  export { $head, AlephaReactHead, Head, HeadPrimitive, HeadPrimitiveOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
1069
123
  //# sourceMappingURL=index.d.ts.map