@c9up/aurora 0.1.38 → 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.
Files changed (50) hide show
  1. package/dist/AuroraManager.d.ts +6 -0
  2. package/dist/AuroraManager.js +12 -1
  3. package/dist/AuroraProvider.js +5 -2
  4. package/dist/Pages.d.ts +26 -0
  5. package/dist/Pages.js +70 -17
  6. package/dist/browser.js +2 -1
  7. package/dist/component.js +2 -1
  8. package/dist/devPageHooks.d.ts +44 -0
  9. package/dist/devPageHooks.js +62 -0
  10. package/dist/devPageReload.d.ts +75 -0
  11. package/dist/devPageReload.js +136 -0
  12. package/dist/errors.d.ts +51 -0
  13. package/dist/errors.js +26 -0
  14. package/dist/form.d.ts +1 -1
  15. package/dist/html.js +2 -1
  16. package/dist/hydrate.js +4 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/liveRegistry.js +2 -1
  20. package/dist/relay.js +2 -1
  21. package/dist/render.d.ts +17 -1
  22. package/dist/render.js +58 -22
  23. package/dist/server/renderPage.js +2 -1
  24. package/dist/server/serveAssets.d.ts +10 -0
  25. package/dist/server/serveAssets.js +38 -0
  26. package/dist/server.d.ts +4 -1
  27. package/dist/server.js +4 -1
  28. package/dist/services/main.js +2 -1
  29. package/dist/url.js +3 -2
  30. package/package.json +11 -8
  31. package/src/AuroraManager.ts +12 -1
  32. package/src/AuroraProvider.ts +5 -2
  33. package/src/Pages.ts +92 -20
  34. package/src/browser.ts +5 -1
  35. package/src/component.ts +3 -1
  36. package/src/devPageHooks.ts +86 -0
  37. package/src/devPageReload.ts +142 -0
  38. package/src/errors.ts +58 -0
  39. package/src/form.ts +1 -1
  40. package/src/html.ts +4 -1
  41. package/src/hydrate.ts +4 -1
  42. package/src/index.ts +1 -0
  43. package/src/liveRegistry.ts +4 -1
  44. package/src/relay.ts +5 -1
  45. package/src/render.ts +76 -32
  46. package/src/server/renderPage.ts +5 -1
  47. package/src/server/serveAssets.ts +48 -0
  48. package/src/server.ts +8 -1
  49. package/src/services/main.ts +3 -1
  50. package/src/url.ts +6 -2
package/dist/html.js CHANGED
@@ -20,6 +20,7 @@
20
20
  * No custom directives, no fragments-in-attribute-name, no comment-only
21
21
  * placeholders.
22
22
  */
23
+ import { AuroraError } from "./errors.js";
23
24
  import { isTemplateResult, TEMPLATE_RESULT_BRAND, } from "./types.js";
24
25
  const TEMPLATE_CACHE = new WeakMap();
25
26
  /** Sentinel inserted at every `${...}` site. Read back during the walk. */
@@ -183,7 +184,7 @@ function collectSlots(root, classification) {
183
184
  if (cls === undefined)
184
185
  return;
185
186
  if (cls.region !== "text") {
186
- throw new Error(`[aurora] internal classification mismatch at slot ${slotIndex}`);
187
+ throw new AuroraError("E_AURORA_INTERNAL", `[aurora] internal classification mismatch at slot ${slotIndex}`);
187
188
  }
188
189
  const slot = { kind: "text", path: [...path] };
189
190
  slots.push(slot);
package/dist/hydrate.js CHANGED
@@ -91,7 +91,10 @@ function renderValueToNodes(value, cleanups, mountHooks, doc) {
91
91
  return out;
92
92
  }
93
93
  if (isTemplateResult(value)) {
94
- const frag = mount(value, cleanups, [], mountHooks);
94
+ // The renderer collects hooks in a queue now; hydrate keeps its own
95
+ // flat list, so it hands one over and takes back what was collected.
96
+ const nested = { hooks: mountHooks, flushed: false };
97
+ const frag = mount(value, cleanups, [], nested);
95
98
  return Array.from(frag.childNodes);
96
99
  }
97
100
  if (value instanceof Node)
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { type ClassValue, clsx, cn, twMerge } from "./cn.js";
4
4
  export type { Command } from "./command.js";
5
5
  export { command } from "./command.js";
6
6
  export { component, onMount, onUnmount } from "./component.js";
7
+ export { AuroraError, type AuroraErrorCode } from "./errors.js";
7
8
  export type { FieldErrors, Form, FormField, FormOptions, FormSchema, FormValidate, } from "./form.js";
8
9
  export { form } from "./form.js";
9
10
  export { html, isTemplateResult } from "./html.js";
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ export { back, booleanCookie, clipboard, cookie, cookieSignal, cookieState, forw
17
17
  export { clsx, cn, twMerge } from "./cn.js";
18
18
  export { command } from "./command.js";
19
19
  export { component, onMount, onUnmount } from "./component.js";
20
+ export { AuroraError } from "./errors.js";
20
21
  export { form } from "./form.js";
21
22
  export { html, isTemplateResult } from "./html.js";
22
23
  export { HttpClient, HttpError, http, isAbortError, isHttpError, } from "./http.js";
@@ -10,6 +10,7 @@
10
10
  * `get(id)?.dispatch(...)`; disconnect → `disposeOwner(uid)`. Transport-agnostic
11
11
  * and node-free (only `mountLiveSession` + `crypto.randomUUID`, both isomorphic).
12
12
  */
13
+ import { AuroraError } from "./errors.js";
13
14
  import { mountLiveSession, } from "./liveSession.js";
14
15
  /** Create an isolated live-session registry (one per app / per relay instance). */
15
16
  export function createLiveRegistry() {
@@ -39,7 +40,7 @@ export function createLiveRegistry() {
39
40
  mount(name, ownerId) {
40
41
  const factory = defs.get(name);
41
42
  if (!factory) {
42
- throw new Error(`[aurora:live] unknown live component "${name}" — register it with registry.define("${name}", …) before mounting.`);
43
+ throw new AuroraError("E_AURORA_UNKNOWN_LIVE_COMPONENT", `[aurora:live] unknown live component "${name}" — register it with registry.define("${name}", …) before mounting.`);
43
44
  }
44
45
  const id = crypto.randomUUID();
45
46
  const handle = {
package/dist/relay.js CHANGED
@@ -17,6 +17,7 @@
17
17
  * `@c9up/aurora`. Node-side code that pulls it will trip on
18
18
  * `EventSource` being undefined.
19
19
  */
20
+ import { AuroraError } from "./errors.js";
20
21
  import { xsrfHeaderFor } from "./xsrf.js";
21
22
  const STATE = {
22
23
  sse: null,
@@ -250,7 +251,7 @@ async function postHandshake(url, channel) {
250
251
  credentials: "include",
251
252
  });
252
253
  if (!res.ok) {
253
- throw new Error(`HTTP ${res.status}`);
254
+ throw new AuroraError("E_AURORA_RELAY_REQUEST_FAILED", `[aurora:relay] HTTP ${res.status}`);
254
255
  }
255
256
  }
256
257
  function safeJson(raw) {
package/dist/render.d.ts CHANGED
@@ -9,6 +9,21 @@
9
9
  */
10
10
  import { type EffectCallback, type TemplateResult } from "./types.js";
11
11
  export type Disposer = () => void;
12
+ /**
13
+ * The `onMount` hooks collected while a tree is built, and whether they have
14
+ * already been run.
15
+ *
16
+ * A bare array was not enough. The root flushes it once, after the fragment is
17
+ * in the document; a reactive slot that swapped its content LATER kept
18
+ * appending to that same array, and nothing flushed it again — the component's
19
+ * setup ran, its `onMount` never did, and the hooks piled up for the life of
20
+ * the page. The flag is what lets a later update tell "collect these, the root
21
+ * will run them" from "the root is done, run mine myself".
22
+ */
23
+ interface MountQueue {
24
+ hooks: Array<EffectCallback>;
25
+ flushed: boolean;
26
+ }
12
27
  /**
13
28
  * Mount a TemplateResult into `container`. Returns a `Disposer` that
14
29
  * stops every reactive effect and removes the mounted nodes. Calling it
@@ -22,4 +37,5 @@ export declare function render(result: TemplateResult, container: Element | Docu
22
37
  * nested-template subtree when the signal changes after hydration
23
38
  * (the swap path — see `hydrateTextSlot`).
24
39
  */
25
- export declare function mount(result: TemplateResult, cleanups: Disposer[], mounted: ChildNode[], mountHooks: Array<EffectCallback>): DocumentFragment;
40
+ export declare function mount(result: TemplateResult, cleanups: Disposer[], mounted: ChildNode[], queue: MountQueue): DocumentFragment;
41
+ export {};
package/dist/render.js CHANGED
@@ -16,6 +16,24 @@ import { readComponentLifecycle } from "./component.js";
16
16
  import { getTemplate } from "./html.js";
17
17
  import { effect, isSignal } from "./reactive.js";
18
18
  import { isTemplateResult, } from "./types.js";
19
+ /**
20
+ * Run hooks, sending any teardown to `cleanups`.
21
+ *
22
+ * Failures are swallowed per hook: one component's bad `onMount` must not stop
23
+ * its siblings from mounting.
24
+ */
25
+ function runMountHooks(hooks, cleanups) {
26
+ for (const hook of hooks) {
27
+ try {
28
+ const teardown = hook();
29
+ if (typeof teardown === "function")
30
+ cleanups.push(teardown);
31
+ }
32
+ catch {
33
+ /* swallow — one bad onMount should not block sibling components */
34
+ }
35
+ }
36
+ }
19
37
  /**
20
38
  * Mount a TemplateResult into `container`. Returns a `Disposer` that
21
39
  * stops every reactive effect and removes the mounted nodes. Calling it
@@ -24,22 +42,17 @@ import { isTemplateResult, } from "./types.js";
24
42
  export function render(result, container) {
25
43
  const cleanups = [];
26
44
  const mountedNodes = [];
27
- const mountHooks = [];
28
- const fragment = mount(result, cleanups, mountedNodes, mountHooks);
45
+ const queue = { hooks: [], flushed: false };
46
+ const fragment = mount(result, cleanups, mountedNodes, queue);
29
47
  container.appendChild(fragment);
30
48
  // `onMount` hooks fire after the fragment is live in the document so
31
49
  // callbacks that measure / focus / observe see a real DOM. A returned
32
50
  // cleanup function joins the unmount queue.
33
- for (const hook of mountHooks) {
34
- try {
35
- const teardown = hook();
36
- if (typeof teardown === "function")
37
- cleanups.push(teardown);
38
- }
39
- catch {
40
- /* swallow — one bad onMount should not block sibling components */
41
- }
42
- }
51
+ runMountHooks(queue.hooks, cleanups);
52
+ queue.hooks = [];
53
+ // From here on the root never flushes again, so a slot that mounts
54
+ // something later has to run its own hooks.
55
+ queue.flushed = true;
43
56
  let disposed = false;
44
57
  return () => {
45
58
  if (disposed)
@@ -58,14 +71,14 @@ export function render(result, container) {
58
71
  * nested-template subtree when the signal changes after hydration
59
72
  * (the swap path — see `hydrateTextSlot`).
60
73
  */
61
- export function mount(result, cleanups, mounted, mountHooks) {
74
+ export function mount(result, cleanups, mounted, queue) {
62
75
  const tpl = getTemplate(result.strings);
63
76
  const fragment = tpl.element.content.cloneNode(true);
64
77
  // Forward any component()-attached lifecycle from this result.
65
78
  const lifecycle = readComponentLifecycle(result);
66
79
  if (lifecycle) {
67
80
  for (const hook of lifecycle.mountHooks)
68
- mountHooks.push(hook);
81
+ queue.hooks.push(hook);
69
82
  for (const c of lifecycle.cleanups)
70
83
  cleanups.push(c);
71
84
  }
@@ -106,7 +119,7 @@ export function mount(result, cleanups, mounted, mountHooks) {
106
119
  collectMultiAttr(slot, node, result.values[i], multiGroups);
107
120
  }
108
121
  else {
109
- applySlot(slot, node, result.values[i], cleanups, mounted, mountHooks);
122
+ applySlot(slot, node, result.values[i], cleanups, mounted, queue);
110
123
  }
111
124
  }
112
125
  for (const group of multiGroups.values()) {
@@ -134,10 +147,10 @@ function resolvePath(root, path) {
134
147
  }
135
148
  return node;
136
149
  }
137
- function applySlot(slot, node, value, cleanups, mounted, mountHooks) {
150
+ function applySlot(slot, node, value, cleanups, mounted, queue) {
138
151
  switch (slot.kind) {
139
152
  case "text":
140
- applyTextSlot(slot, node, value, cleanups, mounted, mountHooks);
153
+ applyTextSlot(slot, node, value, cleanups, mounted, queue);
141
154
  return;
142
155
  case "attr":
143
156
  applyAttrSlot(slot, node, value, cleanups);
@@ -159,7 +172,7 @@ function applySlot(slot, node, value, cleanups, mounted, mountHooks) {
159
172
  * inserted before it, and each re-render swaps out only the nodes it
160
173
  * previously inserted.
161
174
  */
162
- function applyTextSlot(_slot, anchor, value, cleanups, mounted, mountHooks) {
175
+ function applyTextSlot(_slot, anchor, value, cleanups, mounted, queue) {
163
176
  let currentNodes = [];
164
177
  // Per-render disposers for whatever the slot currently shows. A
165
178
  // reactive slot that swaps a nested TemplateResult for another must
@@ -179,7 +192,16 @@ function applyTextSlot(_slot, anchor, value, cleanups, mounted, mountHooks) {
179
192
  for (const n of currentNodes)
180
193
  n.remove();
181
194
  currentNodes = [];
182
- const nodes = renderValueIntoNodes(newValue, localCleanups, mounted, mountHooks);
195
+ // This render's hooks are collected apart from the shared queue,
196
+ // whichever phase we are in, because their TEARDOWNS belong to this
197
+ // slot: the next swap must dispose what it replaces. Left on the root's
198
+ // list, a component mounted per row kept its subscription until the
199
+ // whole page unmounted.
200
+ //
201
+ // `flushed` is inherited so a deeper slot built during this render
202
+ // still knows whether the root has a flush coming.
203
+ const own = { hooks: [], flushed: queue.flushed };
204
+ const nodes = renderValueIntoNodes(newValue, localCleanups, mounted, own);
183
205
  const parent = anchor.parentNode;
184
206
  if (!parent)
185
207
  return;
@@ -187,6 +209,20 @@ function applyTextSlot(_slot, anchor, value, cleanups, mounted, mountHooks) {
187
209
  parent.insertBefore(n, anchor);
188
210
  currentNodes.push(n);
189
211
  }
212
+ if (queue.flushed) {
213
+ // After insertion, exactly as at the root: an `onMount` that
214
+ // measures, focuses or observes has to see a live node.
215
+ runMountHooks(own.hooks, localCleanups);
216
+ return;
217
+ }
218
+ // Still building the initial tree: the nodes are in a detached
219
+ // fragment, so defer to the root's flush. One wrapper carries them, and
220
+ // it returns nothing — the real teardowns go to `localCleanups`, not to
221
+ // the root.
222
+ const pending = own.hooks;
223
+ queue.hooks.push(() => {
224
+ runMountHooks(pending.splice(0), localCleanups);
225
+ });
190
226
  }
191
227
  if (isSignal(value) || typeof value === "function") {
192
228
  const dispose = effect(() => {
@@ -206,18 +242,18 @@ function applyTextSlot(_slot, anchor, value, cleanups, mounted, mountHooks) {
206
242
  cleanups.push(disposeLocal);
207
243
  }
208
244
  }
209
- function renderValueIntoNodes(value, cleanups, mounted, mountHooks) {
245
+ function renderValueIntoNodes(value, cleanups, mounted, queue) {
210
246
  if (value === null || value === undefined || value === false)
211
247
  return [];
212
248
  if (Array.isArray(value)) {
213
249
  const out = [];
214
250
  for (const item of value) {
215
- out.push(...renderValueIntoNodes(item, cleanups, mounted, mountHooks));
251
+ out.push(...renderValueIntoNodes(item, cleanups, mounted, queue));
216
252
  }
217
253
  return out;
218
254
  }
219
255
  if (isTemplateResult(value)) {
220
- const frag = mount(value, cleanups, mounted, mountHooks);
256
+ const frag = mount(value, cleanups, mounted, queue);
221
257
  return Array.from(frag.childNodes);
222
258
  }
223
259
  if (value instanceof Node) {
@@ -24,6 +24,7 @@
24
24
  */
25
25
  import { AsyncLocalStorage } from "node:async_hooks";
26
26
  import { setCookieStoreReader } from "../browser.js";
27
+ import { AuroraError } from "../errors.js";
27
28
  import { renderToString } from "../ssr.js";
28
29
  import { setRouteManifestReader } from "../url.js";
29
30
  const renderScope = new AsyncLocalStorage();
@@ -154,7 +155,7 @@ function isPlainRecord(value) {
154
155
  function normalizeRootTag(tag) {
155
156
  if (/^[a-z][a-z0-9-]*$/i.test(tag))
156
157
  return tag.toLowerCase();
157
- throw new Error(`[aurora] illegal root tag: ${JSON.stringify(tag)}`);
158
+ throw new AuroraError("E_AURORA_ILLEGAL_ROOT_TAG", `[aurora] illegal root tag: ${JSON.stringify(tag)}`);
158
159
  }
159
160
  function rootAttrs(id, className) {
160
161
  const attrs = [`id="${escapeAttr(id)}"`];
@@ -28,6 +28,12 @@ export interface AssetsRequest {
28
28
  * convention.
29
29
  */
30
30
  param(name: string): unknown;
31
+ /**
32
+ * Read a request header. OPTIONAL, so a host that only implements
33
+ * `param()` keeps working: without it there is no conditional request and
34
+ * every response is a full 200, which is what happened before.
35
+ */
36
+ header?(name: string): string | undefined;
31
37
  }
32
38
  export interface AssetsResponse {
33
39
  status(code: number): AssetsResponse;
@@ -48,6 +54,10 @@ export interface ServeAssetsOptions {
48
54
  * `Cache-Control` value to emit. Defaults to a dev-friendly
49
55
  * 60-second TTL. Production deployments should hash the asset
50
56
  * name and switch to `public, max-age=31536000, immutable`.
57
+ *
58
+ * Note that a TTL alone tells the browser not to ASK for 60 seconds. Pair
59
+ * it with `no-cache` while developing — the ETag below then makes the
60
+ * revalidation nearly free.
51
61
  */
52
62
  cacheControl?: string;
53
63
  }
@@ -9,6 +9,7 @@
9
9
  * and writes to `ctx.response`. Any context that satisfies
10
10
  * `AssetsHttpContext` (Ream, AdonisJS, anything duck-typed) works.
11
11
  */
12
+ import { createHash } from "node:crypto";
12
13
  import { readFile, realpath } from "node:fs/promises";
13
14
  import { dirname, extname, join, resolve as resolvePath, sep } from "node:path";
14
15
  import { fileURLToPath } from "node:url";
@@ -25,6 +26,27 @@ import { fileURLToPath } from "node:url";
25
26
  export function packageAssetDir(specifier) {
26
27
  return dirname(fileURLToPath(import.meta.resolve(specifier)));
27
28
  }
29
+ /**
30
+ * Does `If-None-Match` cover this entity? (RFC 9110 §13.1.2)
31
+ *
32
+ * A strict `===` answered 200 for three shapes a real client sends: `*`, a
33
+ * comma-separated list of tags, and the weak form `W/"…"` — so a browser
34
+ * holding the exact bytes re-downloaded them anyway, which is most of what the
35
+ * validator exists to prevent. Written here rather than imported because aurora
36
+ * does not depend on ream; the same function lives in `ream/src/http/etag.ts`.
37
+ */
38
+ function matchesIfNoneMatch(header, tag) {
39
+ if (header === undefined || header === "" || tag === "")
40
+ return false;
41
+ // `*` means "any current representation", so a stored copy always matches.
42
+ if (header.trim() === "*")
43
+ return true;
44
+ const bare = (value) => value.startsWith("W/") ? value.slice(2) : value;
45
+ const current = bare(tag);
46
+ return header
47
+ .split(",")
48
+ .some((candidate) => bare(candidate.trim()) === current);
49
+ }
28
50
  const CONTENT_TYPES = {
29
51
  ".js": "text/javascript; charset=utf-8",
30
52
  ".mjs": "text/javascript; charset=utf-8",
@@ -98,9 +120,25 @@ export function serveAssets(options) {
98
120
  ctx.response.status(404).send("asset not found");
99
121
  return;
100
122
  }
123
+ // A validator, so a cached copy can be CHECKED rather than only trusted
124
+ // for a fixed time. Without one an edited module was served stale for
125
+ // the whole TTL with no way for the browser to ask whether it changed —
126
+ // in development that is a source file, and the answer is usually yes.
127
+ //
128
+ // Hashed from the bytes actually being sent rather than from mtime and
129
+ // size: a checkout, a rebuild or a touched file all move the metadata
130
+ // without changing the content, and each would needlessly re-download.
131
+ const etag = `"${createHash("sha1").update(body).digest("base64url")}"`;
101
132
  const type = CONTENT_TYPES[extname(canonicalAbsolute)] ?? "application/octet-stream";
102
133
  ctx.response.header("content-type", type);
103
134
  ctx.response.header("cache-control", cacheControl);
135
+ ctx.response.header("etag", etag);
136
+ if (matchesIfNoneMatch(ctx.request.header?.("if-none-match"), etag)) {
137
+ // 304 carries no body, and must not: the browser reuses the copy it
138
+ // already has.
139
+ ctx.response.status(304).send("");
140
+ return;
141
+ }
104
142
  ctx.response.send(body);
105
143
  };
106
144
  }
package/dist/server.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import "./augmentations.js";
2
2
  export { AuroraManager, type AuroraManagerConfig } from "./AuroraManager.js";
3
+ export { AuroraError, type AuroraErrorCode } from "./errors.js";
3
4
  export { type AuroraRequestRenderer, auroraContext, } from "./middleware.js";
4
- export { type PageFactory, Pages, type PagesConfig } from "./Pages.js";
5
+ export { type PageFactory, Pages, type PagesConfig,
6
+ /** @internal classification seam, asserted by the tests */
7
+ pageImportError, } from "./Pages.js";
5
8
  export { type RenderHttpContext, type RenderPageOptions, type RenderResponse, renderPage, type SharedProps, type SharedPropsResolver, } from "./server/renderPage.js";
6
9
  export { type AssetsHttpContext, type AssetsRequest, type AssetsResponse, packageAssetDir, type ServeAssetsOptions, serveAssets, } from "./server/serveAssets.js";
package/dist/server.js CHANGED
@@ -11,7 +11,10 @@
11
11
  // source into every consumer's program — including ones that never use it.
12
12
  import "./augmentations.js";
13
13
  export { AuroraManager } from "./AuroraManager.js";
14
+ export { AuroraError } from "./errors.js";
14
15
  export { auroraContext, } from "./middleware.js";
15
- export { Pages } from "./Pages.js";
16
+ export { Pages,
17
+ /** @internal classification seam, asserted by the tests */
18
+ pageImportError, } from "./Pages.js";
16
19
  export { renderPage, } from "./server/renderPage.js";
17
20
  export { packageAssetDir, serveAssets, } from "./server/serveAssets.js";
@@ -9,6 +9,7 @@
9
9
  * `() => import('@c9up/aurora/provider')`) or by the app itself via
10
10
  * `setAurora(myManager)`.
11
11
  */
12
+ import { AuroraError } from "../errors.js";
12
13
  let instance;
13
14
  /** @internal Bind the singleton (called by AuroraProvider or by the app). */
14
15
  export function setAurora(value) {
@@ -41,7 +42,7 @@ const aurora = new Proxy({}, {
41
42
  return undefined;
42
43
  }
43
44
  if (!instance) {
44
- throw new Error("[aurora] AuroraManager singleton accessed before AuroraProvider.boot() ran " +
45
+ throw new AuroraError("E_AURORA_NOT_BOOTED", "[aurora] AuroraManager singleton accessed before AuroraProvider.boot() ran " +
45
46
  "or `setAurora(myManager)` was called. Wire one of them first.");
46
47
  }
47
48
  const value = Reflect.get(instance, prop, instance);
package/dist/url.js CHANGED
@@ -16,6 +16,7 @@
16
16
  * injects the same map into the page so the hydrate bootstrap re-sets it client
17
17
  * side. Node-free — part of aurora's client runtime.
18
18
  */
19
+ import { AuroraError } from "./errors.js";
19
20
  let manifest = {};
20
21
  let routeManifestReader;
21
22
  /**
@@ -51,7 +52,7 @@ export function urlFor(name, params, query) {
51
52
  const pattern = routes[name];
52
53
  if (pattern === undefined) {
53
54
  const known = Object.keys(routes);
54
- throw new Error(`[aurora] urlFor: unknown route '${name}'. ${known.length > 0
55
+ throw new AuroraError("E_AURORA_UNKNOWN_ROUTE", `[aurora] urlFor: unknown route '${name}'. ${known.length > 0
55
56
  ? `Known: ${known.join(", ")}`
56
57
  : "No routes registered — was the manifest passed to render() / setRouteManifest() called?"}`);
57
58
  }
@@ -67,7 +68,7 @@ export function urlFor(name, params, query) {
67
68
  url = url.replace(/\/:[A-Za-z_][\w]*\?/g, "");
68
69
  const missing = url.match(/:[A-Za-z_][\w]*/g);
69
70
  if (missing && missing.length > 0) {
70
- throw new Error(`[aurora] urlFor: route '${name}' is missing params ${missing.join(", ")}`);
71
+ throw new AuroraError("E_AURORA_MISSING_ROUTE_PARAMS", `[aurora] urlFor: route '${name}' is missing params ${missing.join(", ")}`);
71
72
  }
72
73
  if (query) {
73
74
  const qs = Object.entries(query)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c9up/aurora",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Aurora — reactive UI runtime for the Ream framework. Tagged-template DOM, signal-based state, isomorphic SSR + hydration, zero build step.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,6 +40,9 @@
40
40
  "import": "./dist/rpc.js"
41
41
  }
42
42
  },
43
+ "engines": {
44
+ "node": ">=22.0.0"
45
+ },
43
46
  "peerDependencies": {
44
47
  "@c9up/comet": "^0.1.0",
45
48
  "@c9up/ream": "^0.2.0"
@@ -53,17 +56,17 @@
53
56
  }
54
57
  },
55
58
  "devDependencies": {
56
- "@biomejs/biome": "^2.4.10",
59
+ "@biomejs/biome": "^2.5.12",
57
60
  "@c9up/comet": "^0.1.0",
58
- "@types/node": "^22.19.15",
61
+ "@c9up/ream": "^0.2.0",
62
+ "@types/node": "^22.20.1",
59
63
  "@vitest/browser": "4.1.11",
60
64
  "@vitest/browser-playwright": "4.1.11",
61
- "@vitest/coverage-v8": "4.1.9",
65
+ "@vitest/coverage-v8": "4.1.11",
62
66
  "jsdom": "^30.0.1",
63
- "playwright": "^1.61.1",
64
- "typescript": "^6.0.2",
65
- "vitest": "4.1.9",
66
- "@c9up/ream": "^0.2.0"
67
+ "playwright": "^1.63.0",
68
+ "typescript": "^6.0.3",
69
+ "vitest": "4.1.11"
67
70
  },
68
71
  "files": [
69
72
  "LICENSE",
@@ -209,9 +209,20 @@ export class AuroraManager {
209
209
  /**
210
210
  * Handler for the app's pages directory. Mount on
211
211
  * `GET /__assets/pages/*`.
212
+ *
213
+ * `no-cache` while developing — which does NOT mean "do not cache", it
214
+ * means "always ask". These are source files: served with the default
215
+ * 60-second TTL and no validator, an edited page was handed back stale for
216
+ * a minute with no way for the browser even to enquire. The ETag makes the
217
+ * question cheap; production keeps the TTL.
212
218
  */
213
219
  pageAssetsHandler(): (ctx: AssetsHttpContext) => Promise<void> {
214
- return serveAssets({ root: this.pages.root });
220
+ return serveAssets({
221
+ root: this.pages.root,
222
+ ...(process.env.NODE_ENV === "production"
223
+ ? {}
224
+ : { cacheControl: "no-cache" }),
225
+ });
215
226
  }
216
227
 
217
228
  /**
@@ -83,8 +83,11 @@ export default class AuroraProvider {
83
83
  }
84
84
 
85
85
  async start(): Promise<void> {
86
- // Asset routes are registered in `start()` after preloads — so apps can
87
- // swap aurora's pages root in a preload if they wanted to.
86
+ // Asset routes are registered in `start()`, which runs BEFORE the
87
+ // preloads providers start, then the `starting` hooks, then the
88
+ // preloads are imported. An earlier version of this comment claimed the
89
+ // opposite; an app that wanted to swap aurora's pages root has to do it
90
+ // from a provider, not from a preload.
88
91
  //
89
92
  // Resolve the host router from the container, where Ream registers it as
90
93
  // `'router'` (Ignitor). Reading it from the container — instead of