@alepha/react 0.8.0 → 0.9.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.
@@ -1,11 +1,11 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import {
4
+ $env,
4
5
  $hook,
5
6
  $inject,
6
7
  $logger,
7
8
  Alepha,
8
- OPTIONS,
9
9
  type Static,
10
10
  t,
11
11
  } from "@alepha/core";
@@ -41,8 +41,8 @@ const envSchema = t.object({
41
41
  declare module "@alepha/core" {
42
42
  interface Env extends Partial<Static<typeof envSchema>> {}
43
43
  interface State {
44
- "ReactServerProvider.template"?: string;
45
- "ReactServerProvider.ssr"?: boolean;
44
+ "react.server.template"?: string;
45
+ "react.server.ssr"?: boolean;
46
46
  }
47
47
  }
48
48
 
@@ -53,7 +53,7 @@ export class ReactServerProvider {
53
53
  protected readonly serverStaticProvider = $inject(ServerStaticProvider);
54
54
  protected readonly serverRouterProvider = $inject(ServerRouterProvider);
55
55
  protected readonly serverTimingProvider = $inject(ServerTimingProvider);
56
- protected readonly env = $inject(envSchema);
56
+ protected readonly env = $env(envSchema);
57
57
  protected readonly ROOT_DIV_REGEX = new RegExp(
58
58
  `<div([^>]*)\\s+id=["']${this.env.REACT_ROOT_ID}["']([^>]*)>(.*?)<\\/div>`,
59
59
  "is",
@@ -62,17 +62,15 @@ export class ReactServerProvider {
62
62
  public readonly onConfigure = $hook({
63
63
  on: "configure",
64
64
  handler: async () => {
65
- const pages = this.alepha.getDescriptorValues($page);
65
+ const pages = this.alepha.descriptors($page);
66
66
 
67
67
  const ssrEnabled =
68
68
  pages.length > 0 && this.env.REACT_SSR_ENABLED !== false;
69
69
 
70
- this.alepha.state("ReactServerProvider.ssr", ssrEnabled);
70
+ this.alepha.state("react.server.ssr", ssrEnabled);
71
71
 
72
- for (const { key, instance, value } of pages) {
73
- const name = value[OPTIONS].name ?? key;
74
-
75
- instance[key].render = this.createRenderFunction(name);
72
+ for (const page of pages) {
73
+ page.render = this.createRenderFunction(page.name);
76
74
  }
77
75
 
78
76
  // development mode
@@ -105,7 +103,7 @@ export class ReactServerProvider {
105
103
 
106
104
  // no SSR enabled, serve index.html for all unmatched routes
107
105
  this.log.info("SSR is disabled, use History API fallback");
108
- await this.serverRouterProvider.route({
106
+ this.serverRouterProvider.createRoute({
109
107
  path: "*",
110
108
  handler: async ({ url, reply }) => {
111
109
  if (url.pathname.includes(".")) {
@@ -127,7 +125,7 @@ export class ReactServerProvider {
127
125
 
128
126
  public get template() {
129
127
  return (
130
- this.alepha.state("ReactServerProvider.template") ??
128
+ this.alepha.state("react.server.template") ??
131
129
  "<!DOCTYPE html><html lang='en'><head></head><body></body></html>"
132
130
  );
133
131
  }
@@ -140,7 +138,7 @@ export class ReactServerProvider {
140
138
 
141
139
  this.log.debug(`+ ${page.match} -> ${page.name}`);
142
140
 
143
- await this.serverRouterProvider.route({
141
+ this.serverRouterProvider.createRoute({
144
142
  ...page,
145
143
  schema: undefined, // schema is handled by the page descriptor provider for now (shared by browser and server)
146
144
  method: "GET",
@@ -166,7 +164,7 @@ export class ReactServerProvider {
166
164
  }
167
165
 
168
166
  protected async configureStaticServer(root: string) {
169
- await this.serverStaticProvider.serve({
167
+ await this.serverStaticProvider.createStaticServer({
170
168
  root,
171
169
  path: this.env.REACT_SERVER_PREFIX,
172
170
  });
@@ -262,7 +260,7 @@ export class ReactServerProvider {
262
260
  };
263
261
 
264
262
  if (this.alepha.has(ServerLinksProvider)) {
265
- const srv = this.alepha.get(ServerLinksProvider);
263
+ const srv = this.alepha.inject(ServerLinksProvider);
266
264
  const schema = apiLinksResponseSchema as any;
267
265
 
268
266
  context.links = this.alepha.parse(