alepha 0.7.6 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +44 -44
  3. package/batch.cjs +8 -0
  4. package/batch.d.ts +114 -0
  5. package/batch.js +1 -0
  6. package/cache/redis.d.ts +15 -18
  7. package/cache.d.ts +115 -119
  8. package/command.cjs +8 -0
  9. package/command.d.ts +154 -0
  10. package/command.js +1 -0
  11. package/core.d.ts +800 -795
  12. package/datetime.d.ts +76 -76
  13. package/lock/redis.d.ts +12 -12
  14. package/lock.d.ts +70 -75
  15. package/package.json +102 -29
  16. package/postgres.d.ts +385 -278
  17. package/queue/redis.d.ts +15 -13
  18. package/queue.d.ts +16 -13
  19. package/react/auth.d.ts +16 -16
  20. package/react/head.cjs +8 -0
  21. package/react/head.d.ts +92 -0
  22. package/react/head.js +1 -0
  23. package/react.d.ts +90 -116
  24. package/redis.d.ts +20 -27
  25. package/retry.d.ts +74 -54
  26. package/scheduler.d.ts +14 -13
  27. package/security.d.ts +38 -41
  28. package/server/cache.d.ts +9 -7
  29. package/server/compress.cjs +8 -0
  30. package/server/compress.d.ts +26 -0
  31. package/server/compress.js +1 -0
  32. package/server/cookies.d.ts +71 -14
  33. package/server/cors.cjs +8 -0
  34. package/server/cors.d.ts +29 -0
  35. package/server/cors.js +1 -0
  36. package/server/health.cjs +8 -0
  37. package/server/health.d.ts +42 -0
  38. package/server/health.js +1 -0
  39. package/server/helmet.cjs +8 -0
  40. package/server/helmet.d.ts +72 -0
  41. package/server/helmet.js +1 -0
  42. package/server/links.cjs +8 -0
  43. package/server/links.d.ts +179 -0
  44. package/server/links.js +1 -0
  45. package/server/metrics.cjs +8 -0
  46. package/server/metrics.d.ts +37 -0
  47. package/server/metrics.js +1 -0
  48. package/server/multipart.cjs +8 -0
  49. package/server/multipart.d.ts +48 -0
  50. package/server/multipart.js +1 -0
  51. package/server/proxy.cjs +8 -0
  52. package/server/proxy.d.ts +41 -0
  53. package/server/proxy.js +1 -0
  54. package/server/static.d.ts +63 -51
  55. package/server/swagger.d.ts +50 -50
  56. package/server.d.ts +220 -437
  57. package/topic/redis.d.ts +24 -23
  58. package/topic.d.ts +9 -19
  59. package/vite.d.ts +8 -1
package/react.d.ts CHANGED
@@ -1,19 +1,18 @@
1
- import * as _alepha_core2 from "@alepha/core";
2
- import * as _alepha_core23 from "@alepha/core";
3
- import * as _alepha_core15 from "@alepha/core";
4
- import * as _alepha_core11 from "@alepha/core";
5
- import { Alepha, Async, KIND, Module, OPTIONS, Service, Static, TObject, TSchema } from "@alepha/core";
6
- import { ApiLinksResponse, ClientScope, HttpClient, HttpVirtualClient, ServerHandler, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "@alepha/server";
7
- import { ServerRouteCache } from "@alepha/server-cache";
8
- import * as react18 from "react";
9
- import * as react21 from "react";
1
+ import * as _alepha_core11 from "alepha";
2
+ import * as _alepha_core18 from "alepha";
3
+ import * as _alepha_core16 from "alepha";
4
+ import * as _alepha_core1 from "alepha";
5
+ import { Alepha, Async, KIND, Module, OPTIONS, Service, Static, TObject, TSchema } from "alepha";
6
+ import { ApiLinksResponse, ServerHandler, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "alepha/server";
7
+ import { ServerRouteCache } from "alepha/server/cache";
8
+ import { ClientScope, HttpVirtualClient, LinkProvider } from "alepha/server/links";
9
+ import * as react23 from "react";
10
+ import * as react24 from "react";
10
11
  import React, { AnchorHTMLAttributes, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
11
- import * as react_jsx_runtime20 from "react/jsx-runtime";
12
12
  import * as react_jsx_runtime22 from "react/jsx-runtime";
13
- import { ServerStaticProvider } from "@alepha/server-static";
14
- import { Route, RouterProvider } from "@alepha/router";
15
- import * as _sinclair_typebox1 from "@sinclair/typebox";
16
- import * as _sinclair_typebox6 from "@sinclair/typebox";
13
+ import * as react_jsx_runtime20 from "react/jsx-runtime";
14
+ import { ServerStaticProvider } from "alepha/server/static";
15
+ import { Route, RouterProvider } from "alepha/router";
17
16
  import { Root } from "react-dom/client";
18
17
 
19
18
  //#region src/components/ClientOnly.d.ts
@@ -106,14 +105,21 @@ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSch
106
105
  */
107
106
  children?: Array<{
108
107
  [OPTIONS]: PageDescriptorOptions;
109
- }>;
108
+ }> | (() => Array<{
109
+ [OPTIONS]: PageDescriptorOptions;
110
+ }>);
110
111
  parent?: {
111
112
  [OPTIONS]: PageDescriptorOptions<PageConfigSchema, TPropsParent>;
112
113
  };
113
114
  can?: () => boolean;
114
- head?: Head | ((props: TProps, previous?: Head) => Head);
115
115
  errorHandler?: (error: Error) => ReactNode;
116
- prerender?: boolean | {
116
+ /**
117
+ * If true, the page will be rendered on the build time.
118
+ * Works only with viteAlepha plugin.
119
+ *
120
+ * Replace boolean by an object to define static entries. (e.g. list of params/query)
121
+ */
122
+ static?: boolean | {
117
123
  entries?: Array<Partial<PageRequestConfig<TConfig>>>;
118
124
  };
119
125
  /**
@@ -142,49 +148,13 @@ declare const $page: {
142
148
  interface PageDescriptorRenderOptions {
143
149
  params?: Record<string, string>;
144
150
  query?: Record<string, string>;
145
- withLayout?: boolean;
151
+ html?: boolean;
152
+ hydration?: boolean;
146
153
  }
147
154
  interface PageDescriptorRenderResult {
148
155
  html: string;
149
156
  context: PageReactContext;
150
157
  }
151
- interface Head {
152
- title?: string;
153
- description?: string;
154
- titleSeparator?: string;
155
- htmlAttributes?: Record<string, string>;
156
- bodyAttributes?: Record<string, string>;
157
- meta?: Array<{
158
- name: string;
159
- content: string;
160
- }>;
161
- keywords?: string[];
162
- author?: string;
163
- robots?: string;
164
- themeColor?: string;
165
- viewport?: string | {
166
- width?: string;
167
- height?: string;
168
- initialScale?: string;
169
- maximumScale?: string;
170
- userScalable?: "no" | "yes" | "0" | "1";
171
- interactiveWidget?: "resizes-visual" | "resizes-content" | "overlays-content";
172
- };
173
- og?: {
174
- title?: string;
175
- description?: string;
176
- image?: string;
177
- url?: string;
178
- type?: string;
179
- };
180
- twitter?: {
181
- card?: string;
182
- title?: string;
183
- description?: string;
184
- image?: string;
185
- site?: string;
186
- };
187
- }
188
158
  interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
189
159
  params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
190
160
  query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
@@ -192,14 +162,14 @@ interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema>
192
162
  type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & PageReactContext;
193
163
  //#endregion
194
164
  //#region src/providers/PageDescriptorProvider.d.ts
195
- declare const envSchema$1: _alepha_core2.TObject<{
196
- REACT_STRICT_MODE: _sinclair_typebox1.TBoolean;
165
+ declare const envSchema$1: _alepha_core11.TObject<{
166
+ REACT_STRICT_MODE: _alepha_core11.TBoolean;
197
167
  }>;
198
168
  declare module "alepha" {
199
169
  interface Env extends Partial<Static<typeof envSchema$1>> {}
200
170
  }
201
171
  declare class PageDescriptorProvider {
202
- protected readonly log: _alepha_core2.Logger;
172
+ protected readonly log: _alepha_core11.Logger;
203
173
  protected readonly env: {
204
174
  REACT_STRICT_MODE: boolean;
205
175
  };
@@ -215,7 +185,6 @@ declare class PageDescriptorProvider {
215
185
  createLayers(route: PageRoute, request: PageRequest): Promise<CreateLayersResult>;
216
186
  protected getErrorHandler(route: PageRoute): ((error: Error) => ReactNode) | undefined;
217
187
  protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
218
- protected fillHead(page: PageRoute, ctx: PageRequest, props: Record<string, any>): void;
219
188
  renderError(error: Error): ReactNode;
220
189
  renderEmptyView(): ReactNode;
221
190
  href(page: {
@@ -225,7 +194,7 @@ declare class PageDescriptorProvider {
225
194
  }, params?: Record<string, any>): string;
226
195
  compile(path: string, params?: Record<string, string>): string;
227
196
  protected renderView(index: number, path: string, view: ReactNode | undefined, page: PageRoute): ReactNode;
228
- protected readonly configure: _alepha_core2.HookDescriptor<"configure">;
197
+ protected readonly configure: _alepha_core11.HookDescriptor<"configure">;
229
198
  protected map(pages: Array<{
230
199
  value: {
231
200
  [OPTIONS]: PageDescriptorOptions;
@@ -261,6 +230,7 @@ interface Layer {
261
230
  element: ReactNode;
262
231
  index: number;
263
232
  path: string;
233
+ route?: PageRoute;
264
234
  }
265
235
  type PreviousLayerData = Omit<Layer, "element" | "index" | "path">;
266
236
  interface AnchorProps {
@@ -302,54 +272,31 @@ interface CreateLayersResult extends RouterState {
302
272
  */
303
273
  interface PageReactContext {
304
274
  url: URL;
305
- head: Head;
306
275
  onError: (error: Error) => ReactNode;
307
276
  links?: ApiLinksResponse;
308
277
  }
309
278
  //#endregion
310
- //#region src/providers/ServerHeadProvider.d.ts
311
- interface Head$1 {
312
- title?: string;
313
- htmlAttributes?: Record<string, string>;
314
- bodyAttributes?: Record<string, string>;
315
- meta?: Array<{
316
- name: string;
317
- content: string;
318
- }>;
319
- }
320
- declare class ServerHeadProvider {
321
- renderHead(template: string, head: Head$1): string;
322
- mergeAttributes(existing: string, attrs: Record<string, string>): string;
323
- parseAttributes(attrStr: string): Record<string, string>;
324
- escapeHtml(str: string): string;
325
- }
326
- //#endregion
327
- //#region src/providers/BrowserHeadProvider.d.ts
328
- declare class BrowserHeadProvider {
329
- renderHead(document: Document, head: Head$1): void;
330
- }
331
- //#endregion
332
279
  //#region src/providers/BrowserRouterProvider.d.ts
333
280
  interface BrowserRoute extends Route {
334
281
  page: PageRoute;
335
282
  }
336
283
  declare class BrowserRouterProvider extends RouterProvider<BrowserRoute> {
337
- protected readonly log: _alepha_core23.Logger;
284
+ protected readonly log: _alepha_core18.Logger;
338
285
  protected readonly alepha: Alepha;
339
286
  protected readonly pageDescriptorProvider: PageDescriptorProvider;
340
287
  add(entry: PageRouteEntry): void;
341
- protected readonly configure: _alepha_core23.HookDescriptor<"configure">;
288
+ protected readonly configure: _alepha_core18.HookDescriptor<"configure">;
342
289
  transition(url: URL, options?: TransitionOptions): Promise<RouterRenderResult>;
343
290
  root(state: RouterState, context: PageReactContext): ReactNode;
344
291
  }
292
+ //# sourceMappingURL=BrowserRouterProvider.d.ts.map
345
293
  //#endregion
346
294
  //#region src/providers/ReactBrowserProvider.d.ts
347
295
  declare class ReactBrowserProvider {
348
- protected readonly log: _alepha_core15.Logger;
349
- protected readonly client: HttpClient;
296
+ protected readonly log: _alepha_core16.Logger;
297
+ protected readonly client: LinkProvider;
350
298
  protected readonly alepha: Alepha;
351
299
  protected readonly router: BrowserRouterProvider;
352
- protected readonly headProvider: BrowserHeadProvider;
353
300
  protected root: Root;
354
301
  transitioning?: {
355
302
  to: string;
@@ -368,8 +315,7 @@ declare class ReactBrowserProvider {
368
315
  * Get embedded layers from the server.
369
316
  */
370
317
  protected getHydrationState(): ReactHydrationState | undefined;
371
- readonly ready: _alepha_core15.HookDescriptor<"ready">;
372
- readonly onTransitionEnd: _alepha_core15.HookDescriptor<"react:transition:end">;
318
+ readonly ready: _alepha_core16.HookDescriptor<"ready">;
373
319
  }
374
320
  interface RouterGoOptions {
375
321
  replace?: boolean;
@@ -380,6 +326,7 @@ interface ReactHydrationState {
380
326
  layers?: Array<PreviousLayerData>;
381
327
  links?: ApiLinksResponse;
382
328
  }
329
+ //# sourceMappingURL=ReactBrowserProvider.d.ts.map
383
330
  //#endregion
384
331
  //#region src/components/ErrorBoundary.d.ts
385
332
  /**
@@ -426,7 +373,7 @@ interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
426
373
  to: string | PageDescriptor;
427
374
  children?: React.ReactNode;
428
375
  }
429
- declare const Link: (props: LinkProps) => react_jsx_runtime20.JSX.Element | null;
376
+ declare const Link: (props: LinkProps) => react_jsx_runtime22.JSX.Element | null;
430
377
  //#endregion
431
378
  //#region src/components/NestedView.d.ts
432
379
  interface NestedViewProps {
@@ -439,7 +386,7 @@ interface NestedViewProps {
439
386
  *
440
387
  * @example
441
388
  * ```tsx
442
- * import { NestedView } from "@alepha/react";
389
+ * import { NestedView } from "alepha/react";
443
390
  *
444
391
  * class App {
445
392
  * parent = $page({
@@ -453,7 +400,7 @@ interface NestedViewProps {
453
400
  * }
454
401
  * ```
455
402
  */
456
- declare const NestedView: (props: NestedViewProps) => react_jsx_runtime22.JSX.Element;
403
+ declare const NestedView: (props: NestedViewProps) => react_jsx_runtime20.JSX.Element;
457
404
  //#endregion
458
405
  //#region src/contexts/RouterContext.d.ts
459
406
  interface RouterContextValue {
@@ -461,14 +408,16 @@ interface RouterContextValue {
461
408
  state: RouterState;
462
409
  context: PageReactContext;
463
410
  }
464
- declare const RouterContext: react18.Context<RouterContextValue | undefined>;
411
+ declare const RouterContext: react23.Context<RouterContextValue | undefined>;
412
+ //# sourceMappingURL=RouterContext.d.ts.map
465
413
  //#endregion
466
414
  //#region src/contexts/RouterLayerContext.d.ts
467
415
  interface RouterLayerContextValue {
468
416
  index: number;
469
417
  path: string;
470
418
  }
471
- declare const RouterLayerContext: react21.Context<RouterLayerContextValue | undefined>;
419
+ declare const RouterLayerContext: react24.Context<RouterLayerContextValue | undefined>;
420
+ //# sourceMappingURL=RouterLayerContext.d.ts.map
472
421
  //#endregion
473
422
  //#region src/hooks/RouterHookApi.d.ts
474
423
  declare class RouterHookApi {
@@ -524,12 +473,14 @@ type HrefLike = string | {
524
473
  };
525
474
  };
526
475
  type VirtualRouter<T> = { [K in keyof T as T[K] extends PageDescriptor ? K : never]: T[K] };
476
+ //# sourceMappingURL=RouterHookApi.d.ts.map
527
477
  //#endregion
528
478
  //#region src/errors/RedirectionError.d.ts
529
479
  declare class RedirectionError extends Error {
530
480
  readonly page: HrefLike;
531
481
  constructor(page: HrefLike);
532
482
  }
483
+ //# sourceMappingURL=RedirectionError.d.ts.map
533
484
  //#endregion
534
485
  //#region src/hooks/useActive.d.ts
535
486
  declare const useActive: (path: HrefLike) => UseActiveHook;
@@ -539,15 +490,19 @@ interface UseActiveHook {
539
490
  isPending: boolean;
540
491
  name?: string;
541
492
  }
493
+ //# sourceMappingURL=useActive.d.ts.map
542
494
  //#endregion
543
495
  //#region src/hooks/useAlepha.d.ts
544
496
  declare const useAlepha: () => Alepha;
497
+ //# sourceMappingURL=useAlepha.d.ts.map
545
498
  //#endregion
546
499
  //#region src/hooks/useClient.d.ts
547
500
  declare const useClient: <T extends object>(_scope?: ClientScope) => HttpVirtualClient<T>;
501
+ //# sourceMappingURL=useClient.d.ts.map
548
502
  //#endregion
549
503
  //#region src/hooks/useInject.d.ts
550
504
  declare const useInject: <T extends object>(clazz: Service<T>) => T;
505
+ //# sourceMappingURL=useInject.d.ts.map
551
506
  //#endregion
552
507
  //#region src/hooks/useQueryParams.d.ts
553
508
  interface UseQueryParamsHookOptions {
@@ -556,9 +511,11 @@ interface UseQueryParamsHookOptions {
556
511
  push?: boolean;
557
512
  }
558
513
  declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Static<T>, (data: Static<T>) => void];
514
+ //# sourceMappingURL=useQueryParams.d.ts.map
559
515
  //#endregion
560
516
  //#region src/hooks/useRouter.d.ts
561
517
  declare const useRouter: () => RouterHookApi;
518
+ //# sourceMappingURL=useRouter.d.ts.map
562
519
  //#endregion
563
520
  //#region src/hooks/useRouterEvents.d.ts
564
521
  declare const useRouterEvents: (opts?: {
@@ -573,18 +530,21 @@ declare const useRouterEvents: (opts?: {
573
530
  error: Error;
574
531
  }) => void;
575
532
  }, deps?: any[]) => void;
533
+ //# sourceMappingURL=useRouterEvents.d.ts.map
576
534
  //#endregion
577
535
  //#region src/hooks/useRouterState.d.ts
578
536
  declare const useRouterState: () => RouterState;
537
+ //# sourceMappingURL=useRouterState.d.ts.map
538
+
579
539
  //#endregion
580
540
  //#region src/providers/ReactServerProvider.d.ts
581
- declare const envSchema: _alepha_core11.TObject<{
582
- REACT_SERVER_DIST: _sinclair_typebox6.TString;
583
- REACT_SERVER_PREFIX: _sinclair_typebox6.TString;
584
- REACT_SSR_ENABLED: _sinclair_typebox6.TOptional<_sinclair_typebox6.TBoolean>;
585
- REACT_ROOT_ID: _sinclair_typebox6.TString;
541
+ declare const envSchema: _alepha_core1.TObject<{
542
+ REACT_SERVER_DIST: _alepha_core1.TString;
543
+ REACT_SERVER_PREFIX: _alepha_core1.TString;
544
+ REACT_SSR_ENABLED: _alepha_core1.TOptional<_alepha_core1.TBoolean>;
545
+ REACT_ROOT_ID: _alepha_core1.TString;
586
546
  }>;
587
- declare module "alepha/core" {
547
+ declare module "alepha" {
588
548
  interface Env extends Partial<Static<typeof envSchema>> {}
589
549
  interface State {
590
550
  "ReactServerProvider.template"?: string;
@@ -592,12 +552,11 @@ declare module "alepha/core" {
592
552
  }
593
553
  }
594
554
  declare class ReactServerProvider {
595
- protected readonly log: _alepha_core11.Logger;
555
+ protected readonly log: _alepha_core1.Logger;
596
556
  protected readonly alepha: Alepha;
597
557
  protected readonly pageDescriptorProvider: PageDescriptorProvider;
598
558
  protected readonly serverStaticProvider: ServerStaticProvider;
599
559
  protected readonly serverRouterProvider: ServerRouterProvider;
600
- protected readonly headProvider: ServerHeadProvider;
601
560
  protected readonly serverTimingProvider: ServerTimingProvider;
602
561
  protected readonly env: {
603
562
  REACT_SSR_ENABLED?: boolean | undefined;
@@ -606,8 +565,8 @@ declare class ReactServerProvider {
606
565
  REACT_ROOT_ID: string;
607
566
  };
608
567
  protected readonly ROOT_DIV_REGEX: RegExp;
609
- readonly onConfigure: _alepha_core11.HookDescriptor<"configure">;
610
- get template(): string | undefined;
568
+ readonly onConfigure: _alepha_core1.HookDescriptor<"configure">;
569
+ get template(): string;
611
570
  protected registerPages(templateLoader: TemplateLoader): Promise<void>;
612
571
  protected getPublicDirectory(): string;
613
572
  protected configureStaticServer(root: string): Promise<void>;
@@ -615,15 +574,16 @@ declare class ReactServerProvider {
615
574
  /**
616
575
  * For testing purposes, creates a render function that can be used.
617
576
  */
618
- protected createRenderFunction(name: string, withIndex?: boolean): (options?: {
619
- params?: Record<string, string>;
620
- query?: Record<string, string>;
621
- }) => Promise<{
577
+ protected createRenderFunction(name: string, withIndex?: boolean): (options?: PageDescriptorRenderOptions) => Promise<{
578
+ context: PageRequest;
579
+ state: CreateLayersResult;
580
+ html: string;
581
+ } | {
622
582
  context: PageRequest;
623
583
  html: string;
624
584
  }>;
625
585
  protected createHandler(page: PageRoute, templateLoader: TemplateLoader): ServerHandler;
626
- renderToHtml(template: string, state: RouterState, context: PageReactContext): string;
586
+ renderToHtml(template: string, state: RouterState, context: PageReactContext, hydration?: boolean): string;
627
587
  protected fillTemplate(response: {
628
588
  html: string;
629
589
  }, app: string, script: string): void;
@@ -631,23 +591,35 @@ declare class ReactServerProvider {
631
591
  type TemplateLoader = () => Promise<string | undefined>;
632
592
  //#endregion
633
593
  //#region src/index.d.ts
634
- declare module "@alepha/core" {
594
+ declare module "alepha" {
635
595
  interface Hooks {
596
+ "react:router:createLayers": {
597
+ request: ServerRequest;
598
+ context: PageRequest;
599
+ layers: PageRequest[];
600
+ };
601
+ "react:server:render:begin": {
602
+ request?: ServerRequest;
603
+ context: PageRequest;
604
+ };
605
+ "react:server:render:end": {
606
+ request?: ServerRequest;
607
+ context: PageRequest;
608
+ state: RouterState;
609
+ html: string;
610
+ };
636
611
  "react:browser:render": {
637
612
  state: RouterState;
638
613
  context: PageReactContext;
639
614
  hydration?: ReactHydrationState;
640
615
  };
641
- "react:server:render": {
642
- request: ServerRequest;
643
- pageRequest: PageRequest;
644
- };
645
616
  "react:transition:begin": {
646
617
  state: RouterState;
647
618
  context: PageReactContext;
648
619
  };
649
620
  "react:transition:success": {
650
621
  state: RouterState;
622
+ context: PageReactContext;
651
623
  };
652
624
  "react:transition:error": {
653
625
  error: Error;
@@ -673,6 +645,8 @@ declare class AlephaReact implements Module {
673
645
  readonly name = "alepha.react";
674
646
  readonly $services: (alepha: Alepha) => Alepha;
675
647
  }
648
+ //# sourceMappingURL=index.d.ts.map
649
+
676
650
  //#endregion
677
- export { $page, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, Head, HrefLike, Layer, Link, NestedView, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorProvider, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageReactContext, PageRequest, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactHydrationState, ReactServerProvider, RedirectionError, RouterContext, RouterContextValue, RouterGoOptions, RouterHookApi, RouterLayerContext, RouterLayerContextValue, RouterRenderResult, RouterStackItem, RouterState, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseQueryParamsHookOptions, VirtualRouter, isPageRoute, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
651
+ export { $page, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, HrefLike, Layer, Link, NestedView, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorProvider, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageReactContext, PageRequest, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactHydrationState, ReactServerProvider, RedirectionError, RouterContext, RouterContextValue, RouterGoOptions, RouterHookApi, RouterLayerContext, RouterLayerContextValue, RouterRenderResult, RouterStackItem, RouterState, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseQueryParamsHookOptions, VirtualRouter, isPageRoute, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
678
652
  //# sourceMappingURL=index.d.ts.map
package/redis.d.ts CHANGED
@@ -1,14 +1,11 @@
1
- import * as _alepha_core7 from "@alepha/core";
2
- import * as _alepha_core0 from "@alepha/core";
3
- import { Alepha, Static } from "@alepha/core";
1
+ import { Alepha, HookDescriptor, Logger, Static, TNumber, TObject, TOptional, TString } from "alepha";
4
2
  import { RedisClientType, SetOptions, createClient } from "@redis/client";
5
- import * as _sinclair_typebox3 from "@sinclair/typebox";
6
3
 
7
4
  //#region src/providers/RedisProvider.d.ts
8
- declare const envSchema: _alepha_core7.TObject<{
9
- REDIS_PORT: _sinclair_typebox3.TNumber;
10
- REDIS_HOST: _sinclair_typebox3.TString;
11
- REDIS_PASSWORD: _sinclair_typebox3.TOptional<_sinclair_typebox3.TString>;
5
+ declare const envSchema: TObject<{
6
+ REDIS_PORT: TNumber;
7
+ REDIS_HOST: TString;
8
+ REDIS_PASSWORD: TOptional<TString>;
12
9
  }>;
13
10
  declare module "alepha" {
14
11
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -19,24 +16,20 @@ type RedisClient = RedisClientType<{}, {}, {}, 3, {
19
16
  type RedisClientOptions = Parameters<typeof createClient>[0];
20
17
  type RedisSetOptions = SetOptions;
21
18
  declare class RedisProvider {
22
- protected readonly log: _alepha_core7.Logger;
19
+ protected readonly log: Logger;
23
20
  protected readonly alepha: Alepha;
24
- protected readonly env: {
25
- REDIS_PASSWORD?: string | undefined;
26
- REDIS_PORT: number;
27
- REDIS_HOST: string;
28
- };
21
+ protected readonly env: Static<typeof envSchema>;
29
22
  protected readonly client: RedisClient;
30
23
  get publisher(): RedisClient;
31
- protected readonly start: _alepha_core7.HookDescriptor<"start">;
32
- protected readonly stop: _alepha_core7.HookDescriptor<"stop">;
24
+ protected readonly start: HookDescriptor<"start">;
25
+ protected readonly stop: HookDescriptor<"stop">;
33
26
  /**
34
- * Connect to the Redis server.
35
- */
27
+ * Connect to the Redis server.
28
+ */
36
29
  connect(): Promise<void>;
37
30
  /**
38
- * Close the connection to the Redis server.
39
- */
31
+ * Close the connection to the Redis server.
32
+ */
40
33
  close(): Promise<void>;
41
34
  duplicate(options?: Partial<RedisClientOptions>): RedisClient;
42
35
  get(key: string): Promise<Buffer | undefined>;
@@ -45,25 +38,25 @@ declare class RedisProvider {
45
38
  keys(pattern: string): Promise<string[]>;
46
39
  del(keys: string[]): Promise<void>;
47
40
  /**
48
- * Redis subscriber client factory method.
49
- */
41
+ * Redis subscriber client factory method.
42
+ */
50
43
  protected createClient(): RedisClient;
51
44
  }
52
45
  //#endregion
53
46
  //#region src/providers/RedisSubscriberProvider.d.ts
54
47
  declare class RedisSubscriberProvider {
55
- protected readonly log: _alepha_core0.Logger;
48
+ protected readonly log: Logger;
56
49
  protected readonly alepha: Alepha;
57
50
  protected readonly redisProvider: RedisProvider;
58
51
  protected readonly client: RedisClient;
59
52
  get subscriber(): RedisClient;
60
- protected readonly start: _alepha_core0.HookDescriptor<"start">;
61
- protected readonly stop: _alepha_core0.HookDescriptor<"stop">;
53
+ protected readonly start: HookDescriptor<"start">;
54
+ protected readonly stop: HookDescriptor<"stop">;
62
55
  connect(): Promise<void>;
63
56
  close(): Promise<void>;
64
57
  /**
65
- * Redis subscriber client factory method.
66
- */
58
+ * Redis subscriber client factory method.
59
+ */
67
60
  protected createClient(): RedisClient;
68
61
  }
69
62
  //#endregion
package/retry.d.ts CHANGED
@@ -1,71 +1,91 @@
1
- import { MaybePromise } from "@alepha/core";
1
+ import { AlephaError, MaybePromise } from "alepha";
2
+ import { DateTimeProvider, DurationLike } from "alepha/datetime";
2
3
 
3
4
  //#region src/descriptors/$retry.d.ts
4
5
 
6
+ // TODO: move to RetryProvider
5
7
  /**
6
- * `$retry` creates a retry descriptor.
7
- *
8
- * It will retry the given function up to `max` times with a delay of `delay` milliseconds between attempts.
9
- *
10
- * @example
11
- * ```ts
12
- * import { $retry } from "@alepha/core";
13
- *
14
- * class MyService {
15
- * fetchData = $retry({
16
- * max: 5, // maximum number of attempts
17
- * delay: 1000, // ms
18
- * when: (error) => error.message.includes("Network Error"),
19
- * handler: async (url: string) => {
20
- * const response = await fetch(url);
21
- * if (!response.ok) {
22
- * throw new Error(`Failed to fetch: ${response.statusText}`);
23
- * }
24
- * return response.json();
25
- * },
26
- * onError: (error, attempt, url) => {
27
- * // error happened, log it or handle it
28
- * console.error(`Attempt ${attempt} failed for ${url}:`, error);
29
- * },
30
- * });
31
- * }
32
- * ```
33
- */
8
+ * Creates a function that automatically retries a handler upon failure,
9
+ * with support for exponential backoff, max duration, and cancellation.
10
+ */
34
11
  declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => RetryDescriptor<T>;
35
- /**
36
- * Retry Descriptor options.
37
- */
12
+ declare const createRetryHandler: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>, dateTimeProvider: DateTimeProvider, appAbortController?: AbortController) => RetryDescriptor<T>;
13
+ // ---------------------------------------------------------------------------------------------------------------------
14
+ interface RetryBackoffOptions {
15
+ /**
16
+ * Initial delay in milliseconds.
17
+ *
18
+ * @default 200
19
+ */
20
+ initial?: number;
21
+ /**
22
+ * Multiplier for each subsequent delay.
23
+ *
24
+ * @default 2
25
+ */
26
+ factor?: number;
27
+ /**
28
+ * Maximum delay in milliseconds.
29
+ */
30
+ max?: number;
31
+ /**
32
+ * If true, adds a random jitter to the delay to prevent thundering herd.
33
+ *
34
+ * @default true
35
+ */
36
+ jitter?: boolean;
37
+ }
38
38
  interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
39
39
  /**
40
- * Maximum number of attempts.
41
- *
42
- * @default 3
43
- */
40
+ * The function to retry.
41
+ */
42
+ handler: T;
43
+ /**
44
+ * The maximum number of attempts.
45
+ *
46
+ * @default 3
47
+ */
44
48
  max?: number;
45
49
  /**
46
- * Delay in milliseconds.
47
- *
48
- * @default 0
49
- */
50
- delay?: number;
50
+ * The backoff strategy for delays between retries.
51
+ * Can be a fixed number (in ms) or a configuration object for exponential backoff.
52
+ *
53
+ * @default { initial: 200, factor: 2, jitter: true }
54
+ */
55
+ backoff?: number | RetryBackoffOptions;
56
+ /**
57
+ * An overall time limit for all retry attempts combined.
58
+ *
59
+ * e.g., `[5, 'seconds']`
60
+ */
61
+ maxDuration?: DurationLike;
51
62
  /**
52
- * Optional condition to determine when to retry.
53
- */
63
+ * A function that determines if a retry should be attempted based on the error.
64
+ *
65
+ * @default (error) => true (retries on any error)
66
+ */
54
67
  when?: (error: Error) => boolean;
55
68
  /**
56
- * The function to retry.
57
- */
58
- handler: T;
69
+ * A custom callback for when a retry attempt fails.
70
+ * This is called before the delay.
71
+ */
72
+ onError?: (error: Error, attempt: number, ...args: Parameters<T>) => void;
59
73
  /**
60
- * Optional error handler.
61
- *
62
- * This will be called when an error occurs.
63
- *
64
- * @default undefined
65
- */
66
- onError?: (error: Error, attempt: number, ...parameters: Parameters<T>) => void;
74
+ * An AbortSignal to allow for external cancellation of the retry loop.
75
+ */
76
+ signal?: AbortSignal;
67
77
  }
68
78
  type RetryDescriptor<T extends (...args: any[]) => any> = (...parameters: Parameters<T>) => MaybePromise<ReturnType<T>>;
69
79
  //#endregion
70
- export { $retry, RetryDescriptor, RetryDescriptorOptions };
80
+ //#region src/errors/RetryCancelError.d.ts
81
+ declare class RetryCancelError extends AlephaError {
82
+ constructor();
83
+ }
84
+ //#endregion
85
+ //#region src/errors/RetryTimeoutError.d.ts
86
+ declare class RetryTimeoutError extends AlephaError {
87
+ constructor(duration: number);
88
+ }
89
+ //#endregion
90
+ export { $retry, RetryBackoffOptions, RetryCancelError, RetryDescriptor, RetryDescriptorOptions, RetryTimeoutError, createRetryHandler };
71
91
  //# sourceMappingURL=index.d.ts.map