@c9up/aurora 0.1.39 → 0.1.40

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.
@@ -11,6 +11,8 @@
11
11
  * and node-free (only `mountLiveSession` + `crypto.randomUUID`, both isomorphic).
12
12
  */
13
13
 
14
+ import { AuroraError } from "./errors.js";
15
+
14
16
  import {
15
17
  type LiveComponentDefinition,
16
18
  type LiveSession,
@@ -75,7 +77,8 @@ export function createLiveRegistry(): LiveRegistry {
75
77
  mount(name, ownerId) {
76
78
  const factory = defs.get(name);
77
79
  if (!factory) {
78
- throw new Error(
80
+ throw new AuroraError(
81
+ "E_AURORA_UNKNOWN_LIVE_COMPONENT",
79
82
  `[aurora:live] unknown live component "${name}" — register it with registry.define("${name}", …) before mounting.`,
80
83
  );
81
84
  }
package/src/relay.ts CHANGED
@@ -18,6 +18,7 @@
18
18
  * `EventSource` being undefined.
19
19
  */
20
20
 
21
+ import { AuroraError } from "./errors.js";
21
22
  import { xsrfHeaderFor } from "./xsrf.js";
22
23
 
23
24
  /**
@@ -334,7 +335,10 @@ async function postHandshake(url: string, channel: string): Promise<void> {
334
335
  credentials: "include",
335
336
  });
336
337
  if (!res.ok) {
337
- throw new Error(`HTTP ${res.status}`);
338
+ throw new AuroraError(
339
+ "E_AURORA_RELAY_REQUEST_FAILED",
340
+ `[aurora:relay] HTTP ${res.status}`,
341
+ );
338
342
  }
339
343
  }
340
344
 
@@ -25,6 +25,7 @@
25
25
 
26
26
  import { AsyncLocalStorage } from "node:async_hooks";
27
27
  import { setCookieStoreReader } from "../browser.js";
28
+ import { AuroraError } from "../errors.js";
28
29
  import type { Pages } from "../Pages.js";
29
30
  import { renderToString } from "../ssr.js";
30
31
  import { setRouteManifestReader } from "../url.js";
@@ -331,7 +332,10 @@ function isPlainRecord(value: unknown): value is Record<string, unknown> {
331
332
 
332
333
  function normalizeRootTag(tag: string): string {
333
334
  if (/^[a-z][a-z0-9-]*$/i.test(tag)) return tag.toLowerCase();
334
- throw new Error(`[aurora] illegal root tag: ${JSON.stringify(tag)}`);
335
+ throw new AuroraError(
336
+ "E_AURORA_ILLEGAL_ROOT_TAG",
337
+ `[aurora] illegal root tag: ${JSON.stringify(tag)}`,
338
+ );
335
339
  }
336
340
 
337
341
  function rootAttrs(id: string, className: string | undefined): string {
package/src/server.ts CHANGED
@@ -12,11 +12,18 @@
12
12
  import "./augmentations.js";
13
13
 
14
14
  export { AuroraManager, type AuroraManagerConfig } from "./AuroraManager.js";
15
+ export { AuroraError, type AuroraErrorCode } from "./errors.js";
15
16
  export {
16
17
  type AuroraRequestRenderer,
17
18
  auroraContext,
18
19
  } from "./middleware.js";
19
- export { type PageFactory, Pages, type PagesConfig } from "./Pages.js";
20
+ export {
21
+ type PageFactory,
22
+ Pages,
23
+ type PagesConfig,
24
+ /** @internal classification seam, asserted by the tests */
25
+ pageImportError,
26
+ } from "./Pages.js";
20
27
  export {
21
28
  type RenderHttpContext,
22
29
  type RenderPageOptions,
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import type { AuroraManager } from "../AuroraManager.js";
14
+ import { AuroraError } from "../errors.js";
14
15
 
15
16
  let instance: AuroraManager | undefined;
16
17
 
@@ -48,7 +49,8 @@ const aurora: AuroraManager = new Proxy({} as AuroraManager, {
48
49
  return undefined;
49
50
  }
50
51
  if (!instance) {
51
- throw new Error(
52
+ throw new AuroraError(
53
+ "E_AURORA_NOT_BOOTED",
52
54
  "[aurora] AuroraManager singleton accessed before AuroraProvider.boot() ran " +
53
55
  "or `setAurora(myManager)` was called. Wire one of them first.",
54
56
  );
package/src/url.ts CHANGED
@@ -17,6 +17,8 @@
17
17
  * side. Node-free — part of aurora's client runtime.
18
18
  */
19
19
 
20
+ import { AuroraError } from "./errors.js";
21
+
20
22
  let manifest: Record<string, string> = {};
21
23
 
22
24
  type RouteManifestReader = () => Record<string, string> | undefined;
@@ -65,7 +67,8 @@ export function urlFor(
65
67
  const pattern = routes[name];
66
68
  if (pattern === undefined) {
67
69
  const known = Object.keys(routes);
68
- throw new Error(
70
+ throw new AuroraError(
71
+ "E_AURORA_UNKNOWN_ROUTE",
69
72
  `[aurora] urlFor: unknown route '${name}'. ${
70
73
  known.length > 0
71
74
  ? `Known: ${known.join(", ")}`
@@ -91,7 +94,8 @@ export function urlFor(
91
94
 
92
95
  const missing = url.match(/:[A-Za-z_][\w]*/g);
93
96
  if (missing && missing.length > 0) {
94
- throw new Error(
97
+ throw new AuroraError(
98
+ "E_AURORA_MISSING_ROUTE_PARAMS",
95
99
  `[aurora] urlFor: route '${name}' is missing params ${missing.join(", ")}`,
96
100
  );
97
101
  }