alepha 0.9.5 → 0.10.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.
package/react.d.ts CHANGED
@@ -6,7 +6,7 @@ import { ClientScope, HttpVirtualClient, LinkProvider, VirtualAction } from "ale
6
6
  import * as _alepha_logger1 from "alepha/logger";
7
7
  import * as react0 from "react";
8
8
  import React, { AnchorHTMLAttributes, CSSProperties, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
9
- import * as react_jsx_runtime0 from "react/jsx-runtime";
9
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
10
10
  import { ServerStaticProvider } from "alepha/server/static";
11
11
  import { DateTimeProvider } from "alepha/datetime";
12
12
  import { Route, RouterProvider } from "alepha/router";
@@ -165,6 +165,91 @@ interface CreateLayersResult {
165
165
  //#region src/descriptors/$page.d.ts
166
166
  /**
167
167
  * Main descriptor for defining a React route in the application.
168
+ *
169
+ * The $page descriptor is the core building block for creating type-safe, SSR-enabled React routes.
170
+ * It provides a declarative way to define pages with powerful features:
171
+ *
172
+ * **Routing & Navigation**
173
+ * - URL pattern matching with parameters (e.g., `/users/:id`)
174
+ * - Nested routing with parent-child relationships
175
+ * - Type-safe URL parameter and query string validation
176
+ *
177
+ * **Data Loading**
178
+ * - Server-side data fetching with the `resolve` function
179
+ * - Automatic serialization and hydration for SSR
180
+ * - Access to request context, URL params, and parent data
181
+ *
182
+ * **Component Loading**
183
+ * - Direct component rendering or lazy loading for code splitting
184
+ * - Client-only rendering when browser APIs are needed
185
+ * - Automatic fallback handling during hydration
186
+ *
187
+ * **Performance Optimization**
188
+ * - Static generation for pre-rendered pages at build time
189
+ * - Server-side caching with configurable TTL and providers
190
+ * - Code splitting through lazy component loading
191
+ *
192
+ * **Error Handling**
193
+ * - Custom error handlers with support for redirects
194
+ * - Hierarchical error handling (child → parent)
195
+ * - HTTP status code handling (404, 401, etc.)
196
+ *
197
+ * **Page Animations**
198
+ * - CSS-based enter/exit animations
199
+ * - Dynamic animations based on page state
200
+ * - Custom timing and easing functions
201
+ *
202
+ * **Lifecycle Management**
203
+ * - Server response hooks for headers and status codes
204
+ * - Page leave handlers for cleanup (browser only)
205
+ * - Permission-based access control
206
+ *
207
+ * @example Simple page with data fetching
208
+ * ```typescript
209
+ * const userProfile = $page({
210
+ * path: "/users/:id",
211
+ * schema: {
212
+ * params: t.object({ id: t.int() }),
213
+ * query: t.object({ tab: t.optional(t.string()) })
214
+ * },
215
+ * resolve: async ({ params }) => {
216
+ * const user = await userApi.getUser(params.id);
217
+ * return { user };
218
+ * },
219
+ * lazy: () => import("./UserProfile.tsx")
220
+ * });
221
+ * ```
222
+ *
223
+ * @example Nested routing with error handling
224
+ * ```typescript
225
+ * const projectSection = $page({
226
+ * path: "/projects/:id",
227
+ * children: () => [projectBoard, projectSettings],
228
+ * resolve: async ({ params }) => {
229
+ * const project = await projectApi.get(params.id);
230
+ * return { project };
231
+ * },
232
+ * errorHandler: (error) => {
233
+ * if (HttpError.is(error, 404)) {
234
+ * return <ProjectNotFound />;
235
+ * }
236
+ * }
237
+ * });
238
+ * ```
239
+ *
240
+ * @example Static generation with caching
241
+ * ```typescript
242
+ * const blogPost = $page({
243
+ * path: "/blog/:slug",
244
+ * static: {
245
+ * entries: posts.map(p => ({ params: { slug: p.slug } }))
246
+ * },
247
+ * resolve: async ({ params }) => {
248
+ * const post = await loadPost(params.slug);
249
+ * return { post };
250
+ * }
251
+ * });
252
+ * ```
168
253
  */
169
254
  declare const $page: {
170
255
  <TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = TPropsParentDefault>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
@@ -534,25 +619,25 @@ interface ErrorViewerProps {
534
619
  declare const ErrorViewer: ({
535
620
  error,
536
621
  alepha
537
- }: ErrorViewerProps) => react_jsx_runtime0.JSX.Element;
622
+ }: ErrorViewerProps) => react_jsx_runtime1.JSX.Element;
538
623
  //#endregion
539
624
  //#region src/components/Link.d.ts
540
625
  interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
541
626
  href: string;
542
627
  }
543
- declare const Link: (props: LinkProps) => react_jsx_runtime0.JSX.Element;
628
+ declare const Link: (props: LinkProps) => react_jsx_runtime1.JSX.Element;
544
629
  //#endregion
545
630
  //#region src/components/NestedView.d.ts
546
631
  interface NestedViewProps {
547
632
  children?: ReactNode;
548
633
  errorBoundary?: false | ((error: Error) => ReactNode);
549
634
  }
550
- declare const _default: react0.MemoExoticComponent<(props: NestedViewProps) => react_jsx_runtime0.JSX.Element>;
635
+ declare const _default: react0.MemoExoticComponent<(props: NestedViewProps) => react_jsx_runtime1.JSX.Element>;
551
636
  //#endregion
552
637
  //#region src/components/NotFound.d.ts
553
638
  declare function NotFoundPage(props: {
554
639
  style?: CSSProperties;
555
- }): react_jsx_runtime0.JSX.Element;
640
+ }): react_jsx_runtime1.JSX.Element;
556
641
  //#endregion
557
642
  //#region src/contexts/AlephaContext.d.ts
558
643
  declare const AlephaContext: react0.Context<Alepha | undefined>;
@@ -586,7 +671,7 @@ interface UseActiveHook {
586
671
  *
587
672
  * - alepha.state() for state management
588
673
  * - alepha.inject() for dependency injection
589
- * - alepha.emit() for event handling
674
+ * - alepha.events.emit() for event handling
590
675
  * etc...
591
676
  */
592
677
  declare const useAlepha: () => Alepha;
@@ -610,7 +695,7 @@ declare const useInject: <T extends object>(service: Service<T>) => T;
610
695
  /**
611
696
  * Not well tested. Use with caution.
612
697
  */
613
- declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Static<T>, (data: Static<T>) => void];
698
+ declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Partial<Static<T>>, (data: Static<T>) => void];
614
699
  interface UseQueryParamsHookOptions {
615
700
  format?: "base64" | "querystring";
616
701
  key?: string;
@@ -739,6 +824,7 @@ declare class ReactServerProvider {
739
824
  REACT_ROOT_ID: string;
740
825
  };
741
826
  protected readonly ROOT_DIV_REGEX: RegExp;
827
+ protected preprocessedTemplate: PreprocessedTemplate | null;
742
828
  readonly onConfigure: _alepha_core14.HookDescriptor<"configure">;
743
829
  get template(): string;
744
830
  protected registerPages(templateLoader: TemplateLoader): Promise<void>;
@@ -751,11 +837,18 @@ declare class ReactServerProvider {
751
837
  protected createRenderFunction(name: string, withIndex?: boolean): (options?: PageDescriptorRenderOptions) => Promise<PageDescriptorRenderResult>;
752
838
  protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
753
839
  renderToHtml(template: string, state: ReactRouterState, hydration?: boolean): string | Redirection;
840
+ protected preprocessTemplate(template: string): PreprocessedTemplate;
754
841
  protected fillTemplate(response: {
755
842
  html: string;
756
843
  }, app: string, script: string): void;
757
844
  }
758
845
  type TemplateLoader = () => Promise<string | undefined>;
846
+ interface PreprocessedTemplate {
847
+ beforeApp: string;
848
+ afterApp: string;
849
+ beforeScript: string;
850
+ afterScript: string;
851
+ }
759
852
  //#endregion
760
853
  //#region src/index.d.ts
761
854
  declare module "alepha" {
package/redis.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as _alepha_core3 from "alepha";
2
- import { Alepha, Static, TNumber, TObject, TOptional, TString } from "alepha";
2
+ import { Alepha, Static } from "alepha";
3
3
  import * as _alepha_logger0 from "alepha/logger";
4
4
  import { RedisClientType, SetOptions, createClient } from "@redis/client";
5
5
 
6
6
  //#region src/providers/RedisProvider.d.ts
7
- declare const envSchema: TObject<{
8
- REDIS_PORT: TNumber;
9
- REDIS_HOST: TString;
10
- REDIS_PASSWORD: TOptional<TString>;
7
+ declare const envSchema: _alepha_core3.TObject<{
8
+ REDIS_PORT: _alepha_core3.TInteger;
9
+ REDIS_HOST: _alepha_core3.TString;
10
+ REDIS_PASSWORD: _alepha_core3.TOptional<_alepha_core3.TString>;
11
11
  }>;
12
12
  declare module "alepha" {
13
13
  interface Env extends Partial<Static<typeof envSchema>> {}
package/security.d.ts CHANGED
@@ -3,19 +3,19 @@ import { Alepha, Descriptor, KIND, Static } from "alepha";
3
3
  import * as _alepha_logger0 from "alepha/logger";
4
4
  import { DateTimeProvider, Duration, DurationLike } from "alepha/datetime";
5
5
  import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
6
- import * as _sinclair_typebox13 from "@sinclair/typebox";
6
+ import * as typebox0 from "typebox";
7
7
  import { JWTVerifyOptions } from "jose/jwt/verify";
8
8
 
9
9
  //#region src/schemas/userAccountInfoSchema.d.ts
10
- declare const userAccountInfoSchema: _sinclair_typebox13.TObject<{
11
- id: _sinclair_typebox13.TString;
12
- name: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
13
- email: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
14
- username: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
15
- picture: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
16
- sessionId: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
17
- organizations: _sinclair_typebox13.TOptional<_sinclair_typebox13.TArray<_sinclair_typebox13.TString>>;
18
- roles: _sinclair_typebox13.TOptional<_sinclair_typebox13.TArray<_sinclair_typebox13.TString>>;
10
+ declare const userAccountInfoSchema: typebox0.TObject<{
11
+ id: typebox0.TString;
12
+ name: typebox0.TOptional<typebox0.TString>;
13
+ email: typebox0.TOptional<typebox0.TString>;
14
+ username: typebox0.TOptional<typebox0.TString>;
15
+ picture: typebox0.TOptional<typebox0.TString>;
16
+ sessionId: typebox0.TOptional<typebox0.TString>;
17
+ organizations: typebox0.TOptional<typebox0.TArray<typebox0.TString>>;
18
+ roles: typebox0.TOptional<typebox0.TArray<typebox0.TString>>;
19
19
  }>;
20
20
  type UserAccount = Static<typeof userAccountInfoSchema>;
21
21
  //#endregion
@@ -41,24 +41,24 @@ interface UserAccountToken extends UserAccount {
41
41
  }
42
42
  //#endregion
43
43
  //#region src/schemas/permissionSchema.d.ts
44
- declare const permissionSchema: _sinclair_typebox13.TObject<{
45
- name: _sinclair_typebox13.TString;
46
- group: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
47
- description: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
48
- method: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
49
- path: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
44
+ declare const permissionSchema: typebox0.TObject<{
45
+ name: typebox0.TString;
46
+ group: typebox0.TOptional<typebox0.TString>;
47
+ description: typebox0.TOptional<typebox0.TString>;
48
+ method: typebox0.TOptional<typebox0.TString>;
49
+ path: typebox0.TOptional<typebox0.TString>;
50
50
  }>;
51
51
  type Permission = Static<typeof permissionSchema>;
52
52
  //#endregion
53
53
  //#region src/schemas/roleSchema.d.ts
54
- declare const roleSchema: _sinclair_typebox13.TObject<{
55
- name: _sinclair_typebox13.TString;
56
- description: _sinclair_typebox13.TOptional<_sinclair_typebox13.TString>;
57
- default: _sinclair_typebox13.TOptional<_sinclair_typebox13.TBoolean>;
58
- permissions: _sinclair_typebox13.TArray<_sinclair_typebox13.TObject<{
59
- name: _sinclair_typebox13.TString;
60
- ownership: _sinclair_typebox13.TOptional<_sinclair_typebox13.TBoolean>;
61
- exclude: _sinclair_typebox13.TOptional<_sinclair_typebox13.TArray<_sinclair_typebox13.TString>>;
54
+ declare const roleSchema: typebox0.TObject<{
55
+ name: typebox0.TString;
56
+ description: typebox0.TOptional<typebox0.TString>;
57
+ default: typebox0.TOptional<typebox0.TBoolean>;
58
+ permissions: typebox0.TArray<typebox0.TObject<{
59
+ name: typebox0.TString;
60
+ ownership: typebox0.TOptional<typebox0.TBoolean>;
61
+ exclude: typebox0.TOptional<typebox0.TArray<typebox0.TString>>;
62
62
  }>>;
63
63
  }>;
64
64
  type Role = Static<typeof roleSchema>;
package/server/cache.d.ts CHANGED
@@ -10,6 +10,7 @@ import { RequestConfigSchema, ServerRequest, ServerRoute } from "alepha/server";
10
10
  declare module "alepha/server" {
11
11
  interface ServerRoute {
12
12
  cache?: ServerRouteCache;
13
+ etag?: string;
13
14
  }
14
15
  interface ActionDescriptor<TConfig extends RequestConfigSchema> {
15
16
  invalidate: () => Promise<void>;
@@ -2,7 +2,7 @@ import * as _alepha_core0 from "alepha";
2
2
  import { Alepha } from "alepha";
3
3
  import * as _alepha_server0 from "alepha/server";
4
4
  import { DateTimeProvider } from "alepha/datetime";
5
- import * as _sinclair_typebox0 from "@sinclair/typebox";
5
+ import * as typebox0 from "typebox";
6
6
 
7
7
  //#region src/providers/ServerHealthProvider.d.ts
8
8
  /**
@@ -14,11 +14,11 @@ declare class ServerHealthProvider {
14
14
  protected readonly time: DateTimeProvider;
15
15
  protected readonly alepha: Alepha;
16
16
  readonly health: _alepha_server0.RouteDescriptor<{
17
- response: _sinclair_typebox0.TObject<{
18
- message: _sinclair_typebox0.TString;
19
- uptime: _sinclair_typebox0.TNumber;
20
- date: _sinclair_typebox0.TString;
21
- ready: _sinclair_typebox0.TBoolean;
17
+ response: typebox0.TObject<{
18
+ message: typebox0.TString;
19
+ uptime: typebox0.TNumber;
20
+ date: typebox0.TString;
21
+ ready: typebox0.TBoolean;
22
22
  }>;
23
23
  }>;
24
24
  }
package/server/links.d.ts CHANGED
@@ -7,26 +7,26 @@ import * as _alepha_logger0 from "alepha/logger";
7
7
  import * as _alepha_retry0 from "alepha/retry";
8
8
  import { ProxyDescriptorOptions, ServerProxyProvider } from "alepha/server/proxy";
9
9
  import { ServiceAccountDescriptor, UserAccountToken } from "alepha/security";
10
- import * as _sinclair_typebox0 from "@sinclair/typebox";
10
+ import * as typebox0 from "typebox";
11
11
 
12
12
  //#region src/schemas/apiLinksResponseSchema.d.ts
13
- declare const apiLinkSchema: _sinclair_typebox0.TObject<{
14
- name: _sinclair_typebox0.TString;
15
- group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
16
- path: _sinclair_typebox0.TString;
17
- method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
18
- requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
19
- service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
13
+ declare const apiLinkSchema: typebox0.TObject<{
14
+ name: typebox0.TString;
15
+ group: typebox0.TOptional<typebox0.TString>;
16
+ path: typebox0.TString;
17
+ method: typebox0.TOptional<typebox0.TString>;
18
+ requestBodyType: typebox0.TOptional<typebox0.TString>;
19
+ service: typebox0.TOptional<typebox0.TString>;
20
20
  }>;
21
- declare const apiLinksResponseSchema: _sinclair_typebox0.TObject<{
22
- prefix: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
23
- links: _sinclair_typebox0.TArray<_sinclair_typebox0.TObject<{
24
- name: _sinclair_typebox0.TString;
25
- group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
26
- path: _sinclair_typebox0.TString;
27
- method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
28
- requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
29
- service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
21
+ declare const apiLinksResponseSchema: typebox0.TObject<{
22
+ prefix: typebox0.TOptional<typebox0.TString>;
23
+ links: typebox0.TArray<typebox0.TObject<{
24
+ name: typebox0.TString;
25
+ group: typebox0.TOptional<typebox0.TString>;
26
+ path: typebox0.TString;
27
+ method: typebox0.TOptional<typebox0.TString>;
28
+ requestBodyType: typebox0.TOptional<typebox0.TString>;
29
+ service: typebox0.TOptional<typebox0.TString>;
30
30
  }>>;
31
31
  }>;
32
32
  type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
@@ -257,15 +257,15 @@ declare class ServerLinksProvider {
257
257
  * This is based on the user's permissions.
258
258
  */
259
259
  readonly links: _alepha_server0.RouteDescriptor<{
260
- response: _sinclair_typebox0.TObject<{
261
- prefix: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
262
- links: _sinclair_typebox0.TArray<_sinclair_typebox0.TObject<{
263
- name: _sinclair_typebox0.TString;
264
- group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
265
- path: _sinclair_typebox0.TString;
266
- method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
267
- requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
268
- service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
260
+ response: typebox0.TObject<{
261
+ prefix: typebox0.TOptional<typebox0.TString>;
262
+ links: typebox0.TArray<typebox0.TObject<{
263
+ name: typebox0.TString;
264
+ group: typebox0.TOptional<typebox0.TString>;
265
+ path: typebox0.TString;
266
+ method: typebox0.TOptional<typebox0.TString>;
267
+ requestBodyType: typebox0.TOptional<typebox0.TString>;
268
+ service: typebox0.TOptional<typebox0.TString>;
269
269
  }>>;
270
270
  }>;
271
271
  }>;
@@ -276,10 +276,10 @@ declare class ServerLinksProvider {
276
276
  * I mean for 150+ links, you got 50ms of serialization time.
277
277
  */
278
278
  readonly schema: _alepha_server0.RouteDescriptor<{
279
- params: _sinclair_typebox0.TObject<{
280
- name: _sinclair_typebox0.TString;
279
+ params: typebox0.TObject<{
280
+ name: typebox0.TString;
281
281
  }>;
282
- response: _sinclair_typebox0.TRecord<_sinclair_typebox0.TString, _sinclair_typebox0.TAny>;
282
+ response: typebox0.TRecord<string, typebox0.TAny>;
283
283
  }>;
284
284
  getSchemaByName(name: string, options?: GetApiLinksOptions): Promise<RequestConfigSchema>;
285
285
  /**