alepha 0.7.3 → 0.7.5

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/react.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { TSchema as TSchema$1, KIND, OPTIONS, Static as Static$1, Async, Alepha, Service, TObject as TObject$1 } from '@alepha/core';
3
- import { ServerRoute, ServerRequest, ApiLinksResponse, HttpClient, ClientScope, HttpVirtualClient, ServerRouterProvider, ServerTimingProvider, ServerHandler } from '@alepha/server';
2
+ import { TSchema as TSchema$1, KIND, OPTIONS, Static, Async, Alepha, Service, TObject, Module } from '@alepha/core';
3
+ import { ServerRequest, ApiLinksResponse, HttpClient, ClientScope, HttpVirtualClient, ServerRouterProvider, ServerTimingProvider, ServerHandler } from '@alepha/server';
4
4
  import * as React from 'react';
5
5
  import React__default, { PropsWithChildren, ReactNode, FC, ErrorInfo, AnchorHTMLAttributes } from 'react';
6
+ import { ServerRouteCache } from '@alepha/server-cache';
6
7
  import { Root } from 'react-dom/client';
7
8
  import { RouterProvider, Route } from '@alepha/router';
8
9
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -17,10 +18,6 @@ declare const Hint: unique symbol;
17
18
  /** Symbol key applied to types */
18
19
  declare const Kind: unique symbol;
19
20
 
20
- type TReadonly<T extends TSchema> = T & {
21
- [ReadonlyKind]: 'Readonly';
22
- };
23
-
24
21
  type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
25
22
  type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
26
23
  interface StringOptions extends SchemaOptions {
@@ -53,49 +50,6 @@ type TOptional<T extends TSchema> = T & {
53
50
  [OptionalKind]: 'Optional';
54
51
  };
55
52
 
56
- /** Creates a static type from a TypeBox type */
57
- type Static<Type extends TSchema, Params extends unknown[] = [], Result = (Type & {
58
- params: Params;
59
- })['static']> = Result;
60
-
61
- type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
62
- [K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
63
- }[keyof T];
64
- type ReadonlyPropertyKeys<T extends TProperties> = {
65
- [K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
66
- }[keyof T];
67
- type OptionalPropertyKeys<T extends TProperties> = {
68
- [K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
69
- }[keyof T];
70
- type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
71
- type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
72
- type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
73
- [K in keyof T]: Static<T[K], P>;
74
- }>;
75
- type TPropertyKey = string | number;
76
- type TProperties = Record<TPropertyKey, TSchema>;
77
- type TAdditionalProperties = undefined | TSchema | boolean;
78
- interface ObjectOptions extends SchemaOptions {
79
- /** Additional property constraints for this object */
80
- additionalProperties?: TAdditionalProperties;
81
- /** The minimum number of properties allowed on this object */
82
- minProperties?: number;
83
- /** The maximum number of properties allowed on this object */
84
- maxProperties?: number;
85
- }
86
- interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
87
- [Kind]: 'Object';
88
- static: ObjectStatic<T, this['params']>;
89
- additionalProperties?: TAdditionalProperties;
90
- type: 'object';
91
- properties: T;
92
- required?: string[];
93
- }
94
-
95
- type Evaluate<T> = T extends infer O ? {
96
- [K in keyof O]: O[K];
97
- } : never;
98
-
99
53
  interface SchemaOptions {
100
54
  $schema?: string;
101
55
  /** Id for this schema */
@@ -148,7 +102,7 @@ interface PageConfigSchema {
148
102
  }
149
103
  type TPropsDefault = any;
150
104
  type TPropsParentDefault = {};
151
- interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Pick<ServerRoute, "cache"> {
105
+ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
152
106
  /**
153
107
  * Name your page.
154
108
  *
@@ -228,6 +182,7 @@ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSch
228
182
  */
229
183
  client?: boolean | ClientOnlyProps;
230
184
  afterHandler?: (request: ServerRequest) => any;
185
+ cache?: ServerRouteCache;
231
186
  }
232
187
  interface PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
233
188
  [KIND]: typeof KEY;
@@ -292,8 +247,8 @@ interface Head$1 {
292
247
  };
293
248
  }
294
249
  interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
295
- params: TConfig["params"] extends TSchema$1 ? Static$1<TConfig["params"]> : Record<string, string>;
296
- query: TConfig["query"] extends TSchema$1 ? Static$1<TConfig["query"]> : Record<string, string>;
250
+ params: TConfig["params"] extends TSchema$1 ? Static<TConfig["params"]> : Record<string, string>;
251
+ query: TConfig["query"] extends TSchema$1 ? Static<TConfig["query"]> : Record<string, string>;
297
252
  }
298
253
  type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & PageReactContext;
299
254
 
@@ -301,7 +256,7 @@ declare const envSchema$1: _alepha_core.TObject<{
301
256
  REACT_STRICT_MODE: TBoolean;
302
257
  }>;
303
258
  declare module "alepha" {
304
- interface Env extends Partial<Static$1<typeof envSchema$1>> {
259
+ interface Env extends Partial<Static<typeof envSchema$1>> {
305
260
  }
306
261
  }
307
262
  declare class PageDescriptorProvider {
@@ -483,6 +438,51 @@ interface ReactHydrationState {
483
438
  links?: ApiLinksResponse;
484
439
  }
485
440
 
441
+ /**
442
+ * Props for the ErrorBoundary component.
443
+ */
444
+ interface ErrorBoundaryProps {
445
+ /**
446
+ * Fallback React node to render when an error is caught.
447
+ * If not provided, a default error message will be shown.
448
+ */
449
+ fallback: (error: Error) => ReactNode;
450
+ /**
451
+ * Optional callback that receives the error and error info.
452
+ * Use this to log errors to a monitoring service.
453
+ */
454
+ onError?: (error: Error, info: ErrorInfo) => void;
455
+ }
456
+ /**
457
+ * State of the ErrorBoundary component.
458
+ */
459
+ interface ErrorBoundaryState {
460
+ error?: Error;
461
+ }
462
+ /**
463
+ * A reusable error boundary for catching rendering errors
464
+ * in any part of the React component tree.
465
+ */
466
+ declare class ErrorBoundary extends React__default.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
467
+ constructor(props: ErrorBoundaryProps);
468
+ /**
469
+ * Update state so the next render shows the fallback UI.
470
+ */
471
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
472
+ /**
473
+ * Lifecycle method called when an error is caught.
474
+ * You can log the error or perform side effects here.
475
+ */
476
+ componentDidCatch(error: Error, info: ErrorInfo): void;
477
+ render(): ReactNode;
478
+ }
479
+
480
+ interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
481
+ to: string | PageDescriptor;
482
+ children?: React__default.ReactNode;
483
+ }
484
+ declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
485
+
486
486
  interface NestedViewProps {
487
487
  children?: ReactNode;
488
488
  }
@@ -509,6 +509,19 @@ interface NestedViewProps {
509
509
  */
510
510
  declare const NestedView: (props: NestedViewProps) => react_jsx_runtime.JSX.Element;
511
511
 
512
+ interface RouterContextValue {
513
+ alepha: Alepha;
514
+ state: RouterState;
515
+ context: PageReactContext;
516
+ }
517
+ declare const RouterContext: React.Context<RouterContextValue | undefined>;
518
+
519
+ interface RouterLayerContextValue {
520
+ index: number;
521
+ path: string;
522
+ }
523
+ declare const RouterLayerContext: React.Context<RouterLayerContextValue | undefined>;
524
+
512
525
  declare class RouterHookApi {
513
526
  private readonly pages;
514
527
  private readonly state;
@@ -570,64 +583,6 @@ declare class RedirectionError extends Error {
570
583
  constructor(page: HrefLike);
571
584
  }
572
585
 
573
- /**
574
- * Props for the ErrorBoundary component.
575
- */
576
- interface ErrorBoundaryProps {
577
- /**
578
- * Fallback React node to render when an error is caught.
579
- * If not provided, a default error message will be shown.
580
- */
581
- fallback: (error: Error) => ReactNode;
582
- /**
583
- * Optional callback that receives the error and error info.
584
- * Use this to log errors to a monitoring service.
585
- */
586
- onError?: (error: Error, info: ErrorInfo) => void;
587
- }
588
- /**
589
- * State of the ErrorBoundary component.
590
- */
591
- interface ErrorBoundaryState {
592
- error?: Error;
593
- }
594
- /**
595
- * A reusable error boundary for catching rendering errors
596
- * in any part of the React component tree.
597
- */
598
- declare class ErrorBoundary extends React__default.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
599
- constructor(props: ErrorBoundaryProps);
600
- /**
601
- * Update state so the next render shows the fallback UI.
602
- */
603
- static getDerivedStateFromError(error: Error): ErrorBoundaryState;
604
- /**
605
- * Lifecycle method called when an error is caught.
606
- * You can log the error or perform side effects here.
607
- */
608
- componentDidCatch(error: Error, info: ErrorInfo): void;
609
- render(): ReactNode;
610
- }
611
-
612
- interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
613
- to: string | PageDescriptor;
614
- children?: React__default.ReactNode;
615
- }
616
- declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
617
-
618
- interface RouterContextValue {
619
- alepha: Alepha;
620
- state: RouterState;
621
- context: PageReactContext;
622
- }
623
- declare const RouterContext: React.Context<RouterContextValue | undefined>;
624
-
625
- interface RouterLayerContextValue {
626
- index: number;
627
- path: string;
628
- }
629
- declare const RouterLayerContext: React.Context<RouterLayerContextValue | undefined>;
630
-
631
586
  declare const useActive: (path: HrefLike) => UseActiveHook;
632
587
  interface UseActiveHook {
633
588
  isActive: boolean;
@@ -647,7 +602,7 @@ interface UseQueryParamsHookOptions {
647
602
  key?: string;
648
603
  push?: boolean;
649
604
  }
650
- declare const useQueryParams: <T extends TObject$1>(schema: T, options?: UseQueryParamsHookOptions) => [Static$1<T>, (data: Static$1<T>) => void];
605
+ declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Static<T>, (data: Static<T>) => void];
651
606
 
652
607
  declare const useRouter: () => RouterHookApi;
653
608
 
@@ -666,14 +621,14 @@ declare const useRouterEvents: (opts?: {
666
621
 
667
622
  declare const useRouterState: () => RouterState;
668
623
 
669
- declare const envSchema: TObject<{
624
+ declare const envSchema: _alepha_core.TObject<{
670
625
  REACT_SERVER_DIST: TString;
671
626
  REACT_SERVER_PREFIX: TString;
672
627
  REACT_SSR_ENABLED: TOptional<TBoolean>;
673
628
  REACT_ROOT_ID: TString;
674
629
  }>;
675
630
  declare module "alepha/core" {
676
- interface Env extends Partial<Static$1<typeof envSchema>> {
631
+ interface Env extends Partial<Static<typeof envSchema>> {
677
632
  }
678
633
  interface State {
679
634
  "ReactServerProvider.template"?: string;
@@ -748,9 +703,18 @@ declare module "@alepha/core" {
748
703
  };
749
704
  }
750
705
  }
751
- declare class ReactModule {
752
- protected readonly alepha: Alepha;
753
- constructor();
706
+ /**
707
+ * Alepha React Module
708
+ *
709
+ * Alepha React Module contains a router for client-side navigation and server-side rendering.
710
+ * Routes can be defined using the `$page` descriptor.
711
+ *
712
+ * @see {@link $page}
713
+ * @module alepha.react
714
+ */
715
+ declare class AlephaReact implements Module {
716
+ readonly name = "alepha.react";
717
+ readonly $services: (alepha: Alepha) => Alepha;
754
718
  }
755
719
 
756
- export { $page, type AnchorProps, ClientOnly, type CreateLayersResult, ErrorBoundary, type Head$1 as Head, type HrefLike, type Layer, Link, NestedView, type PageConfigSchema, type PageDescriptor, type PageDescriptorOptions, PageDescriptorProvider, type PageDescriptorRenderOptions, type PageDescriptorRenderResult, type PageReactContext, type PageRequest, type PageRequestConfig, type PageResolve, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, RedirectionError, RouterContext, type RouterContextValue, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterRenderResult, type RouterStackItem, type RouterState, type TPropsDefault, type TPropsParentDefault, type TransitionOptions, type UseActiveHook, type UseQueryParamsHookOptions, type VirtualRouter, envSchema, isPageRoute, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
720
+ export { $page, AlephaReact, type AnchorProps, ClientOnly, type CreateLayersResult, ErrorBoundary, type Head$1 as Head, type HrefLike, type Layer, Link, NestedView, type PageConfigSchema, type PageDescriptor, type PageDescriptorOptions, PageDescriptorProvider, type PageDescriptorRenderOptions, type PageDescriptorRenderResult, type PageReactContext, type PageRequest, type PageRequestConfig, type PageResolve, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactBrowserProvider, type ReactHydrationState, ReactServerProvider, RedirectionError, RouterContext, type RouterContextValue, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterRenderResult, type RouterStackItem, type RouterState, type TPropsDefault, type TPropsParentDefault, type TransitionOptions, type UseActiveHook, type UseQueryParamsHookOptions, type VirtualRouter, isPageRoute, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
package/redis.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import * as _redis_client from '@redis/client';
2
- import { createClient, SetOptions } from '@redis/client';
3
1
  import * as _alepha_core from '@alepha/core';
4
2
  import { Static, Alepha } from '@alepha/core';
3
+ import { RedisClientType, createClient, SetOptions } from '@redis/client';
5
4
 
6
5
  /** Symbol key applied to readonly types */
7
6
  declare const ReadonlyKind: unique symbol;
@@ -89,7 +88,9 @@ declare module "alepha" {
89
88
  interface Env extends Partial<Static<typeof envSchema>> {
90
89
  }
91
90
  }
92
- type RedisClient = ReturnType<typeof createClient>;
91
+ type RedisClient = RedisClientType<{}, {}, {}, 3, {
92
+ 36: BufferConstructor;
93
+ }>;
93
94
  type RedisClientOptions = Parameters<typeof createClient>[0];
94
95
  type RedisSetOptions = SetOptions;
95
96
  declare class RedisProvider {
@@ -100,7 +101,7 @@ declare class RedisProvider {
100
101
  REDIS_PORT: number;
101
102
  REDIS_HOST: string;
102
103
  };
103
- protected readonly client: _redis_client.RedisClientType<_redis_client.RedisModules, _redis_client.RedisFunctions, _redis_client.RedisScripts, _redis_client.RespVersions, _redis_client.TypeMapping>;
104
+ protected readonly client: RedisClient;
104
105
  get publisher(): RedisClient;
105
106
  protected readonly start: _alepha_core.HookDescriptor<"start">;
106
107
  protected readonly stop: _alepha_core.HookDescriptor<"stop">;
@@ -113,6 +114,11 @@ declare class RedisProvider {
113
114
  */
114
115
  close(): Promise<void>;
115
116
  duplicate(options?: Partial<RedisClientOptions>): RedisClient;
117
+ get(key: string): Promise<Buffer | undefined>;
118
+ set(key: string, value: Buffer | string, options?: RedisSetOptions): Promise<Buffer>;
119
+ has(key: string): Promise<boolean>;
120
+ keys(pattern: string): Promise<string[]>;
121
+ del(keys: string[]): Promise<void>;
116
122
  /**
117
123
  * Redis subscriber client factory method.
118
124
  */
@@ -123,7 +129,7 @@ declare class RedisSubscriberProvider {
123
129
  protected readonly log: _alepha_core.Logger;
124
130
  protected readonly alepha: Alepha;
125
131
  protected readonly redisProvider: RedisProvider;
126
- protected readonly client: _redis_client.RedisClientType<_redis_client.RedisModules, _redis_client.RedisFunctions, _redis_client.RedisScripts, _redis_client.RespVersions, _redis_client.TypeMapping>;
132
+ protected readonly client: RedisClient;
127
133
  get subscriber(): RedisClient;
128
134
  protected readonly start: _alepha_core.HookDescriptor<"start">;
129
135
  protected readonly stop: _alepha_core.HookDescriptor<"stop">;
package/retry.d.ts CHANGED
@@ -1,5 +1,35 @@
1
1
  import { MaybePromise } from '@alepha/core';
2
2
 
3
+ /**
4
+ * `$retry` creates a retry descriptor.
5
+ *
6
+ * It will retry the given function up to `max` times with a delay of `delay` milliseconds between attempts.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { $retry } from "@alepha/core";
11
+ *
12
+ * class MyService {
13
+ * fetchData = $retry({
14
+ * max: 5, // maximum number of attempts
15
+ * delay: 1000, // ms
16
+ * when: (error) => error.message.includes("Network Error"),
17
+ * handler: async (url: string) => {
18
+ * const response = await fetch(url);
19
+ * if (!response.ok) {
20
+ * throw new Error(`Failed to fetch: ${response.statusText}`);
21
+ * }
22
+ * return response.json();
23
+ * },
24
+ * onError: (error, attempt, url) => {
25
+ * // error happened, log it or handle it
26
+ * console.error(`Attempt ${attempt} failed for ${url}:`, error);
27
+ * },
28
+ * });
29
+ * }
30
+ * ```
31
+ */
32
+ declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => RetryDescriptor<T>;
3
33
  /**
4
34
  * Retry Descriptor options.
5
35
  */
@@ -34,35 +64,5 @@ interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
34
64
  onError?: (error: Error, attempt: number, ...parameters: Parameters<T>) => void;
35
65
  }
36
66
  type RetryDescriptor<T extends (...args: any[]) => any> = (...parameters: Parameters<T>) => MaybePromise<ReturnType<T>>;
37
- /**
38
- * `$retry` creates a retry descriptor.
39
- *
40
- * It will retry the given function up to `max` times with a delay of `delay` milliseconds between attempts.
41
- *
42
- * @example
43
- * ```ts
44
- * import { $retry } from "@alepha/core";
45
- *
46
- * class MyService {
47
- * fetchData = $retry({
48
- * max: 5, // maximum number of attempts
49
- * delay: 1000, // ms
50
- * when: (error) => error.message.includes("Network Error"),
51
- * handler: async (url: string) => {
52
- * const response = await fetch(url);
53
- * if (!response.ok) {
54
- * throw new Error(`Failed to fetch: ${response.statusText}`);
55
- * }
56
- * return response.json();
57
- * },
58
- * onError: (error, attempt, url) => {
59
- * // error happened, log it or handle it
60
- * console.error(`Attempt ${attempt} failed for ${url}:`, error);
61
- * },
62
- * });
63
- * }
64
- * ```
65
- */
66
- declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => RetryDescriptor<T>;
67
67
 
68
68
  export { $retry, type RetryDescriptor, type RetryDescriptorOptions };
package/scheduler.d.ts CHANGED
@@ -1,15 +1,23 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { Async, KIND, OPTIONS, Static, Alepha } from '@alepha/core';
3
- import { DurationLike, DateTimeProvider, Interval } from '@alepha/datetime';
2
+ import { Async, KIND, OPTIONS, Alepha, Static } from '@alepha/core';
3
+ import { DateTime, DurationLike, DateTimeProvider, Interval } from '@alepha/datetime';
4
4
  import * as _alepha_lock from '@alepha/lock';
5
- import { ScheduledTask } from 'node-cron';
5
+ import { Cron } from 'cron-schedule';
6
6
 
7
7
  declare const KEY = "SCHEDULER";
8
+ /**
9
+ * Scheduler descriptor.
10
+ */
11
+ declare const $scheduler: {
12
+ (options: SchedulerDescriptorOptions): SchedulerDescriptor;
13
+ [KIND]: string;
14
+ };
15
+ declare const isScheduler: (value: any) => value is SchedulerDescriptor;
8
16
  type SchedulerDescriptorOptions = {
9
17
  /**
10
18
  * Function to run on schedule.
11
19
  */
12
- handler: () => Async<void>;
20
+ handler: (args: SchedulerHandlerArguments) => Async<void>;
13
21
  /**
14
22
  * Name of the scheduler. Defaults to the function name.
15
23
  */
@@ -28,7 +36,9 @@ type SchedulerDescriptorOptions = {
28
36
  interval?: DurationLike;
29
37
  /**
30
38
  * If true, the scheduler will be locked and only one instance will run at a time.
31
- * Defaults to true.
39
+ * You probably need to import {@link AlephaLockRedis} for distributed locking.
40
+ *
41
+ * @default true
32
42
  */
33
43
  lock?: boolean;
34
44
  };
@@ -37,17 +47,9 @@ interface SchedulerDescriptor {
37
47
  [OPTIONS]: SchedulerDescriptorOptions;
38
48
  (): Promise<void>;
39
49
  }
40
- /**
41
- * Scheduler descriptor.
42
- *
43
- * @param options - The scheduler options.
44
- * @returns The descriptor value.
45
- */
46
- declare const $scheduler: {
47
- (options: SchedulerDescriptorOptions): SchedulerDescriptor;
48
- [KIND]: string;
49
- };
50
- declare const isScheduler: (value: any) => value is SchedulerDescriptor;
50
+ interface SchedulerHandlerArguments {
51
+ now: DateTime;
52
+ }
51
53
 
52
54
  /** Symbol key applied to readonly types */
53
55
  declare const ReadonlyKind: unique symbol;
@@ -113,6 +115,28 @@ interface TSchema extends TKind, SchemaOptions {
113
115
  static: unknown;
114
116
  }
115
117
 
118
+ interface CronJob {
119
+ handler: (context: {
120
+ now: DateTime;
121
+ }) => Promise<void>;
122
+ cron: Cron;
123
+ loop: boolean;
124
+ running?: boolean;
125
+ onError?: (error: Error) => void;
126
+ abort: AbortController;
127
+ }
128
+ declare class CronProvider {
129
+ protected readonly dt: DateTimeProvider;
130
+ protected readonly alepha: Alepha;
131
+ protected readonly log: _alepha_core.Logger;
132
+ start(cron: CronJob): void;
133
+ stop(cron: CronJob): void;
134
+ create(expression: string, handler: (context: {
135
+ now: DateTime;
136
+ }) => Promise<void>): CronJob;
137
+ run(task: CronJob, now?: undefined): void;
138
+ }
139
+
116
140
  declare const envSchema: _alepha_core.TObject<{
117
141
  SCHEDULER_PREFIX: TOptional<TString>;
118
142
  }>;
@@ -127,10 +151,12 @@ declare class SchedulerDescriptorProvider {
127
151
  };
128
152
  protected readonly alepha: Alepha;
129
153
  protected readonly dateTimeProvider: DateTimeProvider;
154
+ protected readonly cronProvider: CronProvider;
130
155
  protected readonly schedulers: Scheduler[];
131
156
  protected readonly configure: _alepha_core.HookDescriptor<"configure">;
132
157
  protected readonly start: _alepha_core.HookDescriptor<"start">;
133
158
  protected readonly stop: _alepha_core.HookDescriptor<"stop">;
159
+ protected createContextId(): string;
134
160
  /**
135
161
  * Get the schedulers.
136
162
  */
@@ -150,16 +176,14 @@ declare class SchedulerDescriptorProvider {
150
176
  * @protected
151
177
  */
152
178
  protected createScheduler(options: SchedulerDescriptorOptions, instance: any, key: string): Scheduler;
179
+ protected createHandler(name: string, options: SchedulerDescriptorOptions): (args: SchedulerHandlerArguments) => Promise<void>;
153
180
  trigger(name: string): Promise<void>;
154
181
  protected runLock: _alepha_lock.LockDescriptor<(options: SchedulerDescriptorOptions & {
155
182
  name: string;
183
+ args: SchedulerHandlerArguments;
156
184
  }) => Promise<void>>;
157
- protected run(options: SchedulerDescriptorOptions): Promise<void>;
158
185
  /**
159
186
  * Prefix the scheduler key.
160
- *
161
- * @param key
162
- * @protected
163
187
  */
164
188
  protected prefix(key: string): string;
165
189
  /**
@@ -172,14 +196,22 @@ declare class SchedulerDescriptorProvider {
172
196
  interface Scheduler {
173
197
  name: string;
174
198
  options: SchedulerDescriptorOptions;
175
- trigger: () => Promise<void>;
176
- cron?: ScheduledTask;
199
+ trigger: (args: SchedulerHandlerArguments) => Promise<void>;
200
+ cron?: CronJob;
177
201
  interval?: Interval;
178
202
  }
179
203
 
180
- declare class SchedulerModule {
181
- protected readonly alepha: Alepha;
182
- constructor();
204
+ /**
205
+ * Alepha Scheduler Module
206
+ *
207
+ * Generic interface for scheduling tasks.
208
+ *
209
+ * @see {@link $scheduler}
210
+ * @module alepha.scheduler
211
+ */
212
+ declare class AlephaScheduler {
213
+ readonly name = "alepha.scheduler";
214
+ readonly $services: (alepha: Alepha) => Alepha;
183
215
  }
184
216
 
185
- export { $scheduler, type Scheduler, type SchedulerDescriptor, type SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerModule, isScheduler };
217
+ export { $scheduler, AlephaScheduler, type Scheduler, type SchedulerDescriptor, type SchedulerDescriptorOptions, SchedulerDescriptorProvider, type SchedulerHandlerArguments, isScheduler };
package/security.d.ts CHANGED
@@ -697,9 +697,9 @@ declare module "alepha/core" {
697
697
  };
698
698
  }
699
699
  }
700
- declare class SecurityModule {
701
- protected readonly alepha: Alepha;
702
- constructor();
700
+ declare class AlephaSecurity {
701
+ readonly name = "alepha.security";
702
+ readonly $services: (alepha: Alepha) => Alepha;
703
703
  }
704
704
 
705
- export { $permission, $realm, $role, $serviceAccount, type AccessTokenResponse, type ExtendedJWTPayload, InvalidPermissionError, type JwtParseResult, JwtProvider, type JwtServiceAccountDescriptorOptions, type JwtSignOptions, type KeyLoader, type KeyLoaderHolder, type Oauth2ServiceAccountDescriptorOptions, type Permission, type PermissionDescriptor, type PermissionDescriptorOptions, type Realm, type RealmConfig, type RealmDescriptor, type RealmDescriptorOptions, type Role, type RoleDescriptor, type RoleDescriptorOptions, type SecurityCheckResult, SecurityError, SecurityModule, SecurityProvider, type SecurityUserAccountProvider, type ServiceAccountDescriptor, type ServiceAccountDescriptorOptions, type ServiceAccountStore, type UserAccountInfo, type UserAccountToken, permissionSchema, roleSchema };
705
+ export { $permission, $realm, $role, $serviceAccount, type AccessTokenResponse, AlephaSecurity, type ExtendedJWTPayload, InvalidPermissionError, type JwtParseResult, JwtProvider, type JwtServiceAccountDescriptorOptions, type JwtSignOptions, type KeyLoader, type KeyLoaderHolder, type Oauth2ServiceAccountDescriptorOptions, type Permission, type PermissionDescriptor, type PermissionDescriptorOptions, type Realm, type RealmConfig, type RealmDescriptor, type RealmDescriptorOptions, type Role, type RoleDescriptor, type RoleDescriptorOptions, type SecurityCheckResult, SecurityError, SecurityProvider, type SecurityUserAccountProvider, type ServiceAccountDescriptor, type ServiceAccountDescriptorOptions, type ServiceAccountStore, type UserAccountInfo, type UserAccountToken, permissionSchema, roleSchema };
package/server/cache.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { Alepha, OPTIONS } from '@alepha/core';
2
+ import { Alepha, OPTIONS, Module } from '@alepha/core';
3
3
  import { CacheDescriptorOptions, CacheDescriptorProvider, Cache } from '@alepha/cache';
4
4
  import { DurationLike, DateTimeProvider } from '@alepha/datetime';
5
5
  import { ServerHandler, ServerRequestConfig } from '@alepha/server';
6
6
 
7
7
  declare module "alepha/server" {
8
8
  interface ServerRoute {
9
- cache?: ServiceRouteCache;
9
+ cache?: ServerRouteCache;
10
10
  }
11
11
  interface ActionDescriptor {
12
12
  invalidate: () => Promise<void>;
@@ -27,7 +27,7 @@ declare class ServerCacheProvider {
27
27
  protected getCacheByRoute(route: RouteLike): RouteCache | undefined;
28
28
  protected createCacheKey(args: ServerRequestConfig): string;
29
29
  }
30
- type ServiceRouteCache = boolean | DurationLike | Omit<CacheDescriptorOptions<any>, "handler" | "key">;
30
+ type ServerRouteCache = boolean | DurationLike | Omit<CacheDescriptorOptions<any>, "handler" | "key">;
31
31
  type RouteCache = Cache<{
32
32
  contentType?: string;
33
33
  body: string;
@@ -43,9 +43,40 @@ type RouteLike = {
43
43
  handler?: ServerHandler;
44
44
  };
45
45
 
46
- declare class ServerCacheModule {
47
- protected readonly alepha: Alepha;
48
- constructor();
46
+ /**
47
+ * # Alepha Server Cache Module
48
+ *
49
+ * @description
50
+ * Plugin for Alepha Server that provides server-side caching capabilities.
51
+ * It uses the Alepha Cache module to cache responses from server actions ($action).
52
+ * It also provides a ETag-based cache invalidation mechanism.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { Alepha } from "@alepha/core";
57
+ * import { $action } from "@alepha/server";
58
+ * import { AlephaServerCache } from "alepha/server/cache";
59
+ *
60
+ * class ApiServer {
61
+ * hello = $action({
62
+ * cache: true,
63
+ * handler: () => "Hello, World!",
64
+ * });
65
+ * }
66
+ *
67
+ * const alepha = Alepha.create()
68
+ * .with(AlephaServerCache)
69
+ * .with(ApiServer);
70
+ *
71
+ * run(alepha);
72
+ * ```
73
+ *
74
+ * @see {@link ServerCacheProvider}
75
+ * @module alepha.server.cache
76
+ */
77
+ declare class AlephaServerCache implements Module {
78
+ readonly name = "alepha.server.cache";
79
+ readonly $services: (alepha: Alepha) => Alepha;
49
80
  }
50
81
 
51
- export { ServerCacheModule, ServerCacheProvider, type ServiceRouteCache };
82
+ export { AlephaServerCache, ServerCacheProvider, type ServerRouteCache };
@@ -1,5 +1,5 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { KIND, OPTIONS, Alepha, TObject } from '@alepha/core';
2
+ import { KIND, OPTIONS, Alepha, TObject, Module } from '@alepha/core';
3
3
  import { OpenAPIV3 } from 'openapi-types';
4
4
  import { ServerActionDescriptorProvider, ServerRouterProvider, ServerRouteAction } from '@alepha/server';
5
5
  import { ServerStaticProvider } from '@alepha/server-static';
@@ -100,4 +100,19 @@ declare class ServerSwaggerProvider {
100
100
  protected configureSwaggerUi(prefix: string, options: SwaggerDescriptorOptions): Promise<void>;
101
101
  }
102
102
 
103
- export { $swagger, ServerSwaggerProvider, type SwaggerDescriptor, type SwaggerDescriptorOptions, type SwaggerUiOptions };
103
+ /**
104
+ * Alepha Server Swagger Module
105
+ *
106
+ * Plugin for Alepha Server that provides Swagger documentation capabilities.
107
+ * It generates OpenAPI v3 documentation for the server's endpoints ($action).
108
+ * It also provides a Swagger UI for interactive API documentation.
109
+ *
110
+ * @see {@link ServerSwaggerProvider}
111
+ * @module alepha.server.swagger
112
+ */
113
+ declare class AlephaServerSwagger implements Module {
114
+ readonly name = "alepha.server.swagger";
115
+ readonly $services: (alepha: Alepha) => Alepha;
116
+ }
117
+
118
+ export { $swagger, AlephaServerSwagger, ServerSwaggerProvider, type SwaggerDescriptor, type SwaggerDescriptorOptions, type SwaggerUiOptions };