@alepha/react 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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@alepha/core');
4
- var useRouterState = require('./useRouterState-C2uo0jXu.cjs');
4
+ var useRouterState = require('./useRouterState-BTmuHxkM.cjs');
5
5
  var client = require('react-dom/client');
6
6
  require('react/jsx-runtime');
7
7
  require('react');
@@ -45,24 +45,25 @@ class ReactBrowserRenderer {
45
45
  });
46
46
  }
47
47
 
48
- class ReactModule {
49
- alepha = core.$inject(core.Alepha);
50
- constructor() {
51
- this.alepha.with(useRouterState.PageDescriptorProvider).with(useRouterState.ReactBrowserProvider).with(useRouterState.BrowserRouterProvider).with(ReactBrowserRenderer);
52
- }
48
+ class AlephaReact {
49
+ name = "alepha.react";
50
+ $services = (alepha) => alepha.with(useRouterState.PageDescriptorProvider).with(useRouterState.ReactBrowserProvider).with(useRouterState.BrowserRouterProvider).with(ReactBrowserRenderer);
53
51
  }
54
- core.__bind(useRouterState.$page, ReactModule);
52
+ core.__bind(useRouterState.$page, AlephaReact);
55
53
 
56
54
  exports.$page = useRouterState.$page;
55
+ exports.BrowserRouterProvider = useRouterState.BrowserRouterProvider;
57
56
  exports.ClientOnly = useRouterState.ClientOnly;
58
57
  exports.ErrorBoundary = useRouterState.ErrorBoundary;
59
58
  exports.Link = useRouterState.Link;
60
59
  exports.NestedView = useRouterState.NestedView;
60
+ exports.PageDescriptorProvider = useRouterState.PageDescriptorProvider;
61
61
  exports.ReactBrowserProvider = useRouterState.ReactBrowserProvider;
62
62
  exports.RedirectionError = useRouterState.RedirectionError;
63
63
  exports.RouterContext = useRouterState.RouterContext;
64
64
  exports.RouterHookApi = useRouterState.RouterHookApi;
65
65
  exports.RouterLayerContext = useRouterState.RouterLayerContext;
66
+ exports.isPageRoute = useRouterState.isPageRoute;
66
67
  exports.useActive = useRouterState.useActive;
67
68
  exports.useAlepha = useRouterState.useAlepha;
68
69
  exports.useClient = useRouterState.useClient;
@@ -71,4 +72,4 @@ exports.useQueryParams = useRouterState.useQueryParams;
71
72
  exports.useRouter = useRouterState.useRouter;
72
73
  exports.useRouterEvents = useRouterState.useRouterEvents;
73
74
  exports.useRouterState = useRouterState.useRouterState;
74
- exports.ReactModule = ReactModule;
75
+ exports.AlephaReact = AlephaReact;
@@ -1,6 +1,6 @@
1
- import { t, $inject, $logger, $hook, __bind, Alepha } from '@alepha/core';
2
- import { l as ReactBrowserProvider, B as BrowserRouterProvider, $ as $page, P as PageDescriptorProvider } from './useRouterState-D5__ZcUV.js';
3
- export { C as ClientOnly, E as ErrorBoundary, L as Link, N as NestedView, R as RedirectionError, a as RouterContext, c as RouterHookApi, b as RouterLayerContext, u as useActive, d as useAlepha, e as useClient, f as useInject, g as useQueryParams, h as useRouter, i as useRouterEvents, j as useRouterState } from './useRouterState-D5__ZcUV.js';
1
+ import { t, $inject, $logger, $hook, __bind } from '@alepha/core';
2
+ import { l as ReactBrowserProvider, B as BrowserRouterProvider, $ as $page, P as PageDescriptorProvider } from './useRouterState-cCucJfTC.js';
3
+ export { C as ClientOnly, E as ErrorBoundary, L as Link, N as NestedView, b as RedirectionError, R as RouterContext, c as RouterHookApi, a as RouterLayerContext, k as isPageRoute, u as useActive, d as useAlepha, e as useClient, f as useInject, g as useQueryParams, h as useRouter, i as useRouterEvents, j as useRouterState } from './useRouterState-cCucJfTC.js';
4
4
  import { hydrateRoot, createRoot } from 'react-dom/client';
5
5
  import 'react/jsx-runtime';
6
6
  import 'react';
@@ -44,12 +44,10 @@ class ReactBrowserRenderer {
44
44
  });
45
45
  }
46
46
 
47
- class ReactModule {
48
- alepha = $inject(Alepha);
49
- constructor() {
50
- this.alepha.with(PageDescriptorProvider).with(ReactBrowserProvider).with(BrowserRouterProvider).with(ReactBrowserRenderer);
51
- }
47
+ class AlephaReact {
48
+ name = "alepha.react";
49
+ $services = (alepha) => alepha.with(PageDescriptorProvider).with(ReactBrowserProvider).with(BrowserRouterProvider).with(ReactBrowserRenderer);
52
50
  }
53
- __bind($page, ReactModule);
51
+ __bind($page, AlephaReact);
54
52
 
55
- export { $page, ReactBrowserProvider, ReactModule };
53
+ export { $page, AlephaReact, BrowserRouterProvider, PageDescriptorProvider, ReactBrowserProvider };
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  var core = require('@alepha/core');
4
4
  var server = require('@alepha/server');
5
5
  var serverCache = require('@alepha/server-cache');
6
- var useRouterState = require('./useRouterState-C2uo0jXu.cjs');
6
+ var useRouterState = require('./useRouterState-BTmuHxkM.cjs');
7
7
  var node_fs = require('node:fs');
8
8
  var node_path = require('node:path');
9
9
  var serverStatic = require('@alepha/server-static');
@@ -354,13 +354,11 @@ class ReactServerProvider {
354
354
  }
355
355
  }
356
356
 
357
- class ReactModule {
358
- alepha = core.$inject(core.Alepha);
359
- constructor() {
360
- this.alepha.with(server.ServerModule).with(serverCache.ServerCacheModule).with(server.ServerLinksProvider).with(useRouterState.PageDescriptorProvider).with(ReactServerProvider);
361
- }
357
+ class AlephaReact {
358
+ name = "alepha.react";
359
+ $services = (alepha) => alepha.with(server.AlephaServer).with(serverCache.AlephaServerCache).with(ReactServerProvider).with(useRouterState.PageDescriptorProvider);
362
360
  }
363
- core.__bind(useRouterState.$page, ReactModule);
361
+ core.__bind(useRouterState.$page, AlephaReact);
364
362
 
365
363
  exports.$page = useRouterState.$page;
366
364
  exports.ClientOnly = useRouterState.ClientOnly;
@@ -382,6 +380,5 @@ exports.useQueryParams = useRouterState.useQueryParams;
382
380
  exports.useRouter = useRouterState.useRouter;
383
381
  exports.useRouterEvents = useRouterState.useRouterEvents;
384
382
  exports.useRouterState = useRouterState.useRouterState;
385
- exports.ReactModule = ReactModule;
383
+ exports.AlephaReact = AlephaReact;
386
384
  exports.ReactServerProvider = ReactServerProvider;
387
- exports.envSchema = envSchema;
package/dist/index.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/core" {
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/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { t, $logger, $inject, Alepha, $hook, OPTIONS, __bind } from '@alepha/core';
2
- import { ServerRouterProvider, ServerTimingProvider, ServerLinksProvider, apiLinksResponseSchema, ServerModule } from '@alepha/server';
3
- import { ServerCacheModule } from '@alepha/server-cache';
4
- import { P as PageDescriptorProvider, $ as $page } from './useRouterState-D5__ZcUV.js';
5
- export { C as ClientOnly, E as ErrorBoundary, L as Link, N as NestedView, l as ReactBrowserProvider, R as RedirectionError, a as RouterContext, c as RouterHookApi, b as RouterLayerContext, k as isPageRoute, u as useActive, d as useAlepha, e as useClient, f as useInject, g as useQueryParams, h as useRouter, i as useRouterEvents, j as useRouterState } from './useRouterState-D5__ZcUV.js';
2
+ import { ServerRouterProvider, ServerTimingProvider, ServerLinksProvider, apiLinksResponseSchema, AlephaServer } from '@alepha/server';
3
+ import { AlephaServerCache } from '@alepha/server-cache';
4
+ import { P as PageDescriptorProvider, $ as $page } from './useRouterState-cCucJfTC.js';
5
+ export { C as ClientOnly, E as ErrorBoundary, L as Link, N as NestedView, l as ReactBrowserProvider, b as RedirectionError, R as RouterContext, c as RouterHookApi, a as RouterLayerContext, k as isPageRoute, u as useActive, d as useAlepha, e as useClient, f as useInject, g as useQueryParams, h as useRouter, i as useRouterEvents, j as useRouterState } from './useRouterState-cCucJfTC.js';
6
6
  import { existsSync } from 'node:fs';
7
7
  import { join } from 'node:path';
8
8
  import { ServerStaticProvider } from '@alepha/server-static';
@@ -353,12 +353,10 @@ class ReactServerProvider {
353
353
  }
354
354
  }
355
355
 
356
- class ReactModule {
357
- alepha = $inject(Alepha);
358
- constructor() {
359
- this.alepha.with(ServerModule).with(ServerCacheModule).with(ServerLinksProvider).with(PageDescriptorProvider).with(ReactServerProvider);
360
- }
356
+ class AlephaReact {
357
+ name = "alepha.react";
358
+ $services = (alepha) => alepha.with(AlephaServer).with(AlephaServerCache).with(ReactServerProvider).with(PageDescriptorProvider);
361
359
  }
362
- __bind($page, ReactModule);
360
+ __bind($page, AlephaReact);
363
361
 
364
- export { $page, PageDescriptorProvider, ReactModule, ReactServerProvider, envSchema };
362
+ export { $page, AlephaReact, PageDescriptorProvider, ReactServerProvider };
@@ -279,7 +279,7 @@ const NestedView = (props) => {
279
279
  };
280
280
 
281
281
  function NotFoundPage() {
282
- return /* @__PURE__ */ jsxRuntime.jsxs(
282
+ return /* @__PURE__ */ jsxRuntime.jsx(
283
283
  "div",
284
284
  {
285
285
  style: {
@@ -292,21 +292,7 @@ function NotFoundPage() {
292
292
  fontFamily: "sans-serif",
293
293
  padding: "1rem"
294
294
  },
295
- children: [
296
- /* @__PURE__ */ jsxRuntime.jsx("h1", { style: { fontSize: "1rem", marginBottom: "0.5rem" }, children: "This page does not exist" }),
297
- /* @__PURE__ */ jsxRuntime.jsx(
298
- "a",
299
- {
300
- href: "/",
301
- style: {
302
- fontSize: "0.7rem",
303
- color: "#007bff",
304
- textDecoration: "none"
305
- },
306
- children: "\u2190 Back to home"
307
- }
308
- )
309
- ]
295
+ children: /* @__PURE__ */ jsxRuntime.jsx("h1", { style: { fontSize: "1rem", marginBottom: "0.5rem" }, children: "This page does not exist" })
310
296
  }
311
297
  );
312
298
  }
@@ -277,7 +277,7 @@ const NestedView = (props) => {
277
277
  };
278
278
 
279
279
  function NotFoundPage() {
280
- return /* @__PURE__ */ jsxs(
280
+ return /* @__PURE__ */ jsx(
281
281
  "div",
282
282
  {
283
283
  style: {
@@ -290,21 +290,7 @@ function NotFoundPage() {
290
290
  fontFamily: "sans-serif",
291
291
  padding: "1rem"
292
292
  },
293
- children: [
294
- /* @__PURE__ */ jsx("h1", { style: { fontSize: "1rem", marginBottom: "0.5rem" }, children: "This page does not exist" }),
295
- /* @__PURE__ */ jsx(
296
- "a",
297
- {
298
- href: "/",
299
- style: {
300
- fontSize: "0.7rem",
301
- color: "#007bff",
302
- textDecoration: "none"
303
- },
304
- children: "\u2190 Back to home"
305
- }
306
- )
307
- ]
293
+ children: /* @__PURE__ */ jsx("h1", { style: { fontSize: "1rem", marginBottom: "0.5rem" }, children: "This page does not exist" })
308
294
  }
309
295
  );
310
296
  }
@@ -1172,4 +1158,4 @@ const useRouterState = () => {
1172
1158
  return state;
1173
1159
  };
1174
1160
 
1175
- export { $page as $, BrowserRouterProvider as B, ClientOnly as C, ErrorBoundary as E, Link as L, NestedView as N, PageDescriptorProvider as P, RedirectionError as R, RouterContext as a, RouterLayerContext as b, RouterHookApi as c, useAlepha as d, useClient as e, useInject as f, useQueryParams as g, useRouter as h, useRouterEvents as i, useRouterState as j, isPageRoute as k, ReactBrowserProvider as l, useActive as u };
1161
+ export { $page as $, BrowserRouterProvider as B, ClientOnly as C, ErrorBoundary as E, Link as L, NestedView as N, PageDescriptorProvider as P, RouterContext as R, RouterLayerContext as a, RedirectionError as b, RouterHookApi as c, useAlepha as d, useClient as e, useInject as f, useQueryParams as g, useRouter as h, useRouterEvents as i, useRouterState as j, isPageRoute as k, ReactBrowserProvider as l, useActive as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alepha/react",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -13,11 +13,11 @@
13
13
  "src"
14
14
  ],
15
15
  "dependencies": {
16
- "@alepha/core": "0.7.3",
17
- "@alepha/router": "0.7.3",
18
- "@alepha/server": "0.7.3",
19
- "@alepha/server-cache": "0.7.3",
20
- "@alepha/server-static": "0.7.3",
16
+ "@alepha/core": "0.7.5",
17
+ "@alepha/router": "0.7.5",
18
+ "@alepha/server": "0.7.5",
19
+ "@alepha/server-cache": "0.7.5",
20
+ "@alepha/server-static": "0.7.5",
21
21
  "react-dom": "^19.1.0"
22
22
  },
23
23
  "devDependencies": {
@@ -15,16 +15,6 @@ export default function NotFoundPage() {
15
15
  <h1 style={{ fontSize: "1rem", marginBottom: "0.5rem" }}>
16
16
  This page does not exist
17
17
  </h1>
18
- <a
19
- href="/"
20
- style={{
21
- fontSize: "0.7rem",
22
- color: "#007bff",
23
- textDecoration: "none",
24
- }}
25
- >
26
- ← Back to home
27
- </a>
28
18
  </div>
29
19
  );
30
20
  }
@@ -7,7 +7,8 @@ import {
7
7
  type Static,
8
8
  type TSchema,
9
9
  } from "@alepha/core";
10
- import type { ServerRequest, ServerRoute } from "@alepha/server";
10
+ import type { ServerRequest } from "@alepha/server";
11
+ import type { ServerRouteCache } from "@alepha/server-cache";
11
12
  import type { FC, ReactNode } from "react";
12
13
  import type { ClientOnlyProps } from "../components/ClientOnly.tsx";
13
14
  import type { PageReactContext } from "../providers/PageDescriptorProvider.ts";
@@ -27,7 +28,7 @@ export interface PageDescriptorOptions<
27
28
  TConfig extends PageConfigSchema = PageConfigSchema,
28
29
  TProps extends object = TPropsDefault,
29
30
  TPropsParent extends object = TPropsParentDefault,
30
- > extends Pick<ServerRoute, "cache"> {
31
+ > {
31
32
  /**
32
33
  * Name your page.
33
34
  *
@@ -117,6 +118,8 @@ export interface PageDescriptorOptions<
117
118
  client?: boolean | ClientOnlyProps;
118
119
 
119
120
  afterHandler?: (request: ServerRequest) => any;
121
+
122
+ cache?: ServerRouteCache;
120
123
  }
121
124
 
122
125
  export interface PageDescriptor<
@@ -1,23 +1,27 @@
1
- import { __bind, $inject, Alepha } from "@alepha/core";
1
+ import { __bind, type Alepha, type Module } from "@alepha/core";
2
2
  import { $page } from "./descriptors/$page.ts";
3
3
  import { BrowserRouterProvider } from "./providers/BrowserRouterProvider.ts";
4
4
  import { PageDescriptorProvider } from "./providers/PageDescriptorProvider.ts";
5
5
  import { ReactBrowserProvider } from "./providers/ReactBrowserProvider.ts";
6
6
  import { ReactBrowserRenderer } from "./providers/ReactBrowserRenderer.ts";
7
7
 
8
- export * from "./index.shared";
8
+ // ---------------------------------------------------------------------------------------------------------------------
9
+
10
+ export * from "./index.shared.ts";
11
+ export * from "./providers/BrowserRouterProvider.ts";
12
+ export * from "./providers/PageDescriptorProvider.ts";
9
13
  export * from "./providers/ReactBrowserProvider.ts";
10
14
 
11
- export class ReactModule {
12
- protected readonly alepha = $inject(Alepha);
15
+ // ---------------------------------------------------------------------------------------------------------------------
13
16
 
14
- constructor() {
15
- this.alepha //
17
+ export class AlephaReact implements Module {
18
+ public readonly name = "alepha.react";
19
+ public readonly $services = (alepha: Alepha) =>
20
+ alepha
16
21
  .with(PageDescriptorProvider)
17
22
  .with(ReactBrowserProvider)
18
23
  .with(BrowserRouterProvider)
19
24
  .with(ReactBrowserRenderer);
20
- }
21
25
  }
22
26
 
23
- __bind($page, ReactModule);
27
+ __bind($page, AlephaReact);
@@ -3,14 +3,10 @@ export { default as ErrorBoundary } from "./components/ErrorBoundary.tsx";
3
3
  export * from "./components/ErrorViewer.tsx";
4
4
  export { default as Link } from "./components/Link.tsx";
5
5
  export { default as NestedView } from "./components/NestedView.tsx";
6
-
7
6
  export * from "./contexts/RouterContext.ts";
8
7
  export * from "./contexts/RouterLayerContext.ts";
9
-
10
8
  export * from "./descriptors/$page.ts";
11
-
12
9
  export * from "./errors/RedirectionError.ts";
13
-
14
10
  export * from "./hooks/RouterHookApi.ts";
15
11
  export * from "./hooks/useActive.ts";
16
12
  export * from "./hooks/useAlepha.ts";
package/src/index.ts CHANGED
@@ -1,10 +1,6 @@
1
- import { __bind, $inject, Alepha } from "@alepha/core";
2
- import {
3
- ServerLinksProvider,
4
- ServerModule,
5
- type ServerRequest,
6
- } from "@alepha/server";
7
- import { ServerCacheModule } from "@alepha/server-cache";
1
+ import { __bind, type Alepha, type Module } from "@alepha/core";
2
+ import { AlephaServer, type ServerRequest } from "@alepha/server";
3
+ import { AlephaServerCache } from "@alepha/server-cache";
8
4
  import { $page } from "./descriptors/$page.ts";
9
5
  import {
10
6
  PageDescriptorProvider,
@@ -15,13 +11,15 @@ import {
15
11
  import type { ReactHydrationState } from "./providers/ReactBrowserProvider.ts";
16
12
  import { ReactServerProvider } from "./providers/ReactServerProvider.ts";
17
13
 
18
- export { default as NestedView } from "./components/NestedView.tsx";
19
- export * from "./errors/RedirectionError.ts";
14
+ // ---------------------------------------------------------------------------------------------------------------------
15
+
20
16
  export * from "./index.shared.ts";
21
17
  export * from "./providers/PageDescriptorProvider.ts";
22
18
  export * from "./providers/ReactBrowserProvider.ts";
23
19
  export * from "./providers/ReactServerProvider.ts";
24
20
 
21
+ // ---------------------------------------------------------------------------------------------------------------------
22
+
25
23
  declare module "@alepha/core" {
26
24
  interface Hooks {
27
25
  "react:browser:render": {
@@ -52,17 +50,25 @@ declare module "@alepha/core" {
52
50
  }
53
51
  }
54
52
 
55
- export class ReactModule {
56
- protected readonly alepha = $inject(Alepha);
53
+ // ---------------------------------------------------------------------------------------------------------------------
57
54
 
58
- constructor() {
59
- this.alepha //
60
- .with(ServerModule)
61
- .with(ServerCacheModule)
62
- .with(ServerLinksProvider)
63
- .with(PageDescriptorProvider)
64
- .with(ReactServerProvider);
65
- }
55
+ /**
56
+ * Alepha React Module
57
+ *
58
+ * Alepha React Module contains a router for client-side navigation and server-side rendering.
59
+ * Routes can be defined using the `$page` descriptor.
60
+ *
61
+ * @see {@link $page}
62
+ * @module alepha.react
63
+ */
64
+ export class AlephaReact implements Module {
65
+ public readonly name = "alepha.react";
66
+ public readonly $services = (alepha: Alepha) =>
67
+ alepha
68
+ .with(AlephaServer)
69
+ .with(AlephaServerCache)
70
+ .with(ReactServerProvider)
71
+ .with(PageDescriptorProvider);
66
72
  }
67
73
 
68
- __bind($page, ReactModule);
74
+ __bind($page, AlephaReact);
@@ -17,6 +17,7 @@ declare module "@alepha/core" {
17
17
  interface Env extends Partial<Static<typeof envSchema>> {}
18
18
  }
19
19
 
20
+ // TODO: move to ReactBrowserProvider when it will be removed from server-side imports
20
21
  export class ReactBrowserRenderer {
21
22
  protected readonly browserProvider = $inject(ReactBrowserProvider);
22
23
  protected readonly browserRouterProvider = $inject(BrowserRouterProvider);
@@ -29,7 +29,7 @@ import {
29
29
  import type { ReactHydrationState } from "./ReactBrowserProvider.ts";
30
30
  import { ServerHeadProvider } from "./ServerHeadProvider.ts";
31
31
 
32
- export const envSchema = t.object({
32
+ const envSchema = t.object({
33
33
  REACT_SERVER_DIST: t.string({ default: "public" }),
34
34
  REACT_SERVER_PREFIX: t.string({ default: "" }),
35
35
  REACT_SSR_ENABLED: t.optional(t.boolean()),