@fungi.computer/oyster 0.52.0 → 0.52.2

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.
@@ -0,0 +1,5 @@
1
+ import type { HostPageOptions } from "./host-page.js";
2
+ /** Render one host page, loading the renderer on first use. */
3
+ export declare function renderHostPage(options: HostPageOptions): Promise<Response>;
4
+ /** Serve one content-addressed host page asset, loading the renderer on first use. */
5
+ export declare function serveHostPageAsset(path: string): Promise<Response>;
@@ -0,0 +1,15 @@
1
+ import { loadLazily } from "./lazy-import.js";
2
+ // The page renderer brings React's server renderer, the Caps components and
3
+ // their animation library. Only a request that renders a page needs them, so
4
+ // Worker startup does not evaluate them; the first page loads them.
5
+ const renderer = "Oyster's host page renderer";
6
+ /** Render one host page, loading the renderer on first use. */
7
+ export async function renderHostPage(options) {
8
+ const render = await loadLazily(() => import("./host-page.js").then(({ hostPage }) => hostPage), renderer);
9
+ return render(options);
10
+ }
11
+ /** Serve one content-addressed host page asset, loading the renderer on first use. */
12
+ export async function serveHostPageAsset(path) {
13
+ const serve = await loadLazily(() => import("./host-page.js").then(({ hostPageAsset }) => hostPageAsset), renderer);
14
+ return serve(path);
15
+ }
package/dist/host.js CHANGED
@@ -40,7 +40,7 @@ import { buildGitPassPrefix, presentedGitKey } from "./git-auth.js";
40
40
  import { workflowGitPassPrefix } from "@fungi.computer/braid/runtime";
41
41
  import { loadPageAssets, PageAssetsLoadError, } from "./page-assets.js";
42
42
  import { fungiFaviconHref } from "@fungi.computer/sigils/favicon";
43
- import { hostPage, hostPageAsset } from "./host-page.js";
43
+ import { renderHostPage, serveHostPageAsset } from "./host-page-lazy.js";
44
44
  import { parseAccept } from "hono/utils/accept";
45
45
  import { parseArtifactRef } from "@fungi.computer/puffball";
46
46
  import { isBuildJobLogRef } from "./build/job-log.js";
@@ -377,14 +377,14 @@ export function oysterRouteTable(host) {
377
377
  });
378
378
  const page = async (state, options = {}) => {
379
379
  const { loginFonts, styles } = await assets();
380
- return hostPage({
380
+ return renderHostPage({
381
381
  state,
382
382
  title,
383
383
  stylesheets: [styles.path, loginFonts.path],
384
384
  ...options,
385
385
  });
386
386
  };
387
- table.get("/_oyster/host-assets/*", publicRoute("content-addressed host illustrations and layout"), (context) => hostPageAsset(new URL(context.req.url).pathname));
387
+ table.get("/_oyster/host-assets/*", publicRoute("content-addressed host illustrations and layout"), (context) => serveHostPageAsset(new URL(context.req.url).pathname));
388
388
  table.get("/login", publicRoute("the sign-in form"), (context) => page("login", {
389
389
  returning: getCookie(context, returningCookieName) === "1",
390
390
  usedLink: context.req.query("link") === "used",
@@ -1114,7 +1114,7 @@ export function oysterRouteTable(host) {
1114
1114
  headers: { "Cache-Control": "no-store" },
1115
1115
  });
1116
1116
  const pageAssets = await assets();
1117
- const response = await hostPage({
1117
+ const response = await renderHostPage({
1118
1118
  state: "permissions",
1119
1119
  title,
1120
1120
  stylesheets: [pageAssets.loginFonts.path, pageAssets.styles.path],
@@ -1610,7 +1610,11 @@ export function oysterRouteTable(host) {
1610
1610
  if (!(cause instanceof PageAssetsLoadError))
1611
1611
  throw cause;
1612
1612
  console.error("Host page assets unavailable; serving recovery document", cause);
1613
- rendered = await hostPage({ state, title, status: response.status });
1613
+ rendered = await renderHostPage({
1614
+ state,
1615
+ title,
1616
+ status: response.status,
1617
+ });
1614
1618
  }
1615
1619
  // Keep timing, robots and retry metadata from the original refusal.
1616
1620
  response.headers.forEach((value, name) => {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Load a module on first use. A failed load (a missing chunk, a corrupt
3
+ * bundle) is reported as the feature that could not start, with the loader's
4
+ * own error as the cause, instead of a bare module-resolution message.
5
+ */
6
+ export declare function loadLazily<Loaded>(load: () => Promise<Loaded>, what: string): Promise<Loaded>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Load a module on first use. A failed load (a missing chunk, a corrupt
3
+ * bundle) is reported as the feature that could not start, with the loader's
4
+ * own error as the cause, instead of a bare module-resolution message.
5
+ */
6
+ export async function loadLazily(load, what) {
7
+ try {
8
+ return await load();
9
+ }
10
+ catch (cause) {
11
+ throw new Error(`${what} failed to load`, { cause });
12
+ }
13
+ }