@cloudhal/astro-renderer 0.2.0 → 0.3.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.
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { SqlCommentStore } from "@cloudhal/comments/sql";
12
12
  import type { Site } from "@cloudhal/core-contracts";
13
- import { type AiSearchEnv } from "@cloudhal/core-ts";
13
+ import { type AiSearchEnv, SiteGraphStore } from "@cloudhal/core-ts";
14
14
  import type { SqlDriver } from "@cloudhal/storage";
15
15
  import type { CloudhalRendererConfig } from "./integration.js";
16
16
  import type { PeerEdition } from "./locales.js";
@@ -36,6 +36,8 @@ export interface AstroLike {
36
36
  }
37
37
  /** Runs `fn` (and everything it awaits) as a request for `siteId`. */
38
38
  export declare function withRequestSite<T>(siteId: string, fn: () => T): T;
39
+ /** Runs `fn` (and everything it awaits) as a request for `siteId` over `store`. */
40
+ export declare function withRequestStore<T>(store: SiteGraphStore, siteId: string, fn: () => T): T;
39
41
  /** Test/purge hook: forget cached state in this isolate, for one site or all of them. */
40
42
  export declare function resetSource(siteId?: string): void;
41
43
  /**
@@ -56,9 +56,46 @@ export function withRequestSite (siteId , fn ) {
56
56
  return requestSite.run(siteId, fn);
57
57
  }
58
58
 
59
+ /**
60
+ * RFC-0036 §4: a store the entry chose for this request — a playground session's own database in
61
+ * its Durable Object — instead of the D1/R2 bindings. Its pages are private: never edge-cached and
62
+ * never tagged.
63
+ */
64
+ const requestStore = new AsyncLocalStorage ();
65
+ const storeResolvers = new WeakMap ();
66
+
67
+ /** Runs `fn` (and everything it awaits) as a request for `siteId` over `store`. */
68
+ export function withRequestStore (store , siteId , fn ) {
69
+ return requestStore.run({ store, siteId }, fn);
70
+ }
71
+
59
72
  /** The request's site: the entry's choice, else `CLOUDHAL_SITE_ID`, else the build's. */
60
73
  function siteOf(fallback ) {
61
- return requestSite.getStore() ?? (env ).CLOUDHAL_SITE_ID ?? fallback;
74
+ return (
75
+ requestStore.getStore()?.siteId ??
76
+ requestSite.getStore() ??
77
+ (env ).CLOUDHAL_SITE_ID ??
78
+ fallback
79
+ );
80
+ }
81
+
82
+ /** The resolver over the request's own store (`withRequestStore`), one per store. */
83
+ function scopedResolver(siteId ) {
84
+ const scoped = requestStore.getStore();
85
+ if (!scoped || scoped.siteId !== siteId) return undefined;
86
+ let resolver = storeResolvers.get(scoped.store);
87
+ if (!resolver) {
88
+ resolver = new SiteResolver({
89
+ store: scoped.store,
90
+ siteId,
91
+ pointerTtlMs: 0,
92
+ previewCookie: false,
93
+ // The store lives in the caller's Durable Object, which outlives the response.
94
+ persistBundle: (task) => void task.catch(() => {}),
95
+ });
96
+ storeResolvers.set(scoped.store, resolver);
97
+ }
98
+ return resolver;
62
99
  }
63
100
 
64
101
  /** One resolver per site the isolate has served (pointer, snapshot and bundle caches). */
@@ -78,6 +115,8 @@ function siteStore(e ) {
78
115
  }
79
116
 
80
117
  function getResolver(siteId ) {
118
+ const scoped = scopedResolver(siteId);
119
+ if (scoped) return scoped;
81
120
  const e = env ;
82
121
  const known = resolvers.get(siteId);
83
122
  if (known) return known;
@@ -215,6 +254,15 @@ export async function getSource(
215
254
  h.set("x-cloudhal-mode", "unpublished");
216
255
  return undefined;
217
256
  }
257
+ if (requestStore.getStore()) {
258
+ // RFC-0036 §4: a session's page is the session's alone.
259
+ h.set("cache-control", "private, no-store");
260
+ h.set("cloudflare-cdn-cache-control", "no-store");
261
+ h.set("x-robots-tag", "noindex");
262
+ h.set("x-cloudhal-mode", "published");
263
+ h.set("x-cloudhal-snapshot", resolution.snapshotId);
264
+ return resolution.source;
265
+ }
218
266
  // Published: browsers revalidate, the edge keeps it until a publish purges the tag — or, when a
219
267
  // time gate lies ahead, until that gate (RFC-0008 §7.4): any page may list any entry, so the
220
268
  // cap is site-wide and a gate needs no purge.
@@ -1,5 +1,6 @@
1
1
  import { SqlCommentStore } from "@cloudhal/comments/sql";
2
2
  import type { Site } from "@cloudhal/core-contracts";
3
+ import type { SiteGraphStore } from "@cloudhal/core-ts";
3
4
  import type { SqlDriver } from "@cloudhal/storage";
4
5
  import type { CloudhalRendererConfig } from "./integration.js";
5
6
  import type { PeerEdition } from "./locales.js";
@@ -24,6 +25,11 @@ export declare function resetSource(_siteId?: string): void;
24
25
  * serves the project's one site, so this only runs `fn`.
25
26
  */
26
27
  export declare function withRequestSite<T>(_siteId: string, fn: () => T): T;
28
+ /**
29
+ * RFC-0036 §4: on workerd a playground runs each request over its session's store; `cloudhal dev`
30
+ * renders from the project's local store, so this only runs `fn`.
31
+ */
32
+ export declare function withRequestStore<T>(_store: SiteGraphStore, _siteId: string, fn: () => T): T;
27
33
  /**
28
34
  * RFC-0034 §6: other sites' published versions of a work. `cloudhal dev` renders the project's one
29
35
  * site from its local store, so there are none.
@@ -1,5 +1,6 @@
1
1
  import { SqlCommentStore } from "@cloudhal/comments/sql";
2
2
 
3
+
3
4
  import { openLocalStore } from "@cloudhal/core-ts/local";
4
5
 
5
6
 
@@ -57,6 +58,14 @@ export function withRequestSite (_siteId , fn ) {
57
58
  return fn();
58
59
  }
59
60
 
61
+ /**
62
+ * RFC-0036 §4: on workerd a playground runs each request over its session's store; `cloudhal dev`
63
+ * renders from the project's local store, so this only runs `fn`.
64
+ */
65
+ export function withRequestStore (_store , _siteId , fn ) {
66
+ return fn();
67
+ }
68
+
60
69
  /**
61
70
  * RFC-0034 §6: other sites' published versions of a work. `cloudhal dev` renders the project's one
62
71
  * site from its local store, so there are none.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/astro-renderer",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Render a Cloudhal Site Graph with Astro: data sources (live/snapshot), section components and the cloudhal() integration",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://cloudhal.dev",
@@ -179,14 +179,14 @@
179
179
  "README.md"
180
180
  ],
181
181
  "dependencies": {
182
- "@cloudhal/core-contracts": "0.2.0",
183
- "@cloudhal/core-ts": "0.2.0",
184
- "@cloudhal/storage": "0.2.0",
182
+ "@cloudhal/core-contracts": "0.3.0",
183
+ "@cloudhal/core-ts": "0.3.0",
184
+ "@cloudhal/storage": "0.3.0",
185
185
  "marked": "^18.1.0",
186
186
  "parse5": "8.0.1",
187
- "@cloudhal/analytics": "0.2.0",
187
+ "@cloudhal/analytics": "0.3.0",
188
188
  "vite": "^8.3.3",
189
- "@cloudhal/comments": "0.2.0"
189
+ "@cloudhal/comments": "0.3.0"
190
190
  },
191
191
  "peerDependencies": {
192
192
  "astro": "^7.3.0",