@ogygia/postrender 0.12.0 → 0.14.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.
@@ -1,87 +1,102 @@
1
1
  import { normalize_prefix, subtree_prefix } from "../key.js";
2
+ import { OgygiaError } from "../messages.js";
3
+ import { net } from "@ogygia/machine";
2
4
  // src/adapters/upstash.ts
3
5
  const GLOB_ACTIVE_G = /[*?[\]\\]/g;
4
6
  const TRAILING_SLASHES_RE = /\/+$/;
5
7
  const KEY_NS = "og:a:";
6
8
  const TAG_NS = "og:t:";
7
9
  const SCAN_COUNT = 250;
8
- /** Escape glob-active characters so a literal pathname can ride a SCAN MATCH pattern. */
9
10
  function glob_escape(value) {
10
- return value.replace(GLOB_ACTIVE_G, (c) => "\\" + c);
11
+ return value.replace(GLOB_ACTIVE_G, (c) => `\\${c}`);
11
12
  }
12
- function upstash(config) {
13
- const base = config.url.replace(TRAILING_SLASHES_RE, "");
13
+ /**
14
+ * A store on Upstash Redis over its REST API: no client library and no connection, every command
15
+ * is one HTTPS call, which suits serverless and edge origins. The same keys as `ValkeyStore`.
16
+ *
17
+ * postrender.handle({ store: new UpstashStore({ url: env.UPSTASH_REDIS_REST_URL,
18
+ * token: env.UPSTASH_REDIS_REST_TOKEN }) })
19
+ */
20
+ var UpstashStore = class {
21
+ #base;
22
+ #token;
23
+ constructor(config) {
24
+ this.#base = config.url.replace(TRAILING_SLASHES_RE, "");
25
+ this.#token = config.token;
26
+ }
27
+ async get(key) {
28
+ const raw = await this.#command(["GET", KEY_NS + key]);
29
+ if (!raw) return null;
30
+ try {
31
+ return JSON.parse(raw);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+ async put(key, entry, { ttl, tags }) {
37
+ await this.#command([
38
+ "SET",
39
+ KEY_NS + key,
40
+ JSON.stringify(entry),
41
+ "EX",
42
+ ttl
43
+ ]);
44
+ for (const tag of tags ?? []) {
45
+ await this.#command([
46
+ "SADD",
47
+ TAG_NS + tag,
48
+ key
49
+ ]);
50
+ if (await this.#command(["TTL", TAG_NS + tag]) < ttl) await this.#command([
51
+ "EXPIRE",
52
+ TAG_NS + tag,
53
+ ttl
54
+ ]);
55
+ }
56
+ }
57
+ async evict(key) {
58
+ await this.#command(["DEL", KEY_NS + key]);
59
+ }
60
+ async evictWhere({ prefix }) {
61
+ const p = normalize_prefix(prefix);
62
+ const pattern = `${glob_escape(KEY_NS + subtree_prefix(p))}*`;
63
+ let cursor = "0";
64
+ do {
65
+ const reply = await this.#command([
66
+ "SCAN",
67
+ cursor,
68
+ "MATCH",
69
+ pattern,
70
+ "COUNT",
71
+ SCAN_COUNT
72
+ ]);
73
+ cursor = String(reply[0]);
74
+ if (reply[1]?.length) await this.#command(["DEL", ...reply[1]]);
75
+ } while (cursor !== "0");
76
+ await this.#command(["DEL", KEY_NS + p]);
77
+ }
78
+ async evictByTag(tag) {
79
+ const members = await this.#command(["SMEMBERS", TAG_NS + tag]);
80
+ if (members.length) await this.#command(["DEL", ...members.map((m) => KEY_NS + m)]);
81
+ await this.#command(["DEL", TAG_NS + tag]);
82
+ return members;
83
+ }
14
84
  /** One command, Upstash REST shape: POST the command as a JSON array → `{ result }`. */
15
- const command = async (parts) => {
16
- const res = await fetch(base, {
85
+ async #command(parts) {
86
+ const res = await net.fetch(this.#base, {
17
87
  method: "POST",
18
88
  headers: {
19
- authorization: `Bearer ${config.token}`,
89
+ authorization: `Bearer ${this.#token}`,
20
90
  "content-type": "application/json"
21
91
  },
22
92
  body: JSON.stringify(parts.map(String))
23
93
  });
24
- if (!res.ok) throw new Error(`[ogygia] upstash command failed: ${res.status} ${await res.text().catch(() => "")}`);
94
+ if (!res.ok) throw new OgygiaError("postrender_adapter_request_failed", {
95
+ what: "upstash command",
96
+ status: res.status,
97
+ body: await res.text().catch(() => "")
98
+ });
25
99
  return (await res.json()).result;
26
- };
27
- return {
28
- async get(key) {
29
- const raw = await command(["GET", KEY_NS + key]);
30
- if (!raw) return null;
31
- try {
32
- return JSON.parse(raw);
33
- } catch {
34
- return null;
35
- }
36
- },
37
- async put(key, entry, { ttl, tags }) {
38
- await command([
39
- "SET",
40
- KEY_NS + key,
41
- JSON.stringify(entry),
42
- "EX",
43
- ttl
44
- ]);
45
- for (const tag of tags ?? []) {
46
- await command([
47
- "SADD",
48
- TAG_NS + tag,
49
- key
50
- ]);
51
- if (await command(["TTL", TAG_NS + tag]) < ttl) await command([
52
- "EXPIRE",
53
- TAG_NS + tag,
54
- ttl
55
- ]);
56
- }
57
- },
58
- async evict(key) {
59
- await command(["DEL", KEY_NS + key]);
60
- },
61
- async evictWhere({ prefix }) {
62
- const p = normalize_prefix(prefix);
63
- const pattern = glob_escape(KEY_NS + subtree_prefix(p)) + "*";
64
- let cursor = "0";
65
- do {
66
- const reply = await command([
67
- "SCAN",
68
- cursor,
69
- "MATCH",
70
- pattern,
71
- "COUNT",
72
- SCAN_COUNT
73
- ]);
74
- cursor = String(reply[0]);
75
- if (reply[1]?.length) await command(["DEL", ...reply[1]]);
76
- } while (cursor !== "0");
77
- await command(["DEL", KEY_NS + p]);
78
- },
79
- async evictByTag(tag) {
80
- const members = await command(["SMEMBERS", TAG_NS + tag]);
81
- if (members.length) await command(["DEL", ...members.map((m) => KEY_NS + m)]);
82
- await command(["DEL", TAG_NS + tag]);
83
- return members;
84
- }
85
- };
86
- }
87
- export { upstash };
100
+ }
101
+ };
102
+ export { UpstashStore };
@@ -1,4 +1,4 @@
1
- import { PostrenderStore } from "../types.js";
1
+ import { PostrenderEntry, PostrenderPutOptions, PostrenderStore } from "../types.js";
2
2
  /** The minimal client surface — ioredis (lowercase) and node-redis v4 (camelCase) both satisfy
3
3
  * it structurally; the camelCase variants are probed at call time. */
4
4
  export interface ValkeyLike {
@@ -15,4 +15,21 @@ export interface ValkeyLike {
15
15
  ttl?(key: string): Promise<number>;
16
16
  TTL?(key: string): Promise<number>;
17
17
  }
18
- export declare function valkey(client: ValkeyLike): PostrenderStore;
18
+ /**
19
+ * A store on Valkey or Redis, with the app's own client (ioredis and node-redis v4 both fit
20
+ * {@link ValkeyLike}; ogygia takes no Redis dependency). Keys are `og:a:<pathname>` with `EX` as
21
+ * the TTL backstop; prefix eviction is a cursor SCAN, so no index can drift. Each `og.source` tag
22
+ * is a SET of pathnames whose expiry a put only ever extends, to the longest lifetime among its
23
+ * members.
24
+ */
25
+ export declare class ValkeyStore implements PostrenderStore {
26
+ #private;
27
+ constructor(client: ValkeyLike);
28
+ get(key: string): Promise<PostrenderEntry | null>;
29
+ put(key: string, entry: PostrenderEntry, { ttl, tags }: PostrenderPutOptions): Promise<void>;
30
+ evict(key: string): Promise<void>;
31
+ evictWhere({ prefix }: {
32
+ prefix: string;
33
+ }): Promise<void>;
34
+ evictByTag(tag: string): Promise<string[]>;
35
+ }
@@ -1,10 +1,10 @@
1
1
  import { normalize_prefix, subtree_prefix } from "../key.js";
2
+ import { OgygiaError } from "../messages.js";
2
3
  // src/adapters/valkey.ts
3
4
  const GLOB_ACTIVE_G = /[*?[\]\\]/g;
4
5
  const KEY_NS = "og:a:";
5
6
  const TAG_NS = "og:t:";
6
7
  const SCAN_COUNT = 250;
7
- /** Both client families' scan shapes → one { cursor, keys }. */
8
8
  function read_scan_reply(reply) {
9
9
  if (Array.isArray(reply)) return {
10
10
  cursor: String(reply[0]),
@@ -16,75 +16,94 @@ function read_scan_reply(reply) {
16
16
  keys: obj.keys ?? []
17
17
  };
18
18
  }
19
- /** Escape glob-active characters so a literal pathname can ride a SCAN MATCH pattern. */
20
19
  function glob_escape(value) {
21
- return value.replace(GLOB_ACTIVE_G, (c) => "\\" + c);
20
+ return value.replace(GLOB_ACTIVE_G, (c) => `\\${c}`);
22
21
  }
23
- function valkey(client) {
24
- const set_with_ttl = async (key, value, ttl) => {
22
+ /**
23
+ * A store on Valkey or Redis, with the app's own client (ioredis and node-redis v4 both fit
24
+ * {@link ValkeyLike}; ogygia takes no Redis dependency). Keys are `og:a:<pathname>` with `EX` as
25
+ * the TTL backstop; prefix eviction is a cursor SCAN, so no index can drift. Each `og.source` tag
26
+ * is a SET of pathnames whose expiry a put only ever extends, to the longest lifetime among its
27
+ * members.
28
+ */
29
+ var ValkeyStore = class {
30
+ #client;
31
+ constructor(client) {
32
+ this.#client = client;
33
+ }
34
+ async get(key) {
35
+ const raw = await this.#client.get(KEY_NS + key);
36
+ if (!raw) return null;
25
37
  try {
26
- await client.set(key, value, "EX", ttl);
38
+ return JSON.parse(raw);
27
39
  } catch {
28
- await client.set(key, value, { EX: ttl });
40
+ return null;
29
41
  }
30
- };
31
- const sadd = async (key, member) => {
42
+ }
43
+ async put(key, entry, { ttl, tags }) {
44
+ await this.#set_with_ttl(KEY_NS + key, JSON.stringify(entry), ttl);
45
+ for (const tag of tags ?? []) {
46
+ await this.#sadd(TAG_NS + tag, key);
47
+ const left = await this.#read_ttl(TAG_NS + tag);
48
+ if (left === null || left < ttl) await this.#client.expire?.(TAG_NS + tag, ttl);
49
+ }
50
+ }
51
+ async evict(key) {
52
+ await this.#client.del(KEY_NS + key);
53
+ }
54
+ async evictWhere({ prefix }) {
55
+ const client = this.#client;
56
+ const p = normalize_prefix(prefix);
57
+ await this.#scan_prefix(subtree_prefix(p), async (keys) => void await client.del(...keys));
58
+ await client.del(KEY_NS + p);
59
+ }
60
+ async evictByTag(tag) {
61
+ const client = this.#client;
62
+ const members = await this.#smembers(TAG_NS + tag);
63
+ if (members.length) await client.del(...members.map((m) => KEY_NS + m));
64
+ await client.del(TAG_NS + tag);
65
+ return members;
66
+ }
67
+ async #set_with_ttl(key, value, ttl) {
68
+ try {
69
+ await this.#client.set(key, value, "EX", ttl);
70
+ } catch {
71
+ await this.#client.set(key, value, { EX: ttl });
72
+ }
73
+ }
74
+ async #sadd(key, member) {
75
+ const client = this.#client;
32
76
  if (client.sadd) await client.sadd(key, member);
33
77
  else if (client.sAdd) await client.sAdd(key, member);
34
- else throw new Error("[ogygia] valkey client has no sadd/sAdd — og.source tags need it");
35
- };
36
- const smembers = async (key) => {
78
+ else throw new OgygiaError("postrender_store_client_missing", {
79
+ client: "valkey",
80
+ commands: "sadd/sAdd"
81
+ });
82
+ }
83
+ async #smembers(key) {
84
+ const client = this.#client;
37
85
  if (client.smembers) return client.smembers(key);
38
86
  if (client.sMembers) return client.sMembers(key);
39
- throw new Error("[ogygia] valkey client has no smembers/sMembers — og.source tags need it");
40
- };
87
+ throw new OgygiaError("postrender_store_client_missing", {
88
+ client: "valkey",
89
+ commands: "smembers/sMembers"
90
+ });
91
+ }
41
92
  /** Seconds left on a key (-1 = no expiry), or null when the client has no TTL command. */
42
- const read_ttl = async (key) => {
93
+ async #read_ttl(key) {
94
+ const client = this.#client;
43
95
  if (client.ttl) return Number(await client.ttl(key));
44
96
  if (client.TTL) return Number(await client.TTL(key));
45
97
  return null;
46
- };
47
- const scan_prefix = async (prefix, on_keys) => {
48
- const pattern = glob_escape(KEY_NS + prefix) + "*";
98
+ }
99
+ async #scan_prefix(prefix, on_keys) {
100
+ const pattern = `${glob_escape(KEY_NS + prefix)}*`;
49
101
  let cursor = "0";
50
102
  do {
51
- const page = read_scan_reply(await client.scan(cursor, "MATCH", pattern, "COUNT", SCAN_COUNT));
103
+ const page = read_scan_reply(await this.#client.scan(cursor, "MATCH", pattern, "COUNT", SCAN_COUNT));
52
104
  cursor = page.cursor;
53
105
  if (page.keys.length) await on_keys(page.keys);
54
106
  } while (cursor !== "0");
55
- };
56
- return {
57
- async get(key) {
58
- const raw = await client.get(KEY_NS + key);
59
- if (!raw) return null;
60
- try {
61
- return JSON.parse(raw);
62
- } catch {
63
- return null;
64
- }
65
- },
66
- async put(key, entry, { ttl, tags }) {
67
- await set_with_ttl(KEY_NS + key, JSON.stringify(entry), ttl);
68
- for (const tag of tags ?? []) {
69
- await sadd(TAG_NS + tag, key);
70
- const left = await read_ttl(TAG_NS + tag);
71
- if (left === null || left < ttl) await client.expire?.(TAG_NS + tag, ttl);
72
- }
73
- },
74
- async evict(key) {
75
- await client.del(KEY_NS + key);
76
- },
77
- async evictWhere({ prefix }) {
78
- const p = normalize_prefix(prefix);
79
- await scan_prefix(subtree_prefix(p), async (keys) => void await client.del(...keys));
80
- await client.del(KEY_NS + p);
81
- },
82
- async evictByTag(tag) {
83
- const members = await smembers(TAG_NS + tag);
84
- if (members.length) await client.del(...members.map((m) => KEY_NS + m));
85
- await client.del(TAG_NS + tag);
86
- return members;
87
- }
88
- };
89
- }
90
- export { valkey };
107
+ }
108
+ };
109
+ export { ValkeyStore };
package/dist/app.js CHANGED
@@ -1,9 +1,14 @@
1
+ import { slot } from "@ogygia/machine";
1
2
  // src/app.ts
2
- const slot = globalThis[Symbol.for("ogygia.postrender.app.v1")] ??= { app: null };
3
+ const slot$1 = slot({
4
+ name: "ogygia.postrender.app",
5
+ version: 1,
6
+ make: () => ({ app: null })
7
+ });
3
8
  function set_postrender_app(app) {
4
- slot.app = app;
9
+ slot$1.app = app;
5
10
  }
6
11
  function postrender_app() {
7
- return slot.app;
12
+ return slot$1.app;
8
13
  }
9
14
  export { postrender_app, set_postrender_app };
package/dist/handle.d.ts CHANGED
@@ -1,3 +1,19 @@
1
1
  import { PostrenderHandleOptions } from "./types.js";
2
2
  import { Handle } from "@ogygia/core/plugin";
3
+ /**
4
+ * The live half of postrender, a Kit handle that goes BEFORE ogygia's:
5
+ *
6
+ * ```ts
7
+ * export const handle = sequence(
8
+ * postrender.handle({ store: new ValkeyStore(client), edge: [new CloudflareEdge({ … })] }),
9
+ * ogygia.handle()
10
+ * );
11
+ * ```
12
+ *
13
+ * Made once, when hooks.server.ts evaluates: its settings become this server's runtime, the one
14
+ * `postrender.invalidate()` reaches. Per request it hands the request those settings, so ogygia's
15
+ * handle serves the stored page before anything renders. Placed after ogygia's (or outside the
16
+ * sequence), that is an error in dev and one warning in production; with no `postrender()` in
17
+ * vite.config, nothing is ever stored, and it warns once.
18
+ */
3
19
  export declare function handle(options?: PostrenderHandleOptions): Handle;
package/dist/handle.js CHANGED
@@ -1,15 +1,30 @@
1
1
  import { install, mark_handled } from "./registry.js";
2
2
  import { postrender_app } from "./app.js";
3
+ import { warn } from "./messages.js";
4
+ import { say } from "@ogygia/machine";
3
5
  // src/handle.ts
4
- let warned_unlisted = false;
6
+ const unlisted = say({ max: 1 });
7
+ /**
8
+ * The live half of postrender, a Kit handle that goes BEFORE ogygia's:
9
+ *
10
+ * ```ts
11
+ * export const handle = sequence(
12
+ * postrender.handle({ store: new ValkeyStore(client), edge: [new CloudflareEdge({ … })] }),
13
+ * ogygia.handle()
14
+ * );
15
+ * ```
16
+ *
17
+ * Made once, when hooks.server.ts evaluates: its settings become this server's runtime, the one
18
+ * `postrender.invalidate()` reaches. Per request it hands the request those settings, so ogygia's
19
+ * handle serves the stored page before anything renders. Placed after ogygia's (or outside the
20
+ * sequence), that is an error in dev and one warning in production; with no `postrender()` in
21
+ * vite.config, nothing is ever stored, and it warns once.
22
+ */
5
23
  function handle(options = {}) {
6
24
  const runtime = install(options);
7
25
  return ({ event, resolve }) => {
8
26
  mark_handled(event, runtime);
9
- if (!postrender_app() && !warned_unlisted) {
10
- warned_unlisted = true;
11
- console.warn("[@ogygia/postrender] postrender.handle() runs, but `postrender()` is not listed in vite.config, so no page is stored. Add it: `plugins: [ogygia(), postrender(), sveltekit()]` (from '@ogygia/postrender/vite').");
12
- }
27
+ if (!postrender_app()) unlisted.once("postrender_handle_unlisted", () => warn("postrender_handle_unlisted"));
13
28
  return resolve(event);
14
29
  };
15
30
  }
package/dist/index.d.ts CHANGED
@@ -1,16 +1,41 @@
1
1
  import { handle } from "./handle.js";
2
2
  import { invalidate, invalidateWhere } from "./registry.js";
3
- import { memory_store } from "./memory-store.js";
4
- import { ValkeyLike, valkey } from "./adapters/valkey.js";
5
- import { UpstashConfig, upstash } from "./adapters/upstash.js";
6
- import { KvNamespaceLike, cloudflareKv } from "./adapters/cloudflare-kv.js";
7
- import { AkamaiConfig, akamai } from "./adapters/akamai.js";
8
- import { CloudfrontConfig, cloudfront } from "./adapters/cloudfront.js";
9
- import { CloudflareConfig, cloudflare } from "./adapters/cloudflare.js";
3
+ import { MemoryStore } from "./memory-store.js";
4
+ import { ValkeyLike, ValkeyStore } from "./adapters/valkey.js";
5
+ import { UpstashConfig, UpstashStore } from "./adapters/upstash.js";
6
+ import { CloudflareKvStore, KvNamespaceLike } from "./adapters/cloudflare-kv.js";
7
+ import { AkamaiConfig, AkamaiEdge } from "./adapters/akamai.js";
8
+ import { CloudFrontEdge, CloudfrontConfig } from "./adapters/cloudfront.js";
9
+ import { CloudflareConfig, CloudflareEdge } from "./adapters/cloudflare.js";
10
10
  import { EdgeAdapter, PostrenderEntry, PostrenderHandleOptions, PostrenderMeta, PostrenderPutOptions, PostrenderStore } from "./types.js";
11
+ /**
12
+ * Pages stored at request time, on the server only. Prerender renders a page at build time;
13
+ * postrender renders it on its first request, stores it whole, and serves the stored bytes until
14
+ * an invalidation clears it.
15
+ *
16
+ * ```ts
17
+ * // vite.config: the switch (+ serializable policy)
18
+ * import { postrender } from '@ogygia/postrender/vite';
19
+ * plugins: [ogygia(), postrender(), sveltekit()]
20
+ *
21
+ * // hooks.server.ts: the live store and CDN edges, BEFORE ogygia's handle
22
+ * import { postrender, ValkeyStore, AkamaiEdge } from '@ogygia/postrender';
23
+ * export const handle = sequence(
24
+ * postrender.handle({ store: new ValkeyStore(client), edge: [new AkamaiEdge(creds)] }),
25
+ * ogygia.handle()
26
+ * );
27
+ *
28
+ * // a route opts out in Kit's own config: export const config = { postrender: false };
29
+ *
30
+ * // anywhere server-side (CMS publish webhook):
31
+ * await postrender.invalidate('/fr/fr/solar/'); // exact URL
32
+ * await postrender.invalidate(loadContent, [args]); // og.source reverse index
33
+ * await postrender.invalidateWhere({ prefix: '/fr/fr/' }); // subtree nuke
34
+ * ```
35
+ */
11
36
  export declare const postrender: {
12
37
  handle: typeof handle;
13
38
  invalidate: typeof invalidate;
14
39
  invalidateWhere: typeof invalidateWhere;
15
40
  };
16
- export { type AkamaiConfig, type CloudflareConfig, type CloudfrontConfig, type EdgeAdapter, type KvNamespaceLike, type PostrenderEntry, type PostrenderHandleOptions, type PostrenderMeta, type PostrenderPutOptions, type PostrenderStore, type UpstashConfig, type ValkeyLike, akamai, cloudfront as awsCloudfront, cloudflare, cloudflareKv, cloudfront, memory_store as memoryStore, upstash, valkey };
41
+ export { type AkamaiConfig, AkamaiEdge, CloudFrontEdge, type CloudflareConfig, CloudflareEdge, CloudflareKvStore, type CloudfrontConfig, type EdgeAdapter, type KvNamespaceLike, MemoryStore, type PostrenderEntry, type PostrenderHandleOptions, type PostrenderMeta, type PostrenderPutOptions, type PostrenderStore, type UpstashConfig, UpstashStore, type ValkeyLike, ValkeyStore };
package/dist/index.js CHANGED
@@ -1,18 +1,17 @@
1
1
  import { handle } from "./handle.js";
2
2
  import { invalidate, invalidateWhere } from "./registry.js";
3
- import { memory_store } from "./memory-store.js";
4
- import { valkey } from "./adapters/valkey.js";
5
- import { upstash } from "./adapters/upstash.js";
6
- import { cloudflareKv } from "./adapters/cloudflare-kv.js";
7
- import { akamai } from "./adapters/akamai.js";
8
- import { cloudfront } from "./adapters/cloudfront.js";
9
- import { cloudflare } from "./adapters/cloudflare.js";
3
+ import { MemoryStore } from "./memory-store.js";
4
+ import { ValkeyStore } from "./adapters/valkey.js";
5
+ import { UpstashStore } from "./adapters/upstash.js";
6
+ import { CloudflareKvStore } from "./adapters/cloudflare-kv.js";
7
+ import { AkamaiEdge } from "./adapters/akamai.js";
8
+ import { CloudFrontEdge } from "./adapters/cloudfront.js";
9
+ import { CloudflareEdge } from "./adapters/cloudflare.js";
10
10
  // src/index.ts
11
11
  /**
12
- * `@ogygia/postrender` — pages stored at request time. SERVER ONLY.
13
- *
14
- * Prerender renders a page at build time; postrender renders it on its first request, stores it
15
- * whole, and serves the stored bytes until an invalidation clears it.
12
+ * Pages stored at request time, on the server only. Prerender renders a page at build time;
13
+ * postrender renders it on its first request, stores it whole, and serves the stored bytes until
14
+ * an invalidation clears it.
16
15
  *
17
16
  * ```ts
18
17
  * // vite.config: the switch (+ serializable policy)
@@ -20,9 +19,9 @@ import { cloudflare } from "./adapters/cloudflare.js";
20
19
  * plugins: [ogygia(), postrender(), sveltekit()]
21
20
  *
22
21
  * // hooks.server.ts: the live store and CDN edges, BEFORE ogygia's handle
23
- * import { postrender, valkey, akamai } from '@ogygia/postrender';
22
+ * import { postrender, ValkeyStore, AkamaiEdge } from '@ogygia/postrender';
24
23
  * export const handle = sequence(
25
- * postrender.handle({ store: valkey(client), edge: [akamai(creds)] }),
24
+ * postrender.handle({ store: new ValkeyStore(client), edge: [new AkamaiEdge(creds)] }),
26
25
  * ogygia.handle()
27
26
  * );
28
27
  *
@@ -39,4 +38,4 @@ const postrender = {
39
38
  invalidate,
40
39
  invalidateWhere
41
40
  };
42
- export { akamai, cloudfront as awsCloudfront, cloudflare, cloudflareKv, cloudfront, memory_store as memoryStore, postrender, upstash, valkey };
41
+ export { AkamaiEdge, CloudFrontEdge, CloudflareEdge, CloudflareKvStore, MemoryStore, UpstashStore, ValkeyStore, postrender };
package/dist/key.d.ts CHANGED
@@ -1,14 +1,9 @@
1
- /**
2
- * postrender — keying. v1 keying law (internal/notes/freeze.md, RESTRUCTURE): the key IS the
3
- * URL pathname. Zero sources, zero markers; `invalidate(url)` is exact because a CMS publish
4
- * payload carries its urlPath, and bulk eviction is a key-prefix scan (`invalidateWhere({
5
- * prefix: '/fr/fr/' })` — locale nukes are one case of it, not the contract). Query-stringed
6
- * requests are never stored (a `?` is an unbounded personalization axis — utm, search,
7
- * pagination — v1 keeps the store bounded).
8
- */
9
1
  /** The store key for a request URL: the decoded pathname, verbatim (trailing slash preserved —
10
2
  * `/fr/fr/` and `/fr/fr` are different documents to Kit and to the CDN). */
11
3
  export declare function store_key(pathname: string): string;
4
+ /** Whether `key` is in the subtree of a normalized prefix: the prefix itself or a page under it
5
+ * (`/fr/fr` holds `/fr/fr` and `/fr/fr/x`, never `/fr/fright`). */
6
+ export declare function in_subtree(key: string, normalized: string): boolean;
12
7
  /** How many leading path segments become edge prefix tags (`p:/fr`, `p:/fr/fr`, `p:/fr/fr/x`).
13
8
  * Depth-capped so tag counts stay bounded on deep trees; a purge deeper than the cap falls back
14
9
  * to origin eviction + edge TTL. Shared by the akamai adapter and its emulator personality. */
package/dist/key.js CHANGED
@@ -1,37 +1,34 @@
1
1
  // src/key.ts
2
- /**
3
- * postrender — keying. v1 keying law (internal/notes/freeze.md, RESTRUCTURE): the key IS the
4
- * URL pathname. Zero sources, zero markers; `invalidate(url)` is exact because a CMS publish
5
- * payload carries its urlPath, and bulk eviction is a key-prefix scan (`invalidateWhere({
6
- * prefix: '/fr/fr/' })` — locale nukes are one case of it, not the contract). Query-stringed
7
- * requests are never stored (a `?` is an unbounded personalization axis — utm, search,
8
- * pagination — v1 keeps the store bounded).
9
- */
10
2
  /** The store key for a request URL: the decoded pathname, verbatim (trailing slash preserved —
11
3
  * `/fr/fr/` and `/fr/fr` are different documents to Kit and to the CDN). */
12
4
  function store_key(pathname) {
13
5
  return pathname;
14
6
  }
7
+ /** Whether `key` is in the subtree of a normalized prefix: the prefix itself or a page under it
8
+ * (`/fr/fr` holds `/fr/fr` and `/fr/fr/x`, never `/fr/fright`). */
9
+ function in_subtree(key, normalized) {
10
+ return key === normalized || key.startsWith(subtree_prefix(normalized));
11
+ }
15
12
  /** How many leading path segments become edge prefix tags (`p:/fr`, `p:/fr/fr`, `p:/fr/fr/x`).
16
13
  * Depth-capped so tag counts stay bounded on deep trees; a purge deeper than the cap falls back
17
14
  * to origin eviction + edge TTL. Shared by the akamai adapter and its emulator personality. */
18
15
  const PREFIX_TAG_DEPTH = 3;
19
16
  /** Normalize a prefix filter: leading slash enforced, trailing slash stripped (except root). */
20
17
  function normalize_prefix(prefix) {
21
- let p = prefix.startsWith("/") ? prefix : "/" + prefix;
18
+ let p = prefix.startsWith("/") ? prefix : `/${prefix}`;
22
19
  while (p.length > 1 && p.endsWith("/")) p = p.slice(0, -1);
23
20
  return p;
24
21
  }
25
22
  /** The key prefix a normalized prefix's SUBTREE shares: `/fr/fr` → `/fr/fr/` (never `/fr/fright`),
26
23
  * and the root `/` → `/` itself (every key; `'/' + '/'` would match nothing). */
27
24
  function subtree_prefix(normalized) {
28
- return normalized.endsWith("/") ? normalized : normalized + "/";
25
+ return normalized.endsWith("/") ? normalized : `${normalized}/`;
29
26
  }
30
27
  /** The depth-capped prefix list for a pathname — the edge tag vocabulary for this response. */
31
28
  function prefix_tags(pathname) {
32
29
  const segs = pathname.split("/").filter(Boolean);
33
30
  const out = [];
34
- for (let i = 1; i <= Math.min(segs.length, 3); i++) out.push("/" + segs.slice(0, i).join("/"));
31
+ for (let i = 1; i <= Math.min(segs.length, 3); i++) out.push(`/${segs.slice(0, i).join("/")}`);
35
32
  return out;
36
33
  }
37
- export { PREFIX_TAG_DEPTH, normalize_prefix, prefix_tags, store_key, subtree_prefix };
34
+ export { PREFIX_TAG_DEPTH, in_subtree, normalize_prefix, prefix_tags, store_key, subtree_prefix };
@@ -1,2 +1,13 @@
1
- import { PostrenderStore } from "./types.js";
2
- export declare function memory_store(max_entries?: number, max_bytes?: number): PostrenderStore;
1
+ import { PostrenderEntry, PostrenderPutOptions, PostrenderStore } from "./types.js";
2
+ export declare class MemoryStore implements PostrenderStore {
3
+ #private;
4
+ constructor(max_entries?: number, max_bytes?: number);
5
+ get(key: string): Promise<PostrenderEntry | null>;
6
+ put(key: string, entry: PostrenderEntry, options: PostrenderPutOptions): Promise<void>;
7
+ evict(key: string): Promise<void>;
8
+ evictWhere({ prefix }: {
9
+ prefix: string;
10
+ }): Promise<void>;
11
+ evictByTag(tag: string): Promise<string[]>;
12
+ size(): Promise<number>;
13
+ }