@ogygia/postrender 0.12.0 → 0.13.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,4 +1,5 @@
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:";
@@ -20,71 +21,84 @@ function read_scan_reply(reply) {
20
21
  function glob_escape(value) {
21
22
  return value.replace(GLOB_ACTIVE_G, (c) => "\\" + c);
22
23
  }
23
- function valkey(client) {
24
- const set_with_ttl = async (key, value, ttl) => {
24
+ var ValkeyStore = class {
25
+ #client;
26
+ constructor(client) {
27
+ this.#client = client;
28
+ }
29
+ async get(key) {
30
+ const raw = await this.#client.get(KEY_NS + key);
31
+ if (!raw) return null;
25
32
  try {
26
- await client.set(key, value, "EX", ttl);
33
+ return JSON.parse(raw);
27
34
  } catch {
28
- await client.set(key, value, { EX: ttl });
35
+ return null;
29
36
  }
30
- };
31
- const sadd = async (key, member) => {
37
+ }
38
+ async put(key, entry, { ttl, tags }) {
39
+ await this.#set_with_ttl(KEY_NS + key, JSON.stringify(entry), ttl);
40
+ for (const tag of tags ?? []) {
41
+ await this.#sadd(TAG_NS + tag, key);
42
+ const left = await this.#read_ttl(TAG_NS + tag);
43
+ if (left === null || left < ttl) await this.#client.expire?.(TAG_NS + tag, ttl);
44
+ }
45
+ }
46
+ async evict(key) {
47
+ await this.#client.del(KEY_NS + key);
48
+ }
49
+ async evictWhere({ prefix }) {
50
+ const client = this.#client;
51
+ const p = normalize_prefix(prefix);
52
+ await this.#scan_prefix(subtree_prefix(p), async (keys) => void await client.del(...keys));
53
+ await client.del(KEY_NS + p);
54
+ }
55
+ async evictByTag(tag) {
56
+ const client = this.#client;
57
+ const members = await this.#smembers(TAG_NS + tag);
58
+ if (members.length) await client.del(...members.map((m) => KEY_NS + m));
59
+ await client.del(TAG_NS + tag);
60
+ return members;
61
+ }
62
+ async #set_with_ttl(key, value, ttl) {
63
+ try {
64
+ await this.#client.set(key, value, "EX", ttl);
65
+ } catch {
66
+ await this.#client.set(key, value, { EX: ttl });
67
+ }
68
+ }
69
+ async #sadd(key, member) {
70
+ const client = this.#client;
32
71
  if (client.sadd) await client.sadd(key, member);
33
72
  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) => {
73
+ else throw new OgygiaError("postrender_store_client_missing", {
74
+ client: "valkey",
75
+ commands: "sadd/sAdd"
76
+ });
77
+ }
78
+ async #smembers(key) {
79
+ const client = this.#client;
37
80
  if (client.smembers) return client.smembers(key);
38
81
  if (client.sMembers) return client.sMembers(key);
39
- throw new Error("[ogygia] valkey client has no smembers/sMembers — og.source tags need it");
40
- };
82
+ throw new OgygiaError("postrender_store_client_missing", {
83
+ client: "valkey",
84
+ commands: "smembers/sMembers"
85
+ });
86
+ }
41
87
  /** Seconds left on a key (-1 = no expiry), or null when the client has no TTL command. */
42
- const read_ttl = async (key) => {
88
+ async #read_ttl(key) {
89
+ const client = this.#client;
43
90
  if (client.ttl) return Number(await client.ttl(key));
44
91
  if (client.TTL) return Number(await client.TTL(key));
45
92
  return null;
46
- };
47
- const scan_prefix = async (prefix, on_keys) => {
93
+ }
94
+ async #scan_prefix(prefix, on_keys) {
48
95
  const pattern = glob_escape(KEY_NS + prefix) + "*";
49
96
  let cursor = "0";
50
97
  do {
51
- const page = read_scan_reply(await client.scan(cursor, "MATCH", pattern, "COUNT", SCAN_COUNT));
98
+ const page = read_scan_reply(await this.#client.scan(cursor, "MATCH", pattern, "COUNT", SCAN_COUNT));
52
99
  cursor = page.cursor;
53
100
  if (page.keys.length) await on_keys(page.keys);
54
101
  } 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 };
102
+ }
103
+ };
104
+ export { ValkeyStore };
package/dist/handle.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { install, mark_handled } from "./registry.js";
2
2
  import { postrender_app } from "./app.js";
3
+ import { warn } from "./messages.js";
3
4
  // src/handle.ts
4
5
  let warned_unlisted = false;
5
6
  function handle(options = {}) {
@@ -8,7 +9,7 @@ function handle(options = {}) {
8
9
  mark_handled(event, runtime);
9
10
  if (!postrender_app() && !warned_unlisted) {
10
11
  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
+ warn("postrender_handle_unlisted");
12
13
  }
13
14
  return resolve(event);
14
15
  };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
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
11
  export declare const postrender: {
12
12
  handle: typeof handle;
13
13
  invalidate: typeof invalidate;
14
14
  invalidateWhere: typeof invalidateWhere;
15
15
  };
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 };
16
+ 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,12 +1,12 @@
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
12
  * `@ogygia/postrender` — pages stored at request time. SERVER ONLY.
@@ -20,9 +20,9 @@ import { cloudflare } from "./adapters/cloudflare.js";
20
20
  * plugins: [ogygia(), postrender(), sveltekit()]
21
21
  *
22
22
  * // hooks.server.ts: the live store and CDN edges, BEFORE ogygia's handle
23
- * import { postrender, valkey, akamai } from '@ogygia/postrender';
23
+ * import { postrender, ValkeyStore, AkamaiEdge } from '@ogygia/postrender';
24
24
  * export const handle = sequence(
25
- * postrender.handle({ store: valkey(client), edge: [akamai(creds)] }),
25
+ * postrender.handle({ store: new ValkeyStore(client), edge: [new AkamaiEdge(creds)] }),
26
26
  * ogygia.handle()
27
27
  * );
28
28
  *
@@ -39,4 +39,4 @@ const postrender = {
39
39
  invalidate,
40
40
  invalidateWhere
41
41
  };
42
- export { akamai, cloudfront as awsCloudfront, cloudflare, cloudflareKv, cloudfront, memory_store as memoryStore, postrender, upstash, valkey };
42
+ export { AkamaiEdge, CloudFrontEdge, CloudflareEdge, CloudflareKvStore, MemoryStore, UpstashStore, ValkeyStore, postrender };
package/dist/key.d.ts CHANGED
@@ -9,6 +9,9 @@
9
9
  /** The store key for a request URL: the decoded pathname, verbatim (trailing slash preserved —
10
10
  * `/fr/fr/` and `/fr/fr` are different documents to Kit and to the CDN). */
11
11
  export declare function store_key(pathname: string): string;
12
+ /** Whether `key` is in the subtree of a normalized prefix: the prefix itself or a page under it
13
+ * (`/fr/fr` holds `/fr/fr` and `/fr/fr/x`, never `/fr/fright`). */
14
+ export declare function in_subtree(key: string, normalized: string): boolean;
12
15
  /** How many leading path segments become edge prefix tags (`p:/fr`, `p:/fr/fr`, `p:/fr/fr/x`).
13
16
  * Depth-capped so tag counts stay bounded on deep trees; a purge deeper than the cap falls back
14
17
  * to origin eviction + edge TTL. Shared by the akamai adapter and its emulator personality. */
package/dist/key.js CHANGED
@@ -12,6 +12,11 @@
12
12
  function store_key(pathname) {
13
13
  return pathname;
14
14
  }
15
+ /** Whether `key` is in the subtree of a normalized prefix: the prefix itself or a page under it
16
+ * (`/fr/fr` holds `/fr/fr` and `/fr/fr/x`, never `/fr/fright`). */
17
+ function in_subtree(key, normalized) {
18
+ return key === normalized || key.startsWith(subtree_prefix(normalized));
19
+ }
15
20
  /** How many leading path segments become edge prefix tags (`p:/fr`, `p:/fr/fr`, `p:/fr/fr/x`).
16
21
  * Depth-capped so tag counts stay bounded on deep trees; a purge deeper than the cap falls back
17
22
  * to origin eviction + edge TTL. Shared by the akamai adapter and its emulator personality. */
@@ -34,4 +39,4 @@ function prefix_tags(pathname) {
34
39
  for (let i = 1; i <= Math.min(segs.length, 3); i++) out.push("/" + segs.slice(0, i).join("/"));
35
40
  return out;
36
41
  }
37
- export { PREFIX_TAG_DEPTH, normalize_prefix, prefix_tags, store_key, subtree_prefix };
42
+ 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
+ }
@@ -1,4 +1,4 @@
1
- import { normalize_prefix, subtree_prefix } from "./key.js";
1
+ import { in_subtree, normalize_prefix } from "./key.js";
2
2
  import { SizedLru } from "@ogygia/core/plugin/utils";
3
3
  // src/memory-store.ts
4
4
  /** Resident budget for stored pages (a stored page can be multi-MB; a count alone bounds nothing). */
@@ -6,41 +6,42 @@ const DEFAULT_MAX_BYTES = 67108864;
6
6
  const DEFAULT_MAX_ENTRIES = 1e3;
7
7
  /** What an entry costs to keep: a page is its HTML; a redirect is a few dozen bytes. */
8
8
  const entry_bytes = (entry) => entry.kind === "page" ? entry.html.length : 64;
9
- function memory_store(max_entries = DEFAULT_MAX_ENTRIES, max_bytes = DEFAULT_MAX_BYTES) {
10
- const entries = new SizedLru(max_bytes, max_entries);
11
- const tag_index = /* @__PURE__ */ new Map();
12
- return {
13
- async get(key) {
14
- return entries.get(key, Date.now());
15
- },
16
- async put(key, entry, options) {
17
- entries.set(key, entry, entry_bytes(entry), Date.now() + options.ttl * 1e3);
18
- for (const tag of options.tags ?? []) {
19
- let set = tag_index.get(tag);
20
- if (!set) tag_index.set(tag, set = /* @__PURE__ */ new Set());
21
- set.add(key);
22
- }
23
- },
24
- async evict(key) {
25
- entries.delete(key);
26
- },
27
- async evictWhere({ prefix }) {
28
- const p = normalize_prefix(prefix);
29
- const subtree = subtree_prefix(p);
30
- for (const key of entries.keys()) if (key === p || key.startsWith(subtree)) entries.delete(key);
31
- },
32
- async evictByTag(tag) {
33
- const set = tag_index.get(tag);
34
- if (!set) return [];
35
- tag_index.delete(tag);
36
- const evicted = [];
37
- for (const key of set) if (entries.delete(key)) evicted.push(key);
38
- return evicted;
39
- },
40
- async size() {
41
- entries.sweep(Date.now());
42
- return entries.size;
9
+ var MemoryStore = class {
10
+ #entries;
11
+ #tag_index = /* @__PURE__ */ new Map();
12
+ constructor(max_entries = DEFAULT_MAX_ENTRIES, max_bytes = DEFAULT_MAX_BYTES) {
13
+ this.#entries = new SizedLru(max_bytes, max_entries);
14
+ }
15
+ async get(key) {
16
+ return this.#entries.get(key, Date.now());
17
+ }
18
+ async put(key, entry, options) {
19
+ this.#entries.set(key, entry, entry_bytes(entry), Date.now() + options.ttl * 1e3);
20
+ for (const tag of options.tags ?? []) {
21
+ let set = this.#tag_index.get(tag);
22
+ if (!set) this.#tag_index.set(tag, set = /* @__PURE__ */ new Set());
23
+ set.add(key);
43
24
  }
44
- };
45
- }
46
- export { memory_store };
25
+ }
26
+ async evict(key) {
27
+ this.#entries.delete(key);
28
+ }
29
+ async evictWhere({ prefix }) {
30
+ const p = normalize_prefix(prefix);
31
+ const entries = this.#entries;
32
+ for (const key of entries.keys()) if (in_subtree(key, p)) entries.delete(key);
33
+ }
34
+ async evictByTag(tag) {
35
+ const set = this.#tag_index.get(tag);
36
+ if (!set) return [];
37
+ this.#tag_index.delete(tag);
38
+ const evicted = [];
39
+ for (const key of set) if (this.#entries.delete(key)) evicted.push(key);
40
+ return evicted;
41
+ }
42
+ async size() {
43
+ this.#entries.sweep(Date.now());
44
+ return this.#entries.size;
45
+ }
46
+ };
47
+ export { MemoryStore };
@@ -0,0 +1,72 @@
1
+ import { MessagesOf } from "@ogygia/core/internal/messages";
2
+ /** The errors: `throw new OgygiaError(code, args)`. */
3
+ export declare const POSTRENDER_ERRORS: {
4
+ postrender_invalidate_not_source: {
5
+ text: () => string;
6
+ details: () => string;
7
+ };
8
+ postrender_adapter_request_failed: {
9
+ text: (a: {
10
+ what: string;
11
+ status: number;
12
+ body: string;
13
+ }) => string;
14
+ details: () => string;
15
+ };
16
+ postrender_store_client_missing: {
17
+ text: (a: {
18
+ client: string;
19
+ commands: string;
20
+ }) => string;
21
+ details: () => string;
22
+ };
23
+ };
24
+ /** The warnings: `warn(code, args, ...rest)`. */
25
+ export declare const POSTRENDER_WARNINGS: {
26
+ postrender_edges_without_shared_store: {
27
+ text: () => string;
28
+ details: () => string;
29
+ };
30
+ postrender_store_no_evict_by_tag: {
31
+ text: () => string;
32
+ details: () => string;
33
+ };
34
+ postrender_tag_evict_failed: {
35
+ text: (a: {
36
+ tag: string;
37
+ }) => string;
38
+ details: () => string;
39
+ };
40
+ postrender_store_failed: {
41
+ text: (a: {
42
+ op: string;
43
+ key: string;
44
+ }) => string;
45
+ details: () => string;
46
+ };
47
+ postrender_fanout_failed: {
48
+ text: (a: {
49
+ label: string;
50
+ what: string;
51
+ }) => string;
52
+ details: () => string;
53
+ };
54
+ postrender_stays_per_request: {
55
+ text: (a: {
56
+ path: string;
57
+ refusal: string;
58
+ }) => string;
59
+ details: () => string;
60
+ };
61
+ postrender_handle_unlisted: {
62
+ text: () => string;
63
+ details: () => string;
64
+ };
65
+ };
66
+ type Own = MessagesOf<typeof POSTRENDER_ERRORS, typeof POSTRENDER_WARNINGS>;
67
+ /** `throw new OgygiaError(code, args)`; `warn(code, args, ...rest)` logs; `line(code, args)` is the
68
+ * line as a string. Wording and link in dev and while prerendering, the link alone otherwise. */
69
+ export declare const OgygiaError: Own["OgygiaError"];
70
+ export declare const warn: Own["warn"];
71
+ export declare const line: Own["line"];
72
+ export {};
@@ -0,0 +1,146 @@
1
+ import { define_messages, dev_or_prerender, prose } from "@ogygia/core/internal/messages";
2
+ // src/messages.ts
3
+ /**
4
+ * EVERY MESSAGE THE POSTRENDER PACKAGE PRINTS, in one place: its code, its wording, what to do about
5
+ * it (core's `@ogygia/core/internal/messages` says how the system works).
6
+ *
7
+ * throw new OgygiaError('postrender_invalidate_not_source');
8
+ * warn('postrender_tag_evict_failed', { tag }, e);
9
+ *
10
+ * Postrender runs in the app's server build, so the wording is only passed in dev: a production build
11
+ * prints the code's page alone.
12
+ */
13
+ /** The errors: `throw new OgygiaError(code, args)`. */
14
+ const POSTRENDER_ERRORS = {
15
+ postrender_invalidate_not_source: {
16
+ text: () => prose`
17
+ postrender.invalidate(fn, args): the function is not a declared source — wrap its
18
+ definition: \`export const fn = import.meta.og.source(async (…) => …)\`.
19
+ `,
20
+ details: () => prose`
21
+ \`invalidate(fn, args)\` evicts the stored pages that read a data source with those
22
+ arguments. It only knows the functions declared as sources: this one is not.
23
+
24
+ Wrap the function's definition in \`import.meta.og.source(…)\`. Or evict by URL with
25
+ \`invalidate(url)\`.
26
+ `
27
+ },
28
+ postrender_adapter_request_failed: {
29
+ text: (a) => `${a.what} failed: ${a.status} ${a.body}`,
30
+ details: () => prose`
31
+ A store or edge adapter called its service's HTTP API (to purge a URL, or to run a store
32
+ command) and the service answered with an error status. \`status\` and \`body\` are its
33
+ answer.
34
+
35
+ A 401 or 403 is usually the adapter's credentials (a token, a key) or their permissions.
36
+ `
37
+ },
38
+ postrender_store_client_missing: {
39
+ text: (a) => `${a.client} client has no ${a.commands} — og.source tags need it`,
40
+ details: () => prose`
41
+ The client handed to the store adapter has no set commands, which the adapter needs to
42
+ file each stored page under the sources it read (\`import.meta.og.source\`). Pass a
43
+ client that has them.
44
+ `
45
+ }
46
+ };
47
+ /** The warnings: `warn(code, args, ...rest)`. */
48
+ const POSTRENDER_WARNINGS = {
49
+ postrender_edges_without_shared_store: {
50
+ text: () => prose`
51
+ postrender: edge adapters are configured but the store is the per-instance memory default
52
+ — invalidations cannot reach other replicas. Use a shared store (ValkeyStore / UpstashStore /
53
+ CloudflareKvStore) in multi-instance deploys.
54
+ `,
55
+ details: () => prose`
56
+ \`postrender.handle()\` was given edge adapters but no \`store\`, so each server instance
57
+ keeps its own memory store. An invalidation evicts the page on the instance that runs it
58
+ and purges the edge, but the other instances keep their stale copy and serve it to the
59
+ edge again.
60
+
61
+ Give \`postrender.handle()\` a shared \`store\` when the app runs on more than one
62
+ instance.
63
+ `
64
+ },
65
+ postrender_store_no_evict_by_tag: {
66
+ text: () => prose`
67
+ postrender: the configured store has no evictByTag — tag invalidation needs it
68
+ (MemoryStore/ValkeyStore/UpstashStore/CloudflareKvStore all provide it).
69
+ `,
70
+ details: () => prose`
71
+ An invalidation by source or tag needs the store to evict every page filed under a tag,
72
+ through \`evictByTag\`. The configured store has none, so nothing was evicted. Add
73
+ \`evictByTag\` to the custom store, or use one of the built-in stores.
74
+ `
75
+ },
76
+ postrender_tag_evict_failed: {
77
+ text: (a) => prose`
78
+ postrender.invalidate(tags): the store failed to evict tag ${a.tag} (evictByTag); its
79
+ pages stay stored until they expire —
80
+ `,
81
+ details: () => prose`
82
+ The store's \`evictByTag\` threw for one tag (the error follows the message). The other
83
+ tags were still evicted and purged at the edges; this tag's pages stay stored until
84
+ they expire.
85
+ `
86
+ },
87
+ postrender_store_failed: {
88
+ text: (a) => prose`
89
+ postrender: the store failed (${a.op} ${a.key}); pages render fresh and are not kept
90
+ while it does —
91
+ `,
92
+ details: () => prose`
93
+ A call to the store given to \`postrender.handle({ store })\` threw (the error follows the
94
+ message). A store that is down never fails a render: a read is a miss, a write or an
95
+ evict is skipped. So every page renders fresh, nothing is kept, and an evict may leave a
96
+ page stored until it expires. Said once, then again only after a store call worked: a
97
+ store that stays down does not fill the log.
98
+
99
+ Check the store's connection and credentials.
100
+ `
101
+ },
102
+ postrender_fanout_failed: {
103
+ text: (a) => `postrender.${a.label}: ${a.what} —`,
104
+ details: () => prose`
105
+ An invalidation reaches the store and every edge adapter at once. One of those calls
106
+ failed (\`what\` names it; the error follows the message); the others still ran. The
107
+ page may stay stored, or cached at that edge, until it expires.
108
+ `
109
+ },
110
+ postrender_stays_per_request: {
111
+ text: (a) => prose`
112
+ postrender: ${a.path} stays per-request — the render read ${a.refusal}. Personalize inside
113
+ a render:'deferred' hole to make the shell storable.
114
+ `,
115
+ details: () => prose`
116
+ Dev only. The page's render read something personal (a cookie, a header, the visitor) or
117
+ answered in a way that cannot be shared (a status other than 200, a \`set-cookie\`
118
+ header, streamed load promises), so it is rendered per request and never stored.
119
+ \`refusal\` names what.
120
+
121
+ Move the personal part into a \`render: 'deferred'\` hole: the rest of the page is then
122
+ stored, and the hole fills in per visitor.
123
+ `
124
+ },
125
+ postrender_handle_unlisted: {
126
+ text: () => prose`
127
+ postrender.handle() runs, but \`postrender()\` is not listed in vite.config, so no page is
128
+ stored. Add it: \`plugins: [ogygia(), postrender(), sveltekit()]\`
129
+ (from '@ogygia/postrender/vite').
130
+ `,
131
+ details: () => prose`
132
+ \`postrender.handle()\` is in the hooks, but the plugin's server half never started, so
133
+ nothing is ever stored.
134
+
135
+ List \`postrender()\` (from \`@ogygia/postrender/vite\`) in the \`plugins\` of vite.config,
136
+ beside \`ogygia()\`.
137
+ `
138
+ }
139
+ };
140
+ const own = /* @__PURE__ */ define_messages(import.meta.env?.DEV || import.meta.env?.SSR ? POSTRENDER_ERRORS : null, import.meta.env?.DEV || import.meta.env?.SSR ? POSTRENDER_WARNINGS : null, dev_or_prerender);
141
+ /** `throw new OgygiaError(code, args)`; `warn(code, args, ...rest)` logs; `line(code, args)` is the
142
+ * line as a string. Wording and link in dev and while prerendering, the link alone otherwise. */
143
+ const OgygiaError = own.OgygiaError;
144
+ const warn = own.warn;
145
+ const line = own.line;
146
+ export { OgygiaError, POSTRENDER_ERRORS, POSTRENDER_WARNINGS, line, warn };
@@ -1,4 +1,5 @@
1
1
  import { EdgeAdapter, PostrenderEntry, PostrenderHandleOptions, PostrenderPutOptions, PostrenderStore } from "./types.js";
2
+ import { Stale } from "@ogygia/machine";
2
3
  import { RequestEvent } from "@sveltejs/kit";
3
4
  /** One server's live settings: what its `postrender.handle({ store, edge })` was given. */
4
5
  export interface Runtime {
@@ -20,13 +21,57 @@ export declare function reset_for_tests(): void;
20
21
  /** Evict every stored page carrying ANY of `tags` (origin + every edge). The receiving half of a
21
22
  * thaw notice; also what `invalidate(fn, args)` does for one receipt tag. */
22
23
  export declare function invalidate_tags(tags: readonly string[], runtime?: Runtime): Promise<string[]>;
24
+ /** `invalidate_tags`, with what the store failed to evict: the shared hook (a peer's thaw) must not
25
+ * answer "done" for a tag that is still stored (#287). */
26
+ export declare function evict_tags(tags: readonly string[], runtime?: Runtime): Promise<{
27
+ keys: string[];
28
+ failed: unknown[];
29
+ }>;
23
30
  export declare function store_get(runtime: Runtime, key: string): Promise<PostrenderEntry | null>;
24
31
  export declare function store_put(runtime: Runtime, key: string, entry: PostrenderEntry, options: PostrenderPutOptions): Promise<void>;
32
+ /**
33
+ * Store a render's page. An invalidation that starts while the write is out ends the render's
34
+ * flight (it may have read what the invalidation changes), and its evict may run before the write
35
+ * lands: the page is then taken back out, through the same tried-again evict a post waits for.
36
+ * True when it stays stored.
37
+ *
38
+ * From the moment its flight goes stale until that evict ends, the page is RETRACTING: what the
39
+ * store holds for it may be the page from before the invalidation, so no hit is served from it
40
+ * (#332).
41
+ */
42
+ export declare function store_render(runtime: Runtime, key: string, entry: PostrenderEntry, options: PostrenderPutOptions, flight: Flight): Promise<boolean>;
43
+ /** A stale render's page is being taken back out of the store: a hit for it is a miss. */
44
+ export declare function retracting(key: string): boolean;
25
45
  export type FlightOutcome = {
26
46
  stored: PostrenderEntry | null;
27
47
  };
28
- export declare function join_flight(key: string): Promise<FlightOutcome> | null;
29
- export declare function begin_flight(key: string): (outcome: FlightOutcome) => void;
48
+ /**
49
+ * One page's render, opened by the request that renders it: that request settles it exactly once,
50
+ * however it ends (the plugin's `done` settles one nothing else did), with what it stored, or null.
51
+ * An invalidation that would have evicted its page ends it while it renders (`stale`: what it read
52
+ * may be the page from before the publish): it is not stored, and the requests that joined it are
53
+ * let go at once to ask again (#194).
54
+ */
55
+ export declare class Flight {
56
+ #private;
57
+ readonly key: string;
58
+ readonly outcome: Promise<FlightOutcome>;
59
+ constructor(key: string);
60
+ /** An invalidation ended it while it rendered. */
61
+ get stale(): boolean;
62
+ /** Settle it (once: a second settle does nothing). */
63
+ settle(outcome: FlightOutcome): void;
64
+ /** The flight's work: its outcome, once its request settles it. */
65
+ _fly(signal: AbortSignal): Promise<FlightOutcome>;
66
+ }
67
+ /** The render of `key` in progress: join it (its outcome, `STALE` when an invalidation ended it),
68
+ * or, with none out, open it (`opened`: this request renders the page, and settles it however it
69
+ * ends). */
70
+ export declare function enter_flight(key: string): {
71
+ opened: Flight;
72
+ } | {
73
+ joined: Promise<FlightOutcome | Stale>;
74
+ };
30
75
  /** A function stamped by the `import.meta.og.source` macro (core's data sources). */
31
76
  type SourceFn = (...args: never[]) => unknown;
32
77
  /**
@@ -44,7 +89,9 @@ export declare function invalidate(target: string | SourceFn, args?: unknown[]):
44
89
  export declare function invalidateWhere(filter: {
45
90
  prefix: string;
46
91
  }): Promise<void>;
47
- /** Action self-evict: a successful non-GET on a page URL evicts that URL (origin only — the
48
- * edge copy follows via its s-maxage or the app's explicit invalidate; fire-and-forget). */
49
- export declare function self_evict(runtime: Runtime, pathname: string): void;
92
+ /** Action self-evict: a successful non-GET on a page URL evicts that URL (origin only — the edge
93
+ * copy follows via its s-maxage or the app's explicit invalidate). Settles once the store took it
94
+ * out, or gave up (it never rejects): the response waits for it, so the redirect's GET right after
95
+ * cannot be answered with the page from before the post (#283). */
96
+ export declare function self_evict(runtime: Runtime, pathname: string): Promise<void>;
50
97
  export {};