@alepha/react 0.6.2 → 0.6.3

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/dist/index.d.ts CHANGED
@@ -1,15 +1,12 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { EventEmitter, Alepha, Static as Static$1, TSchema as TSchema$1, KIND, Async, Class, TObject as TObject$1 } from '@alepha/core';
2
+ import { Alepha, EventEmitter, Static as Static$1, TSchema as TSchema$1, KIND, Async, Class, TObject as TObject$1 } from '@alepha/core';
3
+ import { HttpClientLink, HttpClient, ServerRouterProvider, ServerHandler, ServerRequest } from '@alepha/server';
3
4
  import * as react from 'react';
4
5
  import react__default, { ReactNode, FC, AnchorHTMLAttributes } from 'react';
5
- import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import { UserAccountToken } from '@alepha/security';
7
- import * as _alepha_server from '@alepha/server';
8
- import { HttpLink, ServerCookieProvider, CookieManager, HttpClient, ServerProvider, ServeDescriptorOptions, RouteObject } from '@alepha/server';
9
6
  import { Root } from 'react-dom/client';
10
- import { MatchFunction, ParamData } from 'path-to-regexp';
11
- import { Configuration } from 'openid-client';
12
- import { CheerioAPI } from 'cheerio';
7
+ import { RouterProvider, Route } from '@alepha/router';
8
+ import * as react_jsx_runtime from 'react/jsx-runtime';
9
+ import { ServerStaticProvider } from '@alepha/server-static';
13
10
 
14
11
  /** Symbol key applied to readonly types */
15
12
  declare const ReadonlyKind: unique symbol;
@@ -52,19 +49,6 @@ interface TBoolean extends TSchema {
52
49
  type: 'boolean';
53
50
  }
54
51
 
55
- interface NumberOptions extends SchemaOptions {
56
- exclusiveMaximum?: number;
57
- exclusiveMinimum?: number;
58
- maximum?: number;
59
- minimum?: number;
60
- multipleOf?: number;
61
- }
62
- interface TNumber extends TSchema, NumberOptions {
63
- [Kind]: 'Number';
64
- static: number;
65
- type: 'number';
66
- }
67
-
68
52
  type TOptional<T extends TSchema> = T & {
69
53
  [OptionalKind]: 'Optional';
70
54
  };
@@ -141,489 +125,53 @@ interface TSchema extends TKind, SchemaOptions {
141
125
  static: unknown;
142
126
  }
143
127
 
144
- interface NestedViewProps {
145
- children?: ReactNode;
146
- }
147
- /**
148
- * Nested view component
149
- *
150
- * @param props
151
- * @constructor
152
- */
153
- declare const NestedView: (props: NestedViewProps) => string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
154
-
155
- declare class Router extends EventEmitter<RouterEvents> {
156
- protected readonly log: _alepha_core.Logger;
157
- protected readonly alepha: Alepha;
158
- protected readonly pages: PageRoute[];
159
- protected notFoundPageRoute?: PageRoute;
160
- /**
161
- * Get the page by name.
162
- *
163
- * @param name - Page name
164
- * @return PageRoute
165
- */
166
- page(name: string): PageRoute;
167
- /**
168
- *
169
- */
170
- root(state: RouterState, context?: PageContext): ReactNode;
171
- /**
172
- *
173
- * @param url
174
- * @param options
175
- */
176
- render(url: string, options?: RouterRenderOptions): Promise<RouterRenderResult>;
177
- /**
178
- *
179
- * @param url
180
- * @param options
181
- * @param context
182
- * @protected
183
- */
184
- match(url: string, options?: RouterMatchOptions, context?: RouterRenderContext): Promise<Layer[]>;
185
- /**
186
- * Create layers for the given route.
187
- *
188
- * @param url
189
- * @param route
190
- * @param params
191
- * @param query
192
- * @param previous
193
- * @param args
194
- * @param renderContext
195
- * @protected
196
- */
197
- createLayers(url: string, route: PageRoute, params?: Record<string, any>, query?: Record<string, string>, previous?: PreviousLayerData[], args?: PageContext, renderContext?: RouterRenderContext): Promise<Layer[]>;
198
- /**
199
- *
200
- * @param route
201
- * @protected
202
- */
203
- protected getErrorHandler(route: PageRoute): react.FC<{
204
- error: Error;
205
- url: string;
206
- }> | undefined;
207
- /**
208
- *
209
- * @param page
210
- * @param props
211
- * @protected
212
- */
213
- protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
214
- /**
215
- * Merge the render context with the page context.
216
- *
217
- * @param page
218
- * @param ctx
219
- * @param props
220
- * @protected
221
- */
222
- protected mergeRenderContext(page: PageRoute, ctx: RouterRenderContext, props: Record<string, any>): void;
223
- /**
224
- *
225
- * @param e
226
- * @protected
227
- */
228
- protected renderError(e: Error): ReactNode;
229
- /**
230
- * Render an empty view.
231
- *
232
- * @protected
233
- */
234
- protected renderEmptyView(): ReactNode;
235
- /**
236
- * Create a valid href for the given page.
237
- * @param page
238
- * @param params
239
- */
240
- href(page: {
241
- options: {
242
- name?: string;
243
- };
244
- }, params?: Record<string, any>): string;
245
- /**
246
- *
247
- * @param index
248
- * @param path
249
- * @param view
250
- * @protected
251
- */
252
- protected renderView(index: number, path: string, view?: ReactNode): ReactNode;
253
- /**
254
- *
255
- * @param entry
256
- */
257
- add(entry: PageRouteEntry): void;
258
- /**
259
- * Create a match function for the given page.
260
- *
261
- * @param page
262
- * @protected
263
- */
264
- protected createMatchFunction(page: PageRoute): {
265
- exec: MatchFunction<ParamData>;
266
- path: string;
267
- } | undefined;
268
- /**
269
- *
270
- */
271
- empty(): boolean;
272
- /**
273
- *
274
- * @protected
275
- */
276
- protected _next: number;
277
- /**
278
- *
279
- * @protected
280
- */
281
- protected nextId(): string;
282
- }
283
- interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
284
- /**
285
- *
286
- */
287
- name?: string;
288
- /**
289
- *
290
- */
291
- match?: {
292
- /**
293
- *
294
- */
295
- exec: MatchFunction<ParamData>;
296
- /**
297
- *
298
- */
299
- path: string;
300
- };
301
- /**
302
- *
303
- */
304
- children?: PageRouteEntry[];
305
- /**
306
- *
307
- */
308
- parent?: PageRoute;
309
- }
310
- interface PageRoute extends PageRouteEntry {
311
- /**
312
- *
313
- */
314
- name: string;
315
- /**
316
- *
317
- */
318
- parent?: PageRoute;
319
- }
320
- interface Layer {
321
- /**
322
- *
323
- */
324
- config?: {
325
- /**
326
- *
327
- */
328
- query?: Record<string, any>;
329
- /**
330
- *
331
- */
332
- params?: Record<string, any>;
333
- /**
334
- *
335
- */
336
- context?: Record<string, any>;
337
- };
338
- /**
339
- *
340
- */
341
- name: string;
342
- /**
343
- *
344
- */
345
- props?: Record<string, any>;
346
- /**
347
- *
348
- */
349
- error?: Error;
350
- /**
351
- *
352
- */
353
- part?: string;
354
- /**
355
- *
356
- */
357
- element: ReactNode;
358
- /**
359
- *
360
- */
361
- index: number;
362
- /**
363
- *
364
- */
365
- path: string;
366
- }
367
- /**
368
- *
369
- */
370
- type PreviousLayerData = Omit<Layer, "element">;
371
- interface AnchorProps {
372
- /**
373
- *
374
- */
375
- href?: string;
376
- /**
377
- *
378
- * @param ev
379
- */
380
- onClick?: (ev: any) => any;
381
- }
382
- interface RouterMatchOptions {
383
- /**
384
- *
385
- */
386
- previous?: PreviousLayerData[];
387
- /**
388
- *
389
- */
390
- args?: PageContext;
391
- }
392
- interface RouterEvents {
393
- /**
394
- *
395
- */
396
- begin: undefined;
397
- /**
398
- *
399
- */
400
- success: undefined;
401
- /**
402
- *
403
- */
404
- error: Error;
405
- /**
406
- *
407
- */
408
- end: RouterState;
409
- }
410
- interface RouterState {
411
- /**
412
- *
413
- */
414
- pathname: string;
415
- /**
416
- *
417
- */
418
- search: string;
419
- /**
420
- *
421
- */
422
- layers: Array<Layer>;
423
- /**
424
- *
425
- */
426
- context: RouterRenderContext;
427
- }
428
- interface RouterRenderContext {
429
- /**
430
- *
431
- */
432
- head?: RouterRenderHeadContext;
433
- }
434
- interface RouterRenderOptions extends RouterMatchOptions {
435
- /**
436
- * State to update.
437
- */
438
- state?: RouterState;
439
- }
440
- interface RouterStackItem {
441
- /**
442
- *
443
- */
444
- route: PageRoute;
445
- /**
446
- *
447
- */
448
- config?: Record<string, any>;
449
- /**
450
- *
451
- */
452
- props?: Record<string, any>;
453
- /**
454
- *
455
- */
456
- error?: Error;
457
- }
458
- interface RouterRenderHeadContext {
459
- /**
460
- *
461
- */
128
+ interface Head$1 {
462
129
  title?: string;
463
- /**
464
- *
465
- */
466
- titleSeparator?: string;
467
- /**
468
- * Add html attributes to the <html> tag.
469
- */
470
130
  htmlAttributes?: Record<string, string>;
471
- /**
472
- * Add html attributes to the <body> tag.
473
- */
474
131
  bodyAttributes?: Record<string, string>;
475
- /**
476
- *
477
- */
478
132
  meta?: Array<{
479
133
  name: string;
480
134
  content: string;
481
135
  }>;
482
136
  }
483
- interface RouterRenderResult {
484
- /**
485
- *
486
- */
487
- element: ReactNode;
488
- /**
489
- *
490
- */
491
- layers: Layer[];
492
- /**
493
- *
494
- */
495
- redirect?: string;
496
- /**
497
- *
498
- */
499
- context: RouterRenderContext;
137
+ declare class ServerHeadProvider {
138
+ renderHead(template: string, head: Head$1): string;
139
+ mergeAttributes(existing: string, attrs: Record<string, string>): string;
140
+ parseAttributes(attrStr: string): Record<string, string>;
141
+ escapeHtml(str: string): string;
500
142
  }
501
143
 
502
- declare class ReactAuthProvider {
503
- protected readonly log: _alepha_core.Logger;
504
- protected readonly alepha: Alepha;
505
- protected readonly serverCookieProvider: ServerCookieProvider;
506
- protected authProviders: AuthProvider[];
507
- protected readonly authorizationCode: _alepha_server.CookieDescriptor<TObject<{
508
- codeVerifier: TOptional<TString>;
509
- redirectUri: TOptional<TString>;
510
- }>>;
511
- protected readonly tokens: _alepha_server.CookieDescriptor<TObject<{
512
- access_token: TOptional<TString>;
513
- expires_in: TOptional<TNumber>;
514
- refresh_token: TOptional<TString>;
515
- id_token: TOptional<TString>;
516
- scope: TOptional<TString>;
517
- issued_at: TOptional<TNumber>;
518
- }>>;
519
- readonly user: _alepha_server.CookieDescriptor<TObject<{
520
- id: TString;
521
- name: TOptional<TString>;
522
- email: TOptional<TString>;
523
- }>>;
524
- protected readonly configure: _alepha_core.HookDescriptor<"configure">;
525
- /**
526
- * Configure Fastify to forward Session Access Token to Header Authorization.
527
- */
528
- protected readonly onRequest: _alepha_core.HookDescriptor<"server:onRequest">;
529
- /**
530
- *
531
- * @param cookies
532
- * @protected
533
- */
534
- protected refresh(cookies: CookieManager): Promise<SessionTokens | undefined>;
535
- /**
536
- *
537
- */
538
- readonly login: _alepha_server.RouteDescriptor<{
539
- query: TObject<{
540
- redirect: TOptional<TString>;
541
- provider: TOptional<TString>;
542
- }>;
543
- }, false>;
544
- /**
545
- *
546
- */
547
- readonly callback: _alepha_server.RouteDescriptor<{
548
- query: TObject<{
549
- provider: TOptional<TString>;
550
- }>;
551
- }, false>;
552
- /**
553
- *
554
- * @param accessToken
555
- * @protected
556
- */
557
- protected userFromAccessToken(accessToken: string): {
558
- id: any;
559
- name: any;
560
- email: any;
561
- } | undefined;
562
- /**
563
- *
564
- */
565
- readonly logout: _alepha_server.RouteDescriptor<{
566
- query: TObject<{
567
- redirect: TOptional<TString>;
568
- provider: TOptional<TString>;
569
- }>;
570
- }, false>;
571
- /**
572
- *
573
- * @param name
574
- * @protected
575
- */
576
- protected provider(name?: string): AuthProvider;
577
- /**
578
- *
579
- * @param file
580
- * @protected
581
- */
582
- protected isViteFile(file: string): boolean;
583
- }
584
- interface SessionTokens {
585
- access_token?: string;
586
- expires_in?: number;
587
- refresh_token?: string;
588
- id_token?: string;
589
- scope?: string;
590
- issued_at?: number;
591
- }
592
- interface SessionAuthorizationCode {
593
- codeVerifier?: string;
594
- redirectUri?: string;
595
- nonce?: string;
596
- max_age?: number;
597
- state?: string;
598
- }
599
- interface AuthProvider {
600
- name: string;
601
- redirectUri: string;
602
- client: Configuration;
144
+ declare class BrowserHeadProvider {
145
+ renderHead(document: Document, head: Head$1): void;
603
146
  }
604
- interface ReactUser {
605
- id: string;
606
- name?: string;
607
- email?: string;
147
+
148
+ interface BrowserRoute extends Route {
149
+ page: PageRoute;
608
150
  }
609
- interface ReactHydrationState {
610
- user?: ReactUser;
611
- auth?: "server" | "client";
612
- layers?: PreviousLayerData[];
613
- links?: HttpLink[];
151
+ declare class BrowserRouterProvider extends RouterProvider<BrowserRoute> {
152
+ protected readonly log: _alepha_core.Logger;
153
+ protected readonly alepha: Alepha;
154
+ protected readonly pageDescriptorProvider: PageDescriptorProvider;
155
+ readonly events: EventEmitter<RouterEvents>;
156
+ add(entry: PageRouteEntry): void;
157
+ protected readonly configure: _alepha_core.HookDescriptor<"configure">;
158
+ transition(url: URL, options?: TransitionOptions): Promise<RouterRenderResult>;
159
+ root(state: RouterState, context?: PageReactContext): ReactNode;
614
160
  }
615
161
 
616
- declare const envSchema$2: _alepha_core.TObject<{
162
+ declare const envSchema$1: _alepha_core.TObject<{
617
163
  REACT_ROOT_ID: TString;
618
164
  }>;
619
165
  declare module "@alepha/core" {
620
- interface Env extends Partial<Static$1<typeof envSchema$2>> {
166
+ interface Env extends Partial<Static$1<typeof envSchema$1>> {
621
167
  }
622
168
  }
623
169
  declare class ReactBrowserProvider {
624
170
  protected readonly log: _alepha_core.Logger;
625
171
  protected readonly client: HttpClient;
626
- protected readonly router: Router;
172
+ protected readonly alepha: Alepha;
173
+ protected readonly router: BrowserRouterProvider;
174
+ protected readonly headProvider: BrowserHeadProvider;
627
175
  protected readonly env: {
628
176
  REACT_ROOT_ID: string;
629
177
  };
@@ -632,22 +180,9 @@ declare class ReactBrowserProvider {
632
180
  to: string;
633
181
  };
634
182
  state: RouterState;
635
- /**
636
- *
637
- */
638
183
  get document(): Document;
639
- /**
640
- *
641
- */
642
184
  get history(): History;
643
- /**
644
- *
645
- */
646
185
  get url(): string;
647
- /**
648
- *
649
- * @param props
650
- */
651
186
  invalidate(props?: Record<string, any>): Promise<void>;
652
187
  /**
653
188
  *
@@ -655,25 +190,13 @@ declare class ReactBrowserProvider {
655
190
  * @param options
656
191
  */
657
192
  go(url: string, options?: RouterGoOptions): Promise<void>;
658
- /**
659
- *
660
- * @param options
661
- * @protected
662
- */
663
193
  protected render(options?: {
664
194
  url?: string;
665
195
  previous?: PreviousLayerData[];
666
196
  }): Promise<{
667
197
  url: string;
668
- context: RouterRenderContext;
198
+ head: Head;
669
199
  }>;
670
- /**
671
- * Render the helmet context.
672
- *
673
- * @param ctx
674
- * @protected
675
- */
676
- protected renderHeadContext(ctx: RouterRenderHeadContext): void;
677
200
  /**
678
201
  * Get embedded layers from the server.
679
202
  *
@@ -685,19 +208,19 @@ declare class ReactBrowserProvider {
685
208
  * @protected
686
209
  */
687
210
  protected getRootElement(): HTMLElement;
688
- protected getUserFromCookies(): UserAccountToken | undefined;
689
211
  /**
690
212
  *
691
213
  * @protected
692
214
  */
693
215
  protected ready: _alepha_core.HookDescriptor<"ready">;
694
216
  }
695
- /**
696
- *
697
- */
698
217
  interface RouterGoOptions {
699
218
  replace?: boolean;
700
- match?: RouterMatchOptions;
219
+ match?: TransitionOptions;
220
+ }
221
+ interface ReactHydrationState {
222
+ layers?: PreviousLayerData[];
223
+ links?: HttpClientLink[];
701
224
  }
702
225
 
703
226
  declare class RouterHookApi {
@@ -776,88 +299,40 @@ type HrefLike = string | {
776
299
  };
777
300
  };
778
301
 
779
- declare const pageDescriptorKey = "PAGE";
780
- interface PageDescriptorConfigSchema {
302
+ declare const KEY = "PAGE";
303
+ interface PageConfigSchema {
781
304
  query?: TSchema$1;
782
305
  params?: TSchema$1;
783
306
  }
784
307
  type TPropsDefault = any;
785
308
  type TPropsParentDefault = object;
786
- interface PageDescriptorOptions<TConfig extends PageDescriptorConfigSchema = PageDescriptorConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
787
- /**
788
- *
789
- */
309
+ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
790
310
  name?: string;
791
- /**
792
- *
793
- */
794
311
  path?: string;
795
- /**
796
- *
797
- */
798
312
  schema?: TConfig;
799
- /**
800
- * Function to call when the page is loaded.
801
- */
802
- resolve?: (config: PageDescriptorConfigValue<TConfig> & TPropsParent & {
803
- context: PageContext;
804
- }, context: PageContext) => Async<TProps>;
805
- /**
806
- * Component to render when the page is loaded.
807
- */
313
+ resolve?: (config: PageResolve<TConfig, TPropsParent>) => Async<TProps>;
808
314
  component?: FC<TProps & TPropsParent>;
809
- /**
810
- * Component to render when the page is loaded. (like .component)
811
- */
812
315
  lazy?: () => Promise<{
813
316
  default: FC<TProps & TPropsParent>;
814
317
  }>;
815
- /**
816
- *
817
- */
818
- children?: () => Array<{
318
+ children?: Array<{
819
319
  options: PageDescriptorOptions;
820
320
  }>;
821
- /**
822
- *
823
- */
824
321
  parent?: {
825
322
  options: PageDescriptorOptions<any, TPropsParent>;
826
323
  };
827
- /**
828
- *
829
- */
830
324
  can?: () => boolean;
831
- /**
832
- *
833
- */
834
- head?: RouterRenderHeadContext | ((props: TProps, previous?: RouterRenderHeadContext) => RouterRenderHeadContext);
835
- /**
836
- *
837
- */
325
+ head?: Head | ((props: TProps, previous?: Head) => Head);
838
326
  notFoundHandler?: FC<{
839
327
  url: string;
840
328
  }>;
841
- /**
842
- *
843
- */
844
329
  errorHandler?: FC<{
845
330
  error: Error;
846
331
  url: string;
847
332
  }>;
848
333
  }
849
- interface PageContext {
850
- user?: UserAccountToken;
851
- cookies?: CookieManager;
852
- links?: HttpLink[];
853
- }
854
- interface PageDescriptorConfigValue<TConfig extends PageDescriptorConfigSchema = PageDescriptorConfigSchema> {
855
- query: TConfig["query"] extends TSchema$1 ? Static$1<TConfig["query"]> : Record<string, string>;
856
- params: TConfig["params"] extends TSchema$1 ? Static$1<TConfig["params"]> : Record<string, string>;
857
- pathname: string;
858
- }
859
- interface PageDescriptor<TConfig extends PageDescriptorConfigSchema = PageDescriptorConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
860
- [KIND]: typeof pageDescriptorKey;
334
+ interface PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
335
+ [KIND]: typeof KEY;
861
336
  render: (options?: {
862
337
  params?: Record<string, string>;
863
338
  query?: Record<string, string>;
@@ -868,11 +343,150 @@ interface PageDescriptor<TConfig extends PageDescriptorConfigSchema = PageDescri
868
343
  onClick: () => void;
869
344
  };
870
345
  options: PageDescriptorOptions<TConfig, TProps, TPropsParent>;
346
+ can: () => boolean;
871
347
  }
872
348
  declare const $page: {
873
- <TConfig extends PageDescriptorConfigSchema = PageDescriptorConfigSchema, TProps extends object = any, TPropsParent extends object = object>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
349
+ <TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = any, TPropsParent extends object = object>(options: PageDescriptorOptions<TConfig, TProps, TPropsParent>): PageDescriptor<TConfig, TProps, TPropsParent>;
874
350
  [KIND]: string;
875
351
  };
352
+ interface Head {
353
+ title?: string;
354
+ titleSeparator?: string;
355
+ htmlAttributes?: Record<string, string>;
356
+ bodyAttributes?: Record<string, string>;
357
+ meta?: Array<{
358
+ name: string;
359
+ content: string;
360
+ }>;
361
+ }
362
+ interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
363
+ params: TConfig["params"] extends TSchema$1 ? Static$1<TConfig["params"]> : Record<string, string>;
364
+ query: TConfig["query"] extends TSchema$1 ? Static$1<TConfig["query"]> : Record<string, string>;
365
+ }
366
+ type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & PageResolveContext;
367
+ interface PageResolveContext {
368
+ url: URL;
369
+ head: Head;
370
+ }
371
+
372
+ declare class PageDescriptorProvider {
373
+ protected readonly log: _alepha_core.Logger;
374
+ protected readonly alepha: Alepha;
375
+ protected readonly pages: PageRoute[];
376
+ getPages(): PageRoute[];
377
+ page(name: string): PageRoute;
378
+ root(state: RouterState, context?: PageReactContext, events?: EventEmitter<RouterEvents>): ReactNode;
379
+ createLayers(route: PageRoute, request: PageRequest): Promise<CreateLayersResult>;
380
+ protected getErrorHandler(route: PageRoute): react.FC<{
381
+ error: Error;
382
+ url: string;
383
+ }> | undefined;
384
+ protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
385
+ protected fillHead(page: PageRoute, ctx: PageRequest, props: Record<string, any>): void;
386
+ renderError(e: Error): ReactNode;
387
+ renderEmptyView(): ReactNode;
388
+ href(page: {
389
+ options: {
390
+ name?: string;
391
+ };
392
+ }, params?: Record<string, any>): string;
393
+ compile(path: string, params?: Record<string, string>): string;
394
+ protected renderView(index: number, path: string, view?: ReactNode): ReactNode;
395
+ protected readonly configure: _alepha_core.HookDescriptor<"configure">;
396
+ protected map(pages: Array<{
397
+ value: {
398
+ options: PageDescriptorOptions;
399
+ };
400
+ }>, target: {
401
+ options: PageDescriptorOptions;
402
+ }): PageRouteEntry;
403
+ add(entry: PageRouteEntry): void;
404
+ protected createMatch(page: PageRoute): string;
405
+ protected _next: number;
406
+ protected nextId(): string;
407
+ }
408
+ declare const isPageRoute: (it: any) => it is PageRoute;
409
+ interface PageRouteEntry extends Omit<PageDescriptorOptions, "children" | "parent"> {
410
+ children?: PageRouteEntry[];
411
+ }
412
+ interface PageRoute extends PageRouteEntry {
413
+ type: "page";
414
+ name: string;
415
+ parent?: PageRoute;
416
+ match: string;
417
+ }
418
+ interface Layer {
419
+ config?: {
420
+ query?: Record<string, any>;
421
+ params?: Record<string, any>;
422
+ context?: Record<string, any>;
423
+ };
424
+ name: string;
425
+ props?: Record<string, any>;
426
+ error?: Error;
427
+ part?: string;
428
+ element: ReactNode;
429
+ index: number;
430
+ path: string;
431
+ }
432
+ type PreviousLayerData = Omit<Layer, "element">;
433
+ interface AnchorProps {
434
+ href?: string;
435
+ onClick?: (ev: any) => any;
436
+ }
437
+ interface RouterEvents {
438
+ begin: undefined;
439
+ success: undefined;
440
+ error: Error;
441
+ end: RouterState;
442
+ }
443
+ interface RouterState {
444
+ pathname: string;
445
+ search: string;
446
+ layers: Array<Layer>;
447
+ head: Head;
448
+ }
449
+ interface TransitionOptions {
450
+ state?: RouterState;
451
+ previous?: PreviousLayerData[];
452
+ context?: PageReactContext;
453
+ }
454
+ interface RouterStackItem {
455
+ route: PageRoute;
456
+ config?: Record<string, any>;
457
+ props?: Record<string, any>;
458
+ error?: Error;
459
+ }
460
+ interface RouterRenderResult {
461
+ redirect?: string;
462
+ layers: Layer[];
463
+ head: Head;
464
+ element: ReactNode;
465
+ }
466
+ interface PageRequest extends PageReactContext {
467
+ url: URL;
468
+ params: Record<string, any>;
469
+ query: Record<string, string>;
470
+ head: Head;
471
+ previous?: PreviousLayerData[];
472
+ }
473
+ interface CreateLayersResult extends RouterState {
474
+ redirect?: string;
475
+ }
476
+ interface PageReactContext {
477
+ links?: HttpClientLink[];
478
+ }
479
+
480
+ interface NestedViewProps {
481
+ children?: ReactNode;
482
+ }
483
+ /**
484
+ * Nested view component
485
+ *
486
+ * @param props
487
+ * @constructor
488
+ */
489
+ declare const NestedView: (props: NestedViewProps) => string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
876
490
 
877
491
  interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
878
492
  to: string | PageDescriptor;
@@ -881,10 +495,10 @@ interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
881
495
  declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
882
496
 
883
497
  interface RouterContextValue {
884
- router: Router;
885
498
  alepha: Alepha;
886
499
  state: RouterState;
887
- args: PageContext;
500
+ context: PageReactContext;
501
+ events: EventEmitter<RouterEvents>;
888
502
  }
889
503
  declare const RouterContext: react.Context<RouterContextValue | undefined>;
890
504
 
@@ -894,39 +508,6 @@ interface RouterLayerContextValue {
894
508
  }
895
509
  declare const RouterLayerContext: react.Context<RouterLayerContextValue | undefined>;
896
510
 
897
- declare class Auth {
898
- alepha: Alepha;
899
- log: _alepha_core.Logger;
900
- client: HttpClient;
901
- slugs: {
902
- login: string;
903
- logout: string;
904
- };
905
- start: _alepha_core.HookDescriptor<"start">;
906
- login: (provider?: string) => void;
907
- logout: () => void;
908
- }
909
-
910
- declare const KEY = "AUTH";
911
- interface AuthDescriptorOptions {
912
- name?: string;
913
- oidc?: {
914
- issuer: string;
915
- clientId: string;
916
- clientSecret?: string;
917
- redirectUri?: string;
918
- };
919
- }
920
- interface AuthDescriptor {
921
- [KIND]: typeof KEY;
922
- options: AuthDescriptorOptions;
923
- jwks: () => string;
924
- }
925
- declare const $auth: {
926
- (options: AuthDescriptorOptions): AuthDescriptor;
927
- [KIND]: string;
928
- };
929
-
930
511
  declare const useInject: <T extends object>(clazz: Class<T>) => T;
931
512
 
932
513
  declare const useClient: () => HttpClient;
@@ -938,9 +519,6 @@ interface UseQueryParamsHookOptions {
938
519
  }
939
520
  declare const useQueryParams: <T extends TObject$1>(schema: T, options?: UseQueryParamsHookOptions) => [Static$1<T>, (data: Static$1<T>) => void];
940
521
 
941
- /**
942
- *
943
- */
944
522
  declare const useRouter: () => RouterHookApi;
945
523
 
946
524
  declare const useRouterEvents: (opts?: {
@@ -959,40 +537,19 @@ interface UseActiveHook {
959
537
  name?: string;
960
538
  }
961
539
 
962
- declare const useAuth: () => AuthHook;
963
- interface AuthHook {
964
- user?: UserAccountToken;
965
- logout: () => void;
966
- login: (provider?: string) => void;
967
- }
968
-
969
- declare class PageDescriptorProvider {
970
- protected readonly alepha: Alepha;
971
- protected readonly router: Router;
972
- protected readonly configure: _alepha_core.HookDescriptor<"configure">;
973
- /**
974
- * Transform
975
- * @param pages
976
- * @param target
977
- * @protected
978
- */
979
- protected map(pages: Array<{
980
- value: {
981
- options: PageDescriptorOptions;
982
- };
983
- }>, target: {
984
- options: PageDescriptorOptions;
985
- }): PageRouteEntry;
540
+ declare class RedirectionError extends Error {
541
+ readonly page: HrefLike;
542
+ constructor(page: HrefLike);
986
543
  }
987
544
 
988
- declare const envSchema$1: TObject<{
545
+ declare const envSchema: TObject<{
989
546
  REACT_SERVER_DIST: TString;
990
547
  REACT_SERVER_PREFIX: TString;
991
548
  REACT_SSR_ENABLED: TBoolean;
992
549
  REACT_ROOT_ID: TString;
993
550
  }>;
994
551
  declare module "@alepha/core" {
995
- interface Env extends Partial<Static$1<typeof envSchema$1>> {
552
+ interface Env extends Partial<Static$1<typeof envSchema>> {
996
553
  }
997
554
  interface State {
998
555
  "ReactServerProvider.template"?: string;
@@ -1002,68 +559,47 @@ declare module "@alepha/core" {
1002
559
  declare class ReactServerProvider {
1003
560
  protected readonly log: _alepha_core.Logger;
1004
561
  protected readonly alepha: Alepha;
1005
- protected readonly router: Router;
1006
- protected readonly serverProvider: ServerProvider;
562
+ protected readonly pageDescriptorProvider: PageDescriptorProvider;
563
+ protected readonly serverStaticProvider: ServerStaticProvider;
564
+ protected readonly serverRouterProvider: ServerRouterProvider;
565
+ protected readonly headProvider: ServerHeadProvider;
1007
566
  protected readonly env: {
1008
567
  REACT_ROOT_ID: string;
1009
568
  REACT_SERVER_DIST: string;
1010
569
  REACT_SERVER_PREFIX: string;
1011
570
  REACT_SSR_ENABLED: boolean;
1012
571
  };
572
+ protected readonly ROOT_DIV_REGEX: RegExp;
1013
573
  protected readonly configure: _alepha_core.HookDescriptor<"configure">;
1014
- id: string;
1015
- protected configureRoutes(): Promise<void>;
1016
- /**
1017
- *
1018
- * @param root
1019
- * @protected
1020
- */
1021
- protected createStaticHandler(root: string): ServeDescriptorOptions;
1022
- /**
1023
- *
1024
- * @param templateLoader
1025
- * @protected
1026
- */
1027
- protected createHandler(templateLoader: () => Promise<string | undefined>): RouteObject;
1028
- /**
1029
- *
1030
- * @protected
1031
- */
1032
- protected processDescriptors(): void;
1033
- /**
1034
- *
1035
- * @param url
1036
- * @protected
1037
- */
1038
- protected notFoundHandler(url: URL): Response | undefined;
1039
- /**
1040
- *
1041
- * @param url
1042
- * @param template
1043
- * @param args
1044
- */
1045
- ssr(url: URL, template: string, args?: PageContext): Promise<Response>;
1046
- protected renderHeadContext($: CheerioAPI, headContext: RouterRenderHeadContext): void;
1047
- }
1048
-
1049
- declare class RedirectionError extends Error {
1050
- readonly page: HrefLike;
1051
- constructor(page: HrefLike);
574
+ protected registerPages(templateLoader: () => Promise<string | undefined>): Promise<void>;
575
+ protected getPublicDirectory(): string;
576
+ protected configureStaticServer(root: string): Promise<void>;
577
+ protected configureVite(): Promise<void>;
578
+ protected createRenderFunction(name: string): (options?: {
579
+ params?: Record<string, string>;
580
+ query?: Record<string, string>;
581
+ }) => Promise<string>;
582
+ protected createHandler(page: PageRoute, templateLoader: () => Promise<string | undefined>): ServerHandler;
583
+ fillTemplate(response: {
584
+ html: string;
585
+ }, app: string, script: string): void;
1052
586
  }
1053
587
 
1054
- declare const envSchema: _alepha_core.TObject<{
1055
- REACT_AUTH_ENABLED: TBoolean;
1056
- }>;
1057
588
  declare module "@alepha/core" {
1058
- interface Env extends Partial<Static$1<typeof envSchema>> {
589
+ interface Hooks {
590
+ "react:browser:render": {
591
+ context: PageReactContext;
592
+ hydration?: ReactHydrationState;
593
+ };
594
+ "react:server:render": {
595
+ request: ServerRequest;
596
+ pageRequest: PageRequest;
597
+ };
1059
598
  }
1060
599
  }
1061
600
  declare class ReactModule {
1062
- protected readonly env: {
1063
- REACT_AUTH_ENABLED: boolean;
1064
- };
1065
601
  protected readonly alepha: Alepha;
1066
602
  constructor();
1067
603
  }
1068
604
 
1069
- export { $auth, $page, type AnchorProps, Auth, type AuthDescriptor, type AuthDescriptorOptions, type AuthHook, type AuthProvider, type HrefLike, type Layer, Link, NestedView, type PageContext, type PageDescriptor, type PageDescriptorConfigSchema, type PageDescriptorConfigValue, type PageDescriptorOptions, PageDescriptorProvider, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactAuthProvider, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, type ReactUser, RedirectionError, Router, RouterContext, type RouterContextValue, type RouterEvents, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterMatchOptions, type RouterRenderContext, type RouterRenderHeadContext, type RouterRenderOptions, type RouterRenderResult, type RouterStackItem, type RouterState, type SessionAuthorizationCode, type SessionTokens, type TPropsDefault, type TPropsParentDefault, type UseActiveHook, type UseQueryParamsHookOptions, envSchema$1 as envSchema, pageDescriptorKey, useActive, useAuth, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
605
+ export { $page, type AnchorProps, type CreateLayersResult, type Head, type HrefLike, type Layer, Link, NestedView, type PageConfigSchema, type PageDescriptor, type PageDescriptorOptions, PageDescriptorProvider, type PageReactContext, type PageRequest, type PageRequestConfig, type PageResolve, type PageResolveContext, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, RedirectionError, RouterContext, type RouterContextValue, type RouterEvents, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterRenderResult, type RouterStackItem, type RouterState, type TPropsDefault, type TPropsParentDefault, type TransitionOptions, type UseActiveHook, type UseQueryParamsHookOptions, envSchema, isPageRoute, useActive, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };