@anaemia/core 0.3.7 → 0.5.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.
Files changed (94) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/config.d.ts +8 -1
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/plugins/lightningcss.js +4 -4
  8. package/dist/runtime/context.d.ts.map +1 -1
  9. package/dist/runtime/context.js +5 -4
  10. package/dist/runtime/entry-client.jsx +4 -5
  11. package/dist/runtime/entry-server.d.ts +1 -2
  12. package/dist/runtime/entry-server.d.ts.map +1 -1
  13. package/dist/runtime/entry-server.jsx +18 -321
  14. package/dist/runtime/resources.d.ts.map +1 -1
  15. package/dist/runtime/resources.js +2 -1
  16. package/dist/runtime/route-data.d.ts.map +1 -1
  17. package/dist/runtime/route-data.js +4 -3
  18. package/dist/runtime/route-request.d.ts.map +1 -1
  19. package/dist/runtime/route-request.js +3 -2
  20. package/dist/runtime/rpc-client.d.ts.map +1 -1
  21. package/dist/runtime/rpc-client.js +10 -9
  22. package/dist/runtime/server/app.d.ts +22 -0
  23. package/dist/runtime/server/app.d.ts.map +1 -0
  24. package/dist/runtime/server/app.js +21 -0
  25. package/dist/runtime/server/assets.d.ts +5 -0
  26. package/dist/runtime/server/assets.d.ts.map +1 -0
  27. package/dist/runtime/server/assets.js +48 -0
  28. package/dist/runtime/server/boot.d.ts +4 -0
  29. package/dist/runtime/server/boot.d.ts.map +1 -0
  30. package/dist/runtime/server/boot.js +6 -0
  31. package/dist/runtime/server/env.d.ts +3 -0
  32. package/dist/runtime/server/env.d.ts.map +1 -0
  33. package/dist/runtime/server/env.js +14 -0
  34. package/dist/runtime/server/guards.d.ts +29 -0
  35. package/dist/runtime/server/guards.d.ts.map +1 -0
  36. package/dist/runtime/server/guards.js +12 -0
  37. package/dist/runtime/server/html.d.ts +15 -0
  38. package/dist/runtime/server/html.d.ts.map +1 -0
  39. package/dist/runtime/server/html.js +62 -0
  40. package/dist/runtime/server/hydration.d.ts +3 -0
  41. package/dist/runtime/server/hydration.d.ts.map +1 -0
  42. package/dist/runtime/server/hydration.js +20 -0
  43. package/dist/runtime/server/manifest.d.ts +14 -0
  44. package/dist/runtime/server/manifest.d.ts.map +1 -0
  45. package/dist/runtime/server/manifest.js +59 -0
  46. package/dist/runtime/server/render-request.d.ts +21 -0
  47. package/dist/runtime/server/render-request.d.ts.map +1 -0
  48. package/dist/runtime/server/render-request.jsx +170 -0
  49. package/dist/runtime/server/route-match.d.ts +14 -0
  50. package/dist/runtime/server/route-match.d.ts.map +1 -0
  51. package/dist/runtime/server/route-match.js +35 -0
  52. package/dist/runtime/server/rpc.d.ts +3 -0
  53. package/dist/runtime/server/rpc.d.ts.map +1 -0
  54. package/dist/runtime/server/rpc.js +32 -0
  55. package/dist/runtime/server/types.d.ts +33 -0
  56. package/dist/runtime/server/types.d.ts.map +1 -0
  57. package/dist/runtime/server/types.js +1 -0
  58. package/dist/runtime/shared/constants.d.ts +8 -0
  59. package/dist/runtime/shared/constants.d.ts.map +1 -0
  60. package/dist/runtime/shared/constants.js +7 -0
  61. package/dist/types.d.ts.map +1 -1
  62. package/package.json +11 -7
  63. package/src/anaemia.d.ts +75 -0
  64. package/src/config.ts +9 -1
  65. package/src/index.ts +9 -1
  66. package/src/plugins/index.ts +1 -1
  67. package/src/plugins/lightningcss.ts +11 -11
  68. package/src/runtime/context.browser.ts +1 -1
  69. package/src/runtime/context.ts +6 -5
  70. package/src/runtime/entry-client.tsx +5 -8
  71. package/src/runtime/entry-server.tsx +19 -373
  72. package/src/runtime/resources.ts +3 -2
  73. package/src/runtime/route-data.ts +6 -5
  74. package/src/runtime/route-request.ts +4 -3
  75. package/src/runtime/rpc-client.ts +14 -13
  76. package/src/runtime/server/app.ts +44 -0
  77. package/src/runtime/server/assets.ts +69 -0
  78. package/src/runtime/server/boot.ts +9 -0
  79. package/src/runtime/server/env.ts +17 -0
  80. package/src/runtime/server/guards.ts +26 -0
  81. package/src/runtime/server/html.ts +84 -0
  82. package/src/runtime/server/hydration.ts +26 -0
  83. package/src/runtime/server/manifest.ts +69 -0
  84. package/src/runtime/server/render-request.tsx +230 -0
  85. package/src/runtime/server/route-match.ts +45 -0
  86. package/src/runtime/server/rpc.ts +34 -0
  87. package/src/runtime/server/types.ts +36 -0
  88. package/src/runtime/shared/constants.ts +7 -0
  89. package/src/runtime/webpack.d.ts +1 -1
  90. package/src/types.ts +18 -3
  91. package/test/integration/hmr.test.mjs +18 -5
  92. package/test/rpc-client.test.mjs +1 -1
  93. package/test/run-on-server.test.mjs +2 -6
  94. package/tsconfig.json +1 -1
package/src/types.ts CHANGED
@@ -13,7 +13,9 @@ export interface LoaderArgs<Params extends Record<string, string> = Record<strin
13
13
  /**
14
14
  * represents an application page loader function.
15
15
  */
16
- export type LoaderFunction<ResponseData = unknown, Params extends Record<string, string> = Record<string, string>> = (args: LoaderArgs<Params>) => Promise<ResponseData> | ResponseData;
16
+ export type LoaderFunction<ResponseData = unknown, Params extends Record<string, string> = Record<string, string>> = (
17
+ args: LoaderArgs<Params>,
18
+ ) => Promise<ResponseData> | ResponseData;
17
19
 
18
20
  /**
19
21
  * extracts and unwraps the true data structure returned by a server function or loader.
@@ -27,9 +29,22 @@ export type GuardContext = {
27
29
  url: string;
28
30
  };
29
31
 
30
- export type GuardResult = void | undefined | { redirect: string; status?: 301 | 302 | 307 | 308 } | { status: 401 | 403 | 404 | 500; body?: string };
32
+ export type GuardResult =
33
+ | void
34
+ | undefined
35
+ | { redirect: string; status?: 301 | 302 | 307 | 308 }
36
+ | { status: 401 | 403 | 404 | 500; body?: string };
31
37
 
32
- export type GuardFn = (ctx: { params: Record<string, string>; request: Request; url: string }) => void | undefined | { redirect: string; status?: RedirectStatusCode } | { status: number; body?: string } | Promise<void | undefined | { redirect: string; status?: RedirectStatusCode } | { status: number; body?: string }>;
38
+ export type GuardFn = (ctx: {
39
+ params: Record<string, string>;
40
+ request: Request;
41
+ url: string;
42
+ }) =>
43
+ | void
44
+ | undefined
45
+ | { redirect: string; status?: RedirectStatusCode }
46
+ | { status: number; body?: string }
47
+ | Promise<void | undefined | { redirect: string; status?: RedirectStatusCode } | { status: number; body?: string }>;
33
48
 
34
49
  export type ServerFunction<Args extends unknown[], Return> = ((...args: Args) => Promise<Return>) & {
35
50
  id?: string;
@@ -28,7 +28,9 @@ async function resolveConfigPort() {
28
28
  return userConfig.port;
29
29
  }
30
30
  } catch (err) {
31
- console.warn(`[HMR test warning]: failed parsing anaemia.config.ts, falling back to port 3000. Error: ${err.message}`);
31
+ console.warn(
32
+ `[HMR test warning]: failed parsing anaemia.config.ts, falling back to port 3000. Error: ${err.message}`,
33
+ );
32
34
  }
33
35
  }
34
36
 
@@ -119,11 +121,18 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
119
121
 
120
122
  const titleText = await page.textContent("h1");
121
123
  assert.equal(titleText.trim(), "anaemia");
122
- assert.equal(consoleErrors.length, 0, `Errors during initial render: ${consoleErrors.map((e) => e.message).join(", ")}`);
124
+ assert.equal(
125
+ consoleErrors.length,
126
+ 0,
127
+ `Errors during initial render: ${consoleErrors.map((e) => e.message).join(", ")}`,
128
+ );
123
129
  });
124
130
 
125
131
  await t.test("should push hot module updates to browser when files change", async () => {
126
- const updatedContent = originalComponentContent.replace(`<h1 class={styles.title}>anaemia</h1>`, `<h1 class={styles.title}>anaemia updated!</h1>`);
132
+ const updatedContent = originalComponentContent.replace(
133
+ `<h1 class={styles.title}>anaemia</h1>`,
134
+ `<h1 class={styles.title}>anaemia updated!</h1>`,
135
+ );
127
136
 
128
137
  assert.notEqual(originalComponentContent, updatedContent, "Regex failed to modify component text.");
129
138
  fs.writeFileSync(componentPath, updatedContent, "utf-8");
@@ -134,7 +143,7 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
134
143
  const h1 = document.querySelector("h1");
135
144
  return h1 && h1.textContent.trim() === "anaemia updated!";
136
145
  },
137
- { timeout: 10000 }
146
+ { timeout: 10000 },
138
147
  );
139
148
  });
140
149
 
@@ -145,6 +154,10 @@ test("integration - dev server HMR & hydration lifecycle", async (t) => {
145
154
 
146
155
  const titleText = await page.textContent("h1");
147
156
  assert.equal(titleText.trim(), "anaemia updated!");
148
- assert.equal(consoleErrors.length, 0, `Errors detected after page refresh: ${consoleErrors.map((e) => e.message).join(", ")}`);
157
+ assert.equal(
158
+ consoleErrors.length,
159
+ 0,
160
+ `Errors detected after page refresh: ${consoleErrors.map((e) => e.message).join(", ")}`,
161
+ );
149
162
  });
150
163
  });
@@ -68,4 +68,4 @@ test("asyncRpcCall returns undefined when no SSR store exists", async () => {
68
68
  const fn = $$executeClientRpc("missing");
69
69
  const result = await fn("someArg");
70
70
  assert.equal(result, undefined);
71
- });
71
+ });
@@ -1,10 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
- import {
4
- runOnServer,
5
- serverFunctionsRegistry,
6
- ssrStorage,
7
- } from "../dist/runtime/context.js";
3
+ import { runOnServer, serverFunctionsRegistry, ssrStorage } from "../dist/runtime/context.js";
8
4
  import { createRouteRequest } from "../dist/runtime/route-request.js";
9
5
 
10
6
  test("runOnServer returns a callable function and registers the original implementation", async () => {
@@ -26,7 +22,7 @@ test("runOnServer records SSR results by id and argument list for hydration", as
26
22
 
27
23
  assert.deepEqual(store.get("__SERVER_FUNCTION_DATA__"), {
28
24
  greet: {
29
- "[\"Ada\"]": "hello Ada",
25
+ '["Ada"]': "hello Ada",
30
26
  },
31
27
  });
32
28
  });
package/tsconfig.json CHANGED
@@ -9,4 +9,4 @@
9
9
  "types": ["node"]
10
10
  },
11
11
  "include": ["src/**/*"]
12
- }
12
+ }