@ogygia/postrender 0.13.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.
- package/dist/adapters/akamai.d.ts +6 -0
- package/dist/adapters/akamai.js +11 -15
- package/dist/adapters/cloudflare-kv.d.ts +12 -0
- package/dist/adapters/cloudflare-kv.js +12 -0
- package/dist/adapters/cloudflare.d.ts +6 -0
- package/dist/adapters/cloudflare.js +8 -1
- package/dist/adapters/cloudfront.js +5 -4
- package/dist/adapters/upstash.d.ts +7 -0
- package/dist/adapters/upstash.js +11 -4
- package/dist/adapters/valkey.d.ts +7 -0
- package/dist/adapters/valkey.js +9 -4
- package/dist/app.js +8 -3
- package/dist/handle.d.ts +16 -0
- package/dist/handle.js +19 -5
- package/dist/index.d.ts +25 -0
- package/dist/index.js +3 -4
- package/dist/key.d.ts +0 -8
- package/dist/key.js +3 -11
- package/dist/memory-store.js +4 -3
- package/dist/messages.d.ts +6 -0
- package/dist/messages.js +14 -10
- package/dist/observe.d.ts +6 -10
- package/dist/observe.js +10 -59
- package/dist/registry.d.ts +2 -0
- package/dist/registry.js +45 -27
- package/dist/server.d.ts +2 -5
- package/dist/server.js +183 -60
- package/dist/stitch.d.ts +8 -22
- package/dist/stitch.js +42 -66
- package/dist/types.d.ts +5 -12
- package/dist/vite.d.ts +17 -1
- package/dist/vite.js +18 -11
- package/package.json +9 -6
|
@@ -14,6 +14,12 @@ export interface AkamaiConfig {
|
|
|
14
14
|
/** The s-maxage this edge is granted (defaults to the policy TTL in `headers(meta)`). */
|
|
15
15
|
maxAge?: number;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* An Akamai edge: Fast Purge v3 by URL and by tag, with EdgeGrid request signing. `headers(meta)`
|
|
19
|
+
* stamps depth-capped prefix tags (`edge-cache-tag: p:/fr, p:/fr/fr, …`), and
|
|
20
|
+
* `purgeWhere({ prefix })` purges the matching tag, as Fast Purge has no prefix purge of its own.
|
|
21
|
+
* `baseUrl` points the same adapter at an emulator, so a test runs the real signing code.
|
|
22
|
+
*/
|
|
17
23
|
export declare class AkamaiEdge implements EdgeAdapter {
|
|
18
24
|
#private;
|
|
19
25
|
readonly name: string;
|
package/dist/adapters/akamai.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import { normalize_prefix, prefix_tags } from "../key.js";
|
|
2
2
|
import { OgygiaError } from "../messages.js";
|
|
3
|
-
import {
|
|
3
|
+
import { clock, net, random } from "@ogygia/machine";
|
|
4
|
+
import { createHash, createHmac } from "node:crypto";
|
|
4
5
|
// src/adapters/akamai.ts
|
|
5
|
-
/**
|
|
6
|
-
* postrender — Akamai edge adapter: Fast Purge v3 (url + tag) with real EdgeGrid request signing.
|
|
7
|
-
*
|
|
8
|
-
* `headers(meta)` stamps the depth-capped PREFIX tags (`edge-cache-tag: p:/fr, p:/fr/fr, …`) the
|
|
9
|
-
* property stores by; `purgeWhere({ prefix })` purges the matching tag — Fast Purge has no
|
|
10
|
-
* arbitrary-prefix purge, tags ARE the prefix mechanism. `purgeUrl` purges by absolute URL.
|
|
11
|
-
*
|
|
12
|
-
* `baseUrl` override points the SAME adapter at the harness's edge emulator — e2e exercises this
|
|
13
|
-
* exact signing/requesting code, not a mock of it.
|
|
14
|
-
*/
|
|
15
6
|
const TRAILING_SLASHES_RE = /\/+$/;
|
|
16
|
-
/** EdgeGrid timestamp: `yyyyMMddTHH:mm:ss+0000`. */
|
|
17
7
|
function edgegrid_timestamp() {
|
|
18
|
-
const d =
|
|
8
|
+
const d = new Date(clock.wall());
|
|
19
9
|
const pad = (n) => String(n).padStart(2, "0");
|
|
20
10
|
return `${d.getUTCFullYear()}${pad(d.getUTCMonth() + 1)}${pad(d.getUTCDate())}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}+0000`;
|
|
21
11
|
}
|
|
22
12
|
const b64_hmac = (key, data) => createHmac("sha256", key).update(data).digest("base64");
|
|
23
13
|
const b64_sha = (data) => createHash("sha256").update(data).digest("base64");
|
|
14
|
+
/**
|
|
15
|
+
* An Akamai edge: Fast Purge v3 by URL and by tag, with EdgeGrid request signing. `headers(meta)`
|
|
16
|
+
* stamps depth-capped prefix tags (`edge-cache-tag: p:/fr, p:/fr/fr, …`), and
|
|
17
|
+
* `purgeWhere({ prefix })` purges the matching tag, as Fast Purge has no prefix purge of its own.
|
|
18
|
+
* `baseUrl` points the same adapter at an emulator, so a test runs the real signing code.
|
|
19
|
+
*/
|
|
24
20
|
var AkamaiEdge = class {
|
|
25
21
|
name = "akamai";
|
|
26
22
|
#config;
|
|
@@ -50,7 +46,7 @@ var AkamaiEdge = class {
|
|
|
50
46
|
const config = this.#config;
|
|
51
47
|
const payload = JSON.stringify(body);
|
|
52
48
|
const timestamp = edgegrid_timestamp();
|
|
53
|
-
const nonce =
|
|
49
|
+
const nonce = random.uuid();
|
|
54
50
|
const auth_prefix = `EG1-HMAC-SHA256 client_token=${config.clientToken};access_token=${config.accessToken};timestamp=${timestamp};nonce=${nonce};`;
|
|
55
51
|
const url = new URL(this.#api_base + path);
|
|
56
52
|
const data_to_sign = [
|
|
@@ -64,7 +60,7 @@ var AkamaiEdge = class {
|
|
|
64
60
|
].join(" ");
|
|
65
61
|
const signing_key = b64_hmac(config.clientSecret, timestamp);
|
|
66
62
|
const signature = b64_hmac(signing_key, data_to_sign);
|
|
67
|
-
const res = await fetch(url, {
|
|
63
|
+
const res = await net.fetch(url, {
|
|
68
64
|
method: "POST",
|
|
69
65
|
headers: {
|
|
70
66
|
"content-type": "application/json",
|
|
@@ -17,6 +17,18 @@ export interface KvNamespaceLike {
|
|
|
17
17
|
cursor?: string;
|
|
18
18
|
}>;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A store on Cloudflare Workers KV, with the Worker's own binding. KV has no sets and no scans but
|
|
22
|
+
* lists by key prefix: pages are `og:a:<pathname>` (subtree eviction is one list) and each tag is
|
|
23
|
+
* a set of sentinel keys `og:t:<tag>:<pathname>` (tag eviction is one list).
|
|
24
|
+
*
|
|
25
|
+
* Differences from the other stores: KV is eventually consistent (an invalidation can serve the
|
|
26
|
+
* old copy for about a minute at far locations), and a TTL under 60 seconds is raised to 60, KV's
|
|
27
|
+
* floor.
|
|
28
|
+
*
|
|
29
|
+
* import { env } from 'cloudflare:workers';
|
|
30
|
+
* postrender.handle({ store: new CloudflareKvStore(env.PAGES) })
|
|
31
|
+
*/
|
|
20
32
|
export declare class CloudflareKvStore implements PostrenderStore {
|
|
21
33
|
#private;
|
|
22
34
|
constructor(kv: KvNamespaceLike);
|
|
@@ -3,6 +3,18 @@ import { normalize_prefix, subtree_prefix } from "../key.js";
|
|
|
3
3
|
const KEY_NS = "og:a:";
|
|
4
4
|
const TAG_NS = "og:t:";
|
|
5
5
|
const KV_MIN_TTL = 60;
|
|
6
|
+
/**
|
|
7
|
+
* A store on Cloudflare Workers KV, with the Worker's own binding. KV has no sets and no scans but
|
|
8
|
+
* lists by key prefix: pages are `og:a:<pathname>` (subtree eviction is one list) and each tag is
|
|
9
|
+
* a set of sentinel keys `og:t:<tag>:<pathname>` (tag eviction is one list).
|
|
10
|
+
*
|
|
11
|
+
* Differences from the other stores: KV is eventually consistent (an invalidation can serve the
|
|
12
|
+
* old copy for about a minute at far locations), and a TTL under 60 seconds is raised to 60, KV's
|
|
13
|
+
* floor.
|
|
14
|
+
*
|
|
15
|
+
* import { env } from 'cloudflare:workers';
|
|
16
|
+
* postrender.handle({ store: new CloudflareKvStore(env.PAGES) })
|
|
17
|
+
*/
|
|
6
18
|
var CloudflareKvStore = class {
|
|
7
19
|
#kv;
|
|
8
20
|
constructor(kv) {
|
|
@@ -10,6 +10,12 @@ export interface CloudflareConfig {
|
|
|
10
10
|
/** The s-maxage this edge is granted (defaults to the policy TTL in `headers(meta)`). */
|
|
11
11
|
maxAge?: number;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* A Cloudflare edge: zone purge with a bearer API token. `purgeUrl` purges by files (every plan);
|
|
15
|
+
* `purgeWhere({ prefix })` purges by prefixes (`<host><prefix>`, Enterprise). `headers(meta)`
|
|
16
|
+
* stamps the depth-capped prefix tags under `cache-tag` (plans that do not read it ignore it)
|
|
17
|
+
* plus the verdict's `s-maxage`. `baseUrl` points the same adapter at an emulator.
|
|
18
|
+
*/
|
|
13
19
|
export declare class CloudflareEdge implements EdgeAdapter {
|
|
14
20
|
#private;
|
|
15
21
|
readonly name: string;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { normalize_prefix, prefix_tags } from "../key.js";
|
|
2
2
|
import { OgygiaError } from "../messages.js";
|
|
3
|
+
import { net } from "@ogygia/machine";
|
|
3
4
|
// src/adapters/cloudflare.ts
|
|
4
5
|
const TRAILING_SLASHES_RE = /\/+$/;
|
|
5
6
|
const HTTP_SCHEME_RE = /^https?:\/\//;
|
|
7
|
+
/**
|
|
8
|
+
* A Cloudflare edge: zone purge with a bearer API token. `purgeUrl` purges by files (every plan);
|
|
9
|
+
* `purgeWhere({ prefix })` purges by prefixes (`<host><prefix>`, Enterprise). `headers(meta)`
|
|
10
|
+
* stamps the depth-capped prefix tags under `cache-tag` (plans that do not read it ignore it)
|
|
11
|
+
* plus the verdict's `s-maxage`. `baseUrl` points the same adapter at an emulator.
|
|
12
|
+
*/
|
|
6
13
|
var CloudflareEdge = class {
|
|
7
14
|
name = "cloudflare";
|
|
8
15
|
#config;
|
|
@@ -31,7 +38,7 @@ var CloudflareEdge = class {
|
|
|
31
38
|
}
|
|
32
39
|
async #purge(body) {
|
|
33
40
|
const config = this.#config;
|
|
34
|
-
const res = await fetch(`${this.#api_base}/client/v4/zones/${config.zoneId}/purge_cache`, {
|
|
41
|
+
const res = await net.fetch(`${this.#api_base}/client/v4/zones/${config.zoneId}/purge_cache`, {
|
|
35
42
|
method: "POST",
|
|
36
43
|
headers: {
|
|
37
44
|
authorization: `Bearer ${config.apiToken}`,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalize_prefix } from "../key.js";
|
|
2
2
|
import { OgygiaError } from "../messages.js";
|
|
3
|
+
import { clock, net, random } from "@ogygia/machine";
|
|
3
4
|
import { createHash, createHmac } from "node:crypto";
|
|
4
5
|
// src/adapters/cloudfront.ts
|
|
5
6
|
/**
|
|
@@ -23,7 +24,7 @@ const hex_sha = (data) => createHash("sha256").update(data).digest("hex");
|
|
|
23
24
|
const hmac = (key, data) => createHmac("sha256", key).update(data).digest();
|
|
24
25
|
/** amz dates: `20260901T120000Z` / `20260901`. */
|
|
25
26
|
function amz_dates() {
|
|
26
|
-
const iso =
|
|
27
|
+
const iso = new Date(clock.wall()).toISOString().replace(DASH_COLON_G, "").replace(MILLISECONDS_RE, "");
|
|
27
28
|
return {
|
|
28
29
|
datetime: iso,
|
|
29
30
|
date: iso.slice(0, 8)
|
|
@@ -50,7 +51,7 @@ var CloudFrontEdge = class {
|
|
|
50
51
|
async #create_invalidation(paths) {
|
|
51
52
|
const config = this.#config;
|
|
52
53
|
const items = paths.map((p) => `<Path>${p}</Path>`).join("");
|
|
53
|
-
const body = `<?xml version="1.0" encoding="UTF-8"?><InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/${API_VERSION}/"><CallerReference>og-${
|
|
54
|
+
const body = `<?xml version="1.0" encoding="UTF-8"?><InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/${API_VERSION}/"><CallerReference>og-${clock.wall()}-${Math.floor(random.float() * 1e6)}</CallerReference><Paths><Quantity>${paths.length}</Quantity><Items>${items}</Items></Paths></InvalidationBatch>`;
|
|
54
55
|
const path = `/${API_VERSION}/distribution/${config.distributionId}/invalidation`;
|
|
55
56
|
const { datetime, date } = amz_dates();
|
|
56
57
|
const payload_hash = hex_sha(body);
|
|
@@ -72,12 +73,12 @@ var CloudFrontEdge = class {
|
|
|
72
73
|
scope,
|
|
73
74
|
hex_sha(canonical)
|
|
74
75
|
].join("\n");
|
|
75
|
-
const k_date = hmac(
|
|
76
|
+
const k_date = hmac(`AWS4${config.secretAccessKey}`, date);
|
|
76
77
|
const k_region = hmac(k_date, REGION);
|
|
77
78
|
const k_service = hmac(k_region, SERVICE);
|
|
78
79
|
const k_signing = hmac(k_service, "aws4_request");
|
|
79
80
|
const signature = createHmac("sha256", k_signing).update(string_to_sign).digest("hex");
|
|
80
|
-
const res = await fetch(this.#api_base + path, {
|
|
81
|
+
const res = await net.fetch(this.#api_base + path, {
|
|
81
82
|
method: "POST",
|
|
82
83
|
headers: {
|
|
83
84
|
host: API_HOST,
|
|
@@ -4,6 +4,13 @@ export interface UpstashConfig {
|
|
|
4
4
|
url: string;
|
|
5
5
|
token: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* A store on Upstash Redis over its REST API: no client library and no connection, every command
|
|
9
|
+
* is one HTTPS call, which suits serverless and edge origins. The same keys as `ValkeyStore`.
|
|
10
|
+
*
|
|
11
|
+
* postrender.handle({ store: new UpstashStore({ url: env.UPSTASH_REDIS_REST_URL,
|
|
12
|
+
* token: env.UPSTASH_REDIS_REST_TOKEN }) })
|
|
13
|
+
*/
|
|
7
14
|
export declare class UpstashStore implements PostrenderStore {
|
|
8
15
|
#private;
|
|
9
16
|
constructor(config: UpstashConfig);
|
package/dist/adapters/upstash.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { normalize_prefix, subtree_prefix } from "../key.js";
|
|
2
2
|
import { OgygiaError } from "../messages.js";
|
|
3
|
+
import { net } from "@ogygia/machine";
|
|
3
4
|
// src/adapters/upstash.ts
|
|
4
5
|
const GLOB_ACTIVE_G = /[*?[\]\\]/g;
|
|
5
6
|
const TRAILING_SLASHES_RE = /\/+$/;
|
|
6
7
|
const KEY_NS = "og:a:";
|
|
7
8
|
const TAG_NS = "og:t:";
|
|
8
9
|
const SCAN_COUNT = 250;
|
|
9
|
-
/** Escape glob-active characters so a literal pathname can ride a SCAN MATCH pattern. */
|
|
10
10
|
function glob_escape(value) {
|
|
11
|
-
return value.replace(GLOB_ACTIVE_G, (c) =>
|
|
11
|
+
return value.replace(GLOB_ACTIVE_G, (c) => `\\${c}`);
|
|
12
12
|
}
|
|
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
|
+
*/
|
|
13
20
|
var UpstashStore = class {
|
|
14
21
|
#base;
|
|
15
22
|
#token;
|
|
@@ -52,7 +59,7 @@ var UpstashStore = class {
|
|
|
52
59
|
}
|
|
53
60
|
async evictWhere({ prefix }) {
|
|
54
61
|
const p = normalize_prefix(prefix);
|
|
55
|
-
const pattern = glob_escape(KEY_NS + subtree_prefix(p))
|
|
62
|
+
const pattern = `${glob_escape(KEY_NS + subtree_prefix(p))}*`;
|
|
56
63
|
let cursor = "0";
|
|
57
64
|
do {
|
|
58
65
|
const reply = await this.#command([
|
|
@@ -76,7 +83,7 @@ var UpstashStore = class {
|
|
|
76
83
|
}
|
|
77
84
|
/** One command, Upstash REST shape: POST the command as a JSON array → `{ result }`. */
|
|
78
85
|
async #command(parts) {
|
|
79
|
-
const res = await fetch(this.#base, {
|
|
86
|
+
const res = await net.fetch(this.#base, {
|
|
80
87
|
method: "POST",
|
|
81
88
|
headers: {
|
|
82
89
|
authorization: `Bearer ${this.#token}`,
|
|
@@ -15,6 +15,13 @@ export interface ValkeyLike {
|
|
|
15
15
|
ttl?(key: string): Promise<number>;
|
|
16
16
|
TTL?(key: string): Promise<number>;
|
|
17
17
|
}
|
|
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
|
+
*/
|
|
18
25
|
export declare class ValkeyStore implements PostrenderStore {
|
|
19
26
|
#private;
|
|
20
27
|
constructor(client: ValkeyLike);
|
package/dist/adapters/valkey.js
CHANGED
|
@@ -5,7 +5,6 @@ const GLOB_ACTIVE_G = /[*?[\]\\]/g;
|
|
|
5
5
|
const KEY_NS = "og:a:";
|
|
6
6
|
const TAG_NS = "og:t:";
|
|
7
7
|
const SCAN_COUNT = 250;
|
|
8
|
-
/** Both client families' scan shapes → one { cursor, keys }. */
|
|
9
8
|
function read_scan_reply(reply) {
|
|
10
9
|
if (Array.isArray(reply)) return {
|
|
11
10
|
cursor: String(reply[0]),
|
|
@@ -17,10 +16,16 @@ function read_scan_reply(reply) {
|
|
|
17
16
|
keys: obj.keys ?? []
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
|
-
/** Escape glob-active characters so a literal pathname can ride a SCAN MATCH pattern. */
|
|
21
19
|
function glob_escape(value) {
|
|
22
|
-
return value.replace(GLOB_ACTIVE_G, (c) =>
|
|
20
|
+
return value.replace(GLOB_ACTIVE_G, (c) => `\\${c}`);
|
|
23
21
|
}
|
|
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
|
+
*/
|
|
24
29
|
var ValkeyStore = class {
|
|
25
30
|
#client;
|
|
26
31
|
constructor(client) {
|
|
@@ -92,7 +97,7 @@ var ValkeyStore = class {
|
|
|
92
97
|
return null;
|
|
93
98
|
}
|
|
94
99
|
async #scan_prefix(prefix, on_keys) {
|
|
95
|
-
const pattern = glob_escape(KEY_NS + prefix)
|
|
100
|
+
const pattern = `${glob_escape(KEY_NS + prefix)}*`;
|
|
96
101
|
let cursor = "0";
|
|
97
102
|
do {
|
|
98
103
|
const page = read_scan_reply(await this.#client.scan(cursor, "MATCH", pattern, "COUNT", SCAN_COUNT));
|
package/dist/app.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { slot } from "@ogygia/machine";
|
|
1
2
|
// src/app.ts
|
|
2
|
-
const slot =
|
|
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,16 +1,30 @@
|
|
|
1
1
|
import { install, mark_handled } from "./registry.js";
|
|
2
2
|
import { postrender_app } from "./app.js";
|
|
3
3
|
import { warn } from "./messages.js";
|
|
4
|
+
import { say } from "@ogygia/machine";
|
|
4
5
|
// src/handle.ts
|
|
5
|
-
|
|
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
|
+
*/
|
|
6
23
|
function handle(options = {}) {
|
|
7
24
|
const runtime = install(options);
|
|
8
25
|
return ({ event, resolve }) => {
|
|
9
26
|
mark_handled(event, runtime);
|
|
10
|
-
if (!postrender_app()
|
|
11
|
-
warned_unlisted = true;
|
|
12
|
-
warn("postrender_handle_unlisted");
|
|
13
|
-
}
|
|
27
|
+
if (!postrender_app()) unlisted.once("postrender_handle_unlisted", () => warn("postrender_handle_unlisted"));
|
|
14
28
|
return resolve(event);
|
|
15
29
|
};
|
|
16
30
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,31 @@ import { AkamaiConfig, AkamaiEdge } from "./adapters/akamai.js";
|
|
|
8
8
|
import { CloudFrontEdge, CloudfrontConfig } from "./adapters/cloudfront.js";
|
|
9
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;
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,9 @@ import { CloudFrontEdge } from "./adapters/cloudfront.js";
|
|
|
9
9
|
import { CloudflareEdge } from "./adapters/cloudflare.js";
|
|
10
10
|
// src/index.ts
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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)
|
package/dist/key.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
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;
|
package/dist/key.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
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) {
|
|
@@ -23,20 +15,20 @@ function in_subtree(key, normalized) {
|
|
|
23
15
|
const PREFIX_TAG_DEPTH = 3;
|
|
24
16
|
/** Normalize a prefix filter: leading slash enforced, trailing slash stripped (except root). */
|
|
25
17
|
function normalize_prefix(prefix) {
|
|
26
|
-
let p = prefix.startsWith("/") ? prefix :
|
|
18
|
+
let p = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
27
19
|
while (p.length > 1 && p.endsWith("/")) p = p.slice(0, -1);
|
|
28
20
|
return p;
|
|
29
21
|
}
|
|
30
22
|
/** The key prefix a normalized prefix's SUBTREE shares: `/fr/fr` → `/fr/fr/` (never `/fr/fright`),
|
|
31
23
|
* and the root `/` → `/` itself (every key; `'/' + '/'` would match nothing). */
|
|
32
24
|
function subtree_prefix(normalized) {
|
|
33
|
-
return normalized.endsWith("/") ? normalized : normalized
|
|
25
|
+
return normalized.endsWith("/") ? normalized : `${normalized}/`;
|
|
34
26
|
}
|
|
35
27
|
/** The depth-capped prefix list for a pathname — the edge tag vocabulary for this response. */
|
|
36
28
|
function prefix_tags(pathname) {
|
|
37
29
|
const segs = pathname.split("/").filter(Boolean);
|
|
38
30
|
const out = [];
|
|
39
|
-
for (let i = 1; i <= Math.min(segs.length, 3); i++) out.push(
|
|
31
|
+
for (let i = 1; i <= Math.min(segs.length, 3); i++) out.push(`/${segs.slice(0, i).join("/")}`);
|
|
40
32
|
return out;
|
|
41
33
|
}
|
|
42
34
|
export { PREFIX_TAG_DEPTH, in_subtree, normalize_prefix, prefix_tags, store_key, subtree_prefix };
|
package/dist/memory-store.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { in_subtree, normalize_prefix } from "./key.js";
|
|
2
|
+
import { clock } from "@ogygia/machine";
|
|
2
3
|
import { SizedLru } from "@ogygia/core/plugin/utils";
|
|
3
4
|
// src/memory-store.ts
|
|
4
5
|
/** Resident budget for stored pages (a stored page can be multi-MB; a count alone bounds nothing). */
|
|
@@ -13,10 +14,10 @@ var MemoryStore = class {
|
|
|
13
14
|
this.#entries = new SizedLru(max_bytes, max_entries);
|
|
14
15
|
}
|
|
15
16
|
async get(key) {
|
|
16
|
-
return this.#entries.get(key,
|
|
17
|
+
return this.#entries.get(key, clock.mono());
|
|
17
18
|
}
|
|
18
19
|
async put(key, entry, options) {
|
|
19
|
-
this.#entries.set(key, entry, entry_bytes(entry),
|
|
20
|
+
this.#entries.set(key, entry, entry_bytes(entry), clock.mono() + options.ttl * 1e3);
|
|
20
21
|
for (const tag of options.tags ?? []) {
|
|
21
22
|
let set = this.#tag_index.get(tag);
|
|
22
23
|
if (!set) this.#tag_index.set(tag, set = /* @__PURE__ */ new Set());
|
|
@@ -40,7 +41,7 @@ var MemoryStore = class {
|
|
|
40
41
|
return evicted;
|
|
41
42
|
}
|
|
42
43
|
async size() {
|
|
43
|
-
this.#entries.sweep(
|
|
44
|
+
this.#entries.sweep(clock.mono());
|
|
44
45
|
return this.#entries.size;
|
|
45
46
|
}
|
|
46
47
|
};
|
package/dist/messages.d.ts
CHANGED
|
@@ -44,6 +44,12 @@ export declare const POSTRENDER_WARNINGS: {
|
|
|
44
44
|
}) => string;
|
|
45
45
|
details: () => string;
|
|
46
46
|
};
|
|
47
|
+
postrender_capture_failed: {
|
|
48
|
+
text: (a: {
|
|
49
|
+
path: string;
|
|
50
|
+
}) => string;
|
|
51
|
+
details: () => string;
|
|
52
|
+
};
|
|
47
53
|
postrender_fanout_failed: {
|
|
48
54
|
text: (a: {
|
|
49
55
|
label: string;
|
package/dist/messages.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { define_messages, dev_or_prerender, prose } from "@ogygia/core/internal/messages";
|
|
2
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
3
|
/** The errors: `throw new OgygiaError(code, args)`. */
|
|
14
4
|
const POSTRENDER_ERRORS = {
|
|
15
5
|
postrender_invalidate_not_source: {
|
|
@@ -99,6 +89,20 @@ const POSTRENDER_WARNINGS = {
|
|
|
99
89
|
Check the store's connection and credentials.
|
|
100
90
|
`
|
|
101
91
|
},
|
|
92
|
+
postrender_capture_failed: {
|
|
93
|
+
text: (a) => prose`
|
|
94
|
+
postrender: storing ${a.path} failed; the page went out as rendered, not stored —
|
|
95
|
+
`,
|
|
96
|
+
details: () => prose`
|
|
97
|
+
Postrender reads each storable page to store it (its stitched holes rewritten, its
|
|
98
|
+
headers made). That step threw for this page (the error follows the message). The
|
|
99
|
+
visitor got the page as the app rendered it, marked \`no-store\`, and nothing was
|
|
100
|
+
stored: the next request renders it again. Said once per page.
|
|
101
|
+
|
|
102
|
+
The error names what failed: often a stitched hole whose \`endpoint\` is not a URL, or
|
|
103
|
+
an edge adapter that threw.
|
|
104
|
+
`
|
|
105
|
+
},
|
|
102
106
|
postrender_fanout_failed: {
|
|
103
107
|
text: (a) => `postrender.${a.label}: ${a.what} —`,
|
|
104
108
|
details: () => prose`
|
package/dist/observe.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestContext } from "@ogygia/core/plugin";
|
|
2
2
|
export interface Observation {
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* request's `perVisitor` fact: a flag read or a streamed promise lands there too. */
|
|
3
|
+
/** The first per-visitor read, or null — the verdict input. Named (`cookie:consent`,
|
|
4
|
+
* `header:accept-language`, `locals.user`, `flag:hero`) for the dev note. */
|
|
6
5
|
readonly disqualified_by: string | null;
|
|
7
6
|
/** The render (or the app) wrote a cookie — always per-request. */
|
|
8
7
|
wrote_cookie: boolean;
|
|
9
8
|
}
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Returns the live observation the verdict reads after the render.
|
|
13
|
-
* (the event dies with the request) — nothing to restore.
|
|
10
|
+
* Note the event's personal reads from now on, and record its cookie writes (patched in place, per
|
|
11
|
+
* request: the event dies with it). Returns the live observation the verdict reads after the render.
|
|
14
12
|
*/
|
|
15
|
-
export declare function observe_event(
|
|
16
|
-
perVisitor: string | null;
|
|
17
|
-
}): Observation;
|
|
13
|
+
export declare function observe_event(ctx: Pick<RequestContext<unknown, unknown>, "event" | "facts" | "app">): Observation;
|