@cloudhal/astro-renderer 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +36 -2
- package/dist/src/ambient-client.d.ts +17 -0
- package/dist/src/ambient-client.js +55 -0
- package/dist/src/analytics-client.d.ts +17 -0
- package/dist/src/analytics-client.js +96 -0
- package/dist/src/analytics-middleware.d.ts +6 -0
- package/dist/src/analytics-middleware.js +43 -0
- package/dist/src/analytics-node.d.ts +46 -0
- package/dist/src/analytics-node.js +134 -0
- package/dist/src/analytics.d.ts +117 -0
- package/dist/src/analytics.js +372 -0
- package/dist/src/archive.d.ts +106 -0
- package/dist/src/archive.js +207 -0
- package/dist/src/astro-env.d.ts +21 -0
- package/dist/src/block-html.d.ts +14 -0
- package/dist/src/block-html.js +103 -0
- package/dist/src/blocks.d.ts +24 -0
- package/dist/src/blocks.js +66 -0
- package/dist/src/cache-tags.d.ts +25 -0
- package/dist/src/cache-tags.js +59 -0
- package/dist/src/carousel-client.d.ts +28 -0
- package/dist/src/carousel-client.js +67 -0
- package/dist/src/chart.d.ts +34 -0
- package/dist/src/chart.js +182 -0
- package/dist/src/chrome-client.d.ts +27 -0
- package/dist/src/chrome-client.js +64 -0
- package/dist/src/cloudflare-entry.d.ts +87 -0
- package/dist/src/cloudflare-entry.js +548 -0
- package/dist/src/comments-client.d.ts +11 -0
- package/dist/src/comments-client.js +58 -0
- package/dist/src/comments-html.d.ts +42 -0
- package/dist/src/comments-html.js +303 -0
- package/dist/src/comments-middleware.d.ts +6 -0
- package/dist/src/comments-middleware.js +38 -0
- package/dist/src/comments-node.d.ts +42 -0
- package/dist/src/comments-node.js +112 -0
- package/dist/src/comments-view.d.ts +68 -0
- package/dist/src/comments-view.js +174 -0
- package/dist/src/comments.d.ts +66 -0
- package/dist/src/comments.js +258 -0
- package/dist/src/components/Block.astro +39 -0
- package/dist/src/components/Body.astro +43 -0
- package/dist/src/components/Comments.astro +19 -0
- package/dist/src/components/ContentList.astro +31 -0
- package/dist/src/components/EntryArticle.astro +31 -0
- package/dist/src/components/Hero.astro +36 -0
- package/dist/src/components/Image.astro +36 -0
- package/dist/src/components/RichText.astro +19 -0
- package/dist/src/components/Sections.astro +66 -0
- package/dist/src/components/SeoHead.astro +22 -0
- package/dist/src/components/Surface.astro +36 -0
- package/dist/src/components/SurfaceNode.astro +82 -0
- package/dist/src/components/index.d.ts +12 -0
- package/dist/src/components/index.js +12 -0
- package/dist/src/csp.d.ts +20 -0
- package/dist/src/csp.js +28 -0
- package/dist/src/embed-client.d.ts +38 -0
- package/dist/src/embed-client.js +98 -0
- package/dist/src/embed-middleware.d.ts +9 -0
- package/dist/src/embed-middleware.js +49 -0
- package/dist/src/feeds.d.ts +72 -0
- package/dist/src/feeds.js +246 -0
- package/dist/src/gates.d.ts +25 -0
- package/dist/src/gates.js +63 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +17 -0
- package/dist/src/integration.d.ts +55 -0
- package/dist/src/integration.js +244 -0
- package/dist/src/kit.d.ts +48 -0
- package/dist/src/kit.js +83 -0
- package/dist/src/locale-feeds.d.ts +29 -0
- package/dist/src/locale-feeds.js +152 -0
- package/dist/src/locale-middleware.d.ts +5 -0
- package/dist/src/locale-middleware.js +26 -0
- package/dist/src/locales.d.ts +87 -0
- package/dist/src/locales.js +336 -0
- package/dist/src/markdown.d.ts +83 -0
- package/dist/src/markdown.js +533 -0
- package/dist/src/media-middleware.d.ts +5 -0
- package/dist/src/media-middleware.js +18 -0
- package/dist/src/media-route.d.ts +47 -0
- package/dist/src/media-route.js +238 -0
- package/dist/src/media.d.ts +109 -0
- package/dist/src/media.js +298 -0
- package/dist/src/motion-client.d.ts +39 -0
- package/dist/src/motion-client.js +115 -0
- package/dist/src/navigation.d.ts +127 -0
- package/dist/src/navigation.js +382 -0
- package/dist/src/not-found.d.ts +16 -0
- package/dist/src/not-found.js +41 -0
- package/dist/src/overlay-client.d.ts +20 -0
- package/dist/src/overlay-client.js +49 -0
- package/dist/src/prefs-client.d.ts +14 -0
- package/dist/src/prefs-client.js +18 -0
- package/dist/src/preview.d.ts +70 -0
- package/dist/src/preview.js +551 -0
- package/dist/src/resolver.d.ts +71 -0
- package/dist/src/resolver.js +206 -0
- package/dist/src/routing.d.ts +108 -0
- package/dist/src/routing.js +285 -0
- package/dist/src/runtime-workerd.d.ts +87 -0
- package/dist/src/runtime-workerd.js +275 -0
- package/dist/src/runtime.d.ts +59 -0
- package/dist/src/runtime.js +153 -0
- package/dist/src/safe-urls.d.ts +13 -0
- package/dist/src/safe-urls.js +35 -0
- package/dist/src/sanitize.d.ts +7 -0
- package/dist/src/sanitize.js +217 -0
- package/dist/src/search-client.d.ts +29 -0
- package/dist/src/search-client.js +92 -0
- package/dist/src/search-limit.d.ts +36 -0
- package/dist/src/search-limit.js +66 -0
- package/dist/src/search.d.ts +64 -0
- package/dist/src/search.js +155 -0
- package/dist/src/seo.d.ts +85 -0
- package/dist/src/seo.js +468 -0
- package/dist/src/site-dispatch.d.ts +37 -0
- package/dist/src/site-dispatch.js +86 -0
- package/dist/src/site-hosts.d.ts +35 -0
- package/dist/src/site-hosts.js +110 -0
- package/dist/src/source.d.ts +227 -0
- package/dist/src/source.js +794 -0
- package/dist/src/static-gates.d.ts +3 -0
- package/dist/src/static-gates.js +28 -0
- package/dist/src/static-headers.d.ts +30 -0
- package/dist/src/static-headers.js +140 -0
- package/dist/src/static-media.d.ts +4 -0
- package/dist/src/static-media.js +65 -0
- package/dist/src/static-redirects.d.ts +4 -0
- package/dist/src/static-redirects.js +40 -0
- package/dist/src/surface-client.d.ts +34 -0
- package/dist/src/surface-client.js +146 -0
- package/dist/src/surfaces/html.d.ts +35 -0
- package/dist/src/surfaces/html.js +184 -0
- package/dist/src/surfaces/markup.d.ts +57 -0
- package/dist/src/surfaces/markup.js +135 -0
- package/dist/src/surfaces/motion.d.ts +33 -0
- package/dist/src/surfaces/motion.js +132 -0
- package/dist/src/surfaces/primitives/carousel.d.ts +2 -0
- package/dist/src/surfaces/primitives/carousel.js +95 -0
- package/dist/src/surfaces/primitives/content.d.ts +13 -0
- package/dist/src/surfaces/primitives/content.js +159 -0
- package/dist/src/surfaces/primitives/data.d.ts +5 -0
- package/dist/src/surfaces/primitives/data.js +80 -0
- package/dist/src/surfaces/primitives/index.d.ts +54 -0
- package/dist/src/surfaces/primitives/index.js +106 -0
- package/dist/src/surfaces/primitives/inputs.d.ts +8 -0
- package/dist/src/surfaces/primitives/inputs.js +68 -0
- package/dist/src/surfaces/primitives/layout.d.ts +14 -0
- package/dist/src/surfaces/primitives/layout.js +61 -0
- package/dist/src/surfaces/primitives/motion.d.ts +9 -0
- package/dist/src/surfaces/primitives/motion.js +45 -0
- package/dist/src/surfaces/primitives/overlays.d.ts +6 -0
- package/dist/src/surfaces/primitives/overlays.js +79 -0
- package/dist/src/surfaces/tree.d.ts +107 -0
- package/dist/src/surfaces/tree.js +321 -0
- package/dist/src/surfaces.d.ts +14 -0
- package/dist/src/surfaces.js +33 -0
- package/dist/src/taxonomy.d.ts +86 -0
- package/dist/src/taxonomy.js +268 -0
- package/dist/src/theme-settings.d.ts +24 -0
- package/dist/src/theme-settings.js +111 -0
- package/package.json +219 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0034 §4: which site a request is for, from its hostname. A multi-site Worker serves the sites
|
|
3
|
+
* in its allow-list (`CLOUDHAL_SITE_IDS`); `site_hosts` (written by the API with every site change)
|
|
4
|
+
* maps hostnames to them. Up to `MAX_PRELOAD` hosts the whole map is held in the isolate and
|
|
5
|
+
* reloaded after `ttlMs` or on a purge; beyond that each hostname is looked up on first use and
|
|
6
|
+
* kept for `ttlMs`. A hostname whose site is not in the allow-list is unknown: never another site.
|
|
7
|
+
*
|
|
8
|
+
* Worker-safe: SQL only, the clock injected.
|
|
9
|
+
*/
|
|
10
|
+
import type { SqlDriver } from "@cloudhal/storage";
|
|
11
|
+
export interface HostMatch {
|
|
12
|
+
readonly siteId: string;
|
|
13
|
+
/** A per-locale domain (`Site.localization.domains`): this locale is served at the root. */
|
|
14
|
+
readonly locale?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Hosts held in memory at once; more than this and hostnames are looked up one by one. */
|
|
17
|
+
export declare const MAX_PRELOAD = 1000;
|
|
18
|
+
/** `CLOUDHAL_SITE_IDS`: comma- or space-separated site ids, each once, in order. */
|
|
19
|
+
export declare function parseSiteIds(value: string | undefined): string[];
|
|
20
|
+
export declare class SiteHostMap {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(options: {
|
|
23
|
+
sql: () => SqlDriver;
|
|
24
|
+
siteIds: readonly string[];
|
|
25
|
+
ttlMs?: number;
|
|
26
|
+
now?: () => number;
|
|
27
|
+
});
|
|
28
|
+
get siteIds(): readonly string[];
|
|
29
|
+
/** Forget what was loaded (a purge: the site's domains may have changed). */
|
|
30
|
+
reset(): void;
|
|
31
|
+
/** The site (and locale) `host` serves, or undefined when it serves none of the allowed sites. */
|
|
32
|
+
lookup(host: string): Promise<HostMatch | undefined>;
|
|
33
|
+
/** The hostnames of one site, as last loaded (same-origin checks for analytics and comments). */
|
|
34
|
+
hostsOf(siteId: string): Promise<string[]>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0034 §4: which site a request is for, from its hostname. A multi-site Worker serves the sites
|
|
3
|
+
* in its allow-list (`CLOUDHAL_SITE_IDS`); `site_hosts` (written by the API with every site change)
|
|
4
|
+
* maps hostnames to them. Up to `MAX_PRELOAD` hosts the whole map is held in the isolate and
|
|
5
|
+
* reloaded after `ttlMs` or on a purge; beyond that each hostname is looked up on first use and
|
|
6
|
+
* kept for `ttlMs`. A hostname whose site is not in the allow-list is unknown: never another site.
|
|
7
|
+
*
|
|
8
|
+
* Worker-safe: SQL only, the clock injected.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/** Hosts held in memory at once; more than this and hostnames are looked up one by one. */
|
|
19
|
+
export const MAX_PRELOAD = 1000;
|
|
20
|
+
|
|
21
|
+
/** `CLOUDHAL_SITE_IDS`: comma- or space-separated site ids, each once, in order. */
|
|
22
|
+
export function parseSiteIds(value ) {
|
|
23
|
+
return [...new Set((value ?? "").split(/[\s,]+/).filter(Boolean))];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export class SiteHostMap {
|
|
29
|
+
#sql ;
|
|
30
|
+
#siteIds ;
|
|
31
|
+
#ttlMs ;
|
|
32
|
+
#now ;
|
|
33
|
+
#all ;
|
|
34
|
+
#one = new Map ();
|
|
35
|
+
|
|
36
|
+
constructor(options
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
) {
|
|
42
|
+
this.#sql = options.sql;
|
|
43
|
+
this.#siteIds = options.siteIds;
|
|
44
|
+
this.#ttlMs = options.ttlMs ?? 60_000;
|
|
45
|
+
this.#now = options.now ?? Date.now;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get siteIds() {
|
|
49
|
+
return this.#siteIds;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Forget what was loaded (a purge: the site's domains may have changed). */
|
|
53
|
+
reset() {
|
|
54
|
+
this.#all = undefined;
|
|
55
|
+
this.#one.clear();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The site (and locale) `host` serves, or undefined when it serves none of the allowed sites. */
|
|
59
|
+
async lookup(host ) {
|
|
60
|
+
const key = host.toLowerCase().replace(/\.$/, "");
|
|
61
|
+
const all = await this.#preload();
|
|
62
|
+
if (all !== "too-many") return all.get(key);
|
|
63
|
+
const hit = this.#one.get(key);
|
|
64
|
+
if (hit && this.#now() - hit.at < this.#ttlMs) return hit.match;
|
|
65
|
+
const row = await this.#sql().get (
|
|
66
|
+
`SELECT host, site_id, locale FROM site_hosts WHERE host = ? AND site_id IN (${this.#marks()})`,
|
|
67
|
+
[key, ...this.#siteIds],
|
|
68
|
+
);
|
|
69
|
+
const match = row ? toMatch(row) : undefined;
|
|
70
|
+
this.#one.set(key, { at: this.#now(), match });
|
|
71
|
+
return match;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The hostnames of one site, as last loaded (same-origin checks for analytics and comments). */
|
|
75
|
+
async hostsOf(siteId ) {
|
|
76
|
+
const all = await this.#preload();
|
|
77
|
+
if (all === "too-many") {
|
|
78
|
+
const rows = await this.#sql().all (
|
|
79
|
+
"SELECT host FROM site_hosts WHERE site_id = ? ORDER BY host",
|
|
80
|
+
[siteId],
|
|
81
|
+
);
|
|
82
|
+
return rows.map((r) => r.host);
|
|
83
|
+
}
|
|
84
|
+
return [...all].filter(([, m]) => m.siteId === siteId).map(([h]) => h);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async #preload() {
|
|
88
|
+
if (this.#all && this.#now() - this.#all.at < this.#ttlMs) return this.#all.hosts;
|
|
89
|
+
if (this.#siteIds.length === 0) {
|
|
90
|
+
this.#all = { at: this.#now(), hosts: new Map() };
|
|
91
|
+
return this.#all.hosts;
|
|
92
|
+
}
|
|
93
|
+
const rows = await this.#sql().all (
|
|
94
|
+
`SELECT host, site_id, locale FROM site_hosts WHERE site_id IN (${this.#marks()}) LIMIT ${MAX_PRELOAD + 1}`,
|
|
95
|
+
[...this.#siteIds],
|
|
96
|
+
);
|
|
97
|
+
const hosts =
|
|
98
|
+
rows.length > MAX_PRELOAD ? "too-many" : new Map(rows.map((r) => [r.host, toMatch(r)]));
|
|
99
|
+
this.#all = { at: this.#now(), hosts };
|
|
100
|
+
return hosts;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#marks() {
|
|
104
|
+
return this.#siteIds.map(() => "?").join(", ");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function toMatch(r ) {
|
|
109
|
+
return { siteId: r.site_id, ...(r.locale ? { locale: r.locale } : {}) };
|
|
110
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { Asset, ContentEntry, Menu, Page, Redirect, Site, Snapshot, Taxonomy, Term } from "@cloudhal/core-contracts";
|
|
2
|
+
import type { RedirectMatch, SearchKind, SearchResults, SiteGraphStore } from "@cloudhal/core-ts";
|
|
3
|
+
import { type Navigation, type NavigationOptions } from "./navigation.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a renderer needs from a site, independent of whether it reads live nodes (dev) or a
|
|
6
|
+
* published snapshot (build/production).
|
|
7
|
+
*/
|
|
8
|
+
export interface GraphSource {
|
|
9
|
+
readonly mode: "live" | "snapshot";
|
|
10
|
+
site(): Promise<Site>;
|
|
11
|
+
pages(): Promise<Page[]>;
|
|
12
|
+
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
13
|
+
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
14
|
+
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
15
|
+
/** Every visible entry of a locale, newest first, across collections (feeds, sitemaps). */
|
|
16
|
+
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
17
|
+
/**
|
|
18
|
+
* A visible entry by id, any locale (reader comments name the entry by id, RFC-0007 §6.2).
|
|
19
|
+
* Optional for sources that predate comments.
|
|
20
|
+
*/
|
|
21
|
+
entryById?(id: string): Promise<ContentEntry | undefined>;
|
|
22
|
+
/** The site's taxonomies (RFC-0002). */
|
|
23
|
+
taxonomies(): Promise<Taxonomy[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Terms of a taxonomy that may be shown, by `position`, then name. Snapshot mode (and live mode
|
|
26
|
+
* without drafts): active and public only. Live mode with drafts: every non-retired term.
|
|
27
|
+
*/
|
|
28
|
+
terms(key: string): Promise<Term[]>;
|
|
29
|
+
/** A shown term by its current slug (old slugs answer with a redirect, not a term). */
|
|
30
|
+
termBySlug(key: string, slug: string): Promise<Term | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Every term of a taxonomy (or of the site, without `key`) in any status: proposed, internal and
|
|
33
|
+
* retired terms included. Routes need them to tell a 404 from a 410; never list them publicly.
|
|
34
|
+
*/
|
|
35
|
+
vocabulary(key?: string): Promise<Term[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Visible entries matching a filter expression (RFC-0002 §5), newest first. Unknown terms match
|
|
38
|
+
* nothing (a published snapshot must keep rendering) and are logged.
|
|
39
|
+
*/
|
|
40
|
+
entriesByFilter(filter: string, options?: {
|
|
41
|
+
locale?: string;
|
|
42
|
+
limit?: number;
|
|
43
|
+
}): Promise<ContentEntry[]>;
|
|
44
|
+
/** Visible entries assigned to a term (with `descendants`, also to its sub-terms), newest first. */
|
|
45
|
+
entriesByTerm(key: string, slug: string, options?: {
|
|
46
|
+
locale?: string;
|
|
47
|
+
limit?: number;
|
|
48
|
+
descendants?: boolean;
|
|
49
|
+
}): Promise<ContentEntry[]>;
|
|
50
|
+
/** The redirect for a request path in a locale (default: the site's): exact, then longest prefix. */
|
|
51
|
+
redirectFor(path: string, locale?: string): Promise<RedirectMatch | undefined>;
|
|
52
|
+
/** Every redirect of the site (static builds write them out; see `redirectsFile`). */
|
|
53
|
+
redirects(): Promise<Redirect[]>;
|
|
54
|
+
/** The menu stored under `key`, if the site has one (raw node, RFC-0003). */
|
|
55
|
+
menu(key: string): Promise<Menu | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* The menu under `key` resolved for a locale (default: the site's): only shown items, with labels
|
|
58
|
+
* and hrefs. Undefined: no menu under `key` (themes fall back to `derivedNavigation`).
|
|
59
|
+
*/
|
|
60
|
+
navigation(key: string, locale?: string, options?: NavigationOptions): Promise<Navigation | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* RFC-0004: every asset this source shows — a snapshot's captured assets, or the site's current
|
|
63
|
+
* ones (any status: retired assets keep rendering where they are used). Optional for sources
|
|
64
|
+
* that predate media.
|
|
65
|
+
*/
|
|
66
|
+
assets?(): Promise<Asset[]>;
|
|
67
|
+
/** The asset with this id, if this source shows it. */
|
|
68
|
+
asset?(id: string): Promise<Asset | undefined>;
|
|
69
|
+
/** The asset behind a media URL's 16-hex prefix (the media route). */
|
|
70
|
+
assetByPrefix?(prefix16: string): Promise<Asset | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* RFC-0008 §7.4: the next instant (ms since the epoch) at which a time gate changes what this
|
|
73
|
+
* source shows; undefined when none lies ahead or the source ignores gates (previews, drafts).
|
|
74
|
+
* Optional for sources that predate gates.
|
|
75
|
+
*/
|
|
76
|
+
nextGate?(): Promise<number | undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* RFC-0019 §3: articles matching a reader's query, best first. Snapshot mode reads the search
|
|
79
|
+
* index (it matches the live snapshot; `stale` says when it is behind); live mode searches the
|
|
80
|
+
* entries it shows, drafts included. Optional for sources that predate search.
|
|
81
|
+
*/
|
|
82
|
+
search?(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
83
|
+
}
|
|
84
|
+
export interface SourceSearchOptions {
|
|
85
|
+
page?: number;
|
|
86
|
+
perPage?: number;
|
|
87
|
+
/** Default: the site's default locale. */
|
|
88
|
+
locale?: string;
|
|
89
|
+
/** RFC-0029: only these kinds (default: all). */
|
|
90
|
+
kinds?: readonly SearchKind[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reads the current nodes on every call. Drafts are included so authors can preview them in dev,
|
|
94
|
+
* and so are gated nodes (a preview shows embargoed and expired content, RFC-0008 §7.3). Without
|
|
95
|
+
* drafts it serves what the public would see: published nodes whose gates are open at `now`.
|
|
96
|
+
*/
|
|
97
|
+
export declare class LiveSource implements GraphSource {
|
|
98
|
+
#private;
|
|
99
|
+
readonly mode = "live";
|
|
100
|
+
constructor(store: SiteGraphStore, siteId: string, options?: {
|
|
101
|
+
includeDrafts?: boolean;
|
|
102
|
+
now?: () => number;
|
|
103
|
+
});
|
|
104
|
+
nextGate(): Promise<number | undefined>;
|
|
105
|
+
site(): Promise<Site>;
|
|
106
|
+
pages(): Promise<Page[]>;
|
|
107
|
+
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
108
|
+
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
109
|
+
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
110
|
+
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
111
|
+
search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
112
|
+
entryById(id: string): Promise<ContentEntry | undefined>;
|
|
113
|
+
taxonomies(): Promise<Taxonomy[]>;
|
|
114
|
+
terms(key: string): Promise<Term[]>;
|
|
115
|
+
termBySlug(key: string, slug: string): Promise<Term | undefined>;
|
|
116
|
+
vocabulary(key?: string): Promise<Term[]>;
|
|
117
|
+
entriesByFilter(filter: string, options?: {
|
|
118
|
+
locale?: string;
|
|
119
|
+
limit?: number;
|
|
120
|
+
}): Promise<ContentEntry[]>;
|
|
121
|
+
entriesByTerm(key: string, slug: string, options?: {
|
|
122
|
+
locale?: string;
|
|
123
|
+
limit?: number;
|
|
124
|
+
descendants?: boolean;
|
|
125
|
+
}): Promise<ContentEntry[]>;
|
|
126
|
+
redirectFor(path: string, locale?: string): Promise<RedirectMatch | undefined>;
|
|
127
|
+
redirects(): Promise<Redirect[]>;
|
|
128
|
+
menu(key: string): Promise<Menu | undefined>;
|
|
129
|
+
navigation(key: string, locale?: string, options?: NavigationOptions): Promise<Navigation | undefined>;
|
|
130
|
+
assets(): Promise<Asset[]>;
|
|
131
|
+
asset(id: string): Promise<Asset | undefined>;
|
|
132
|
+
assetByPrefix(prefix16: string): Promise<Asset | undefined>;
|
|
133
|
+
}
|
|
134
|
+
/** Everything a snapshot shows before gates are applied; built once per snapshot and isolate. */
|
|
135
|
+
interface Loaded {
|
|
136
|
+
site: Site;
|
|
137
|
+
/** Published pages in `Site.pageIds` order and published entries, gates not yet applied. */
|
|
138
|
+
pages: Page[];
|
|
139
|
+
entries: ContentEntry[];
|
|
140
|
+
taxonomies: Taxonomy[];
|
|
141
|
+
terms: Term[];
|
|
142
|
+
redirects: Redirect[];
|
|
143
|
+
menus: Menu[];
|
|
144
|
+
assets: Asset[];
|
|
145
|
+
/** Assets by id and by 16-hex URL prefix, built once per snapshot (RFC-0004 §7.1). */
|
|
146
|
+
assetIndex: Map<string, Asset>;
|
|
147
|
+
/**
|
|
148
|
+
* The gate index (RFC-0008 §7.4): every instant at which a published page's or entry's gate
|
|
149
|
+
* changes, sorted. Empty for a site that schedules nothing — then nothing is filtered at all.
|
|
150
|
+
*/
|
|
151
|
+
gates: number[];
|
|
152
|
+
}
|
|
153
|
+
/** State shared by every view of one snapshot: the loaded nodes and the asset gates. */
|
|
154
|
+
interface Shared {
|
|
155
|
+
loaded?: Promise<Loaded> | undefined;
|
|
156
|
+
assetGates?: Promise<ReadonlyMap<string, number>>;
|
|
157
|
+
/** RFC-0010: whether the snapshot's bundle was there when it loaded, or is being written. */
|
|
158
|
+
bundle?: "present" | "missing" | "persisting";
|
|
159
|
+
/** Bodies read node by node (no bundle), as stored JSON text, kept to write the bundle. */
|
|
160
|
+
fetched?: Map<string, string> | undefined;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Reads exactly the node bodies captured in a snapshot (immutable; only published nodes are
|
|
164
|
+
* rendered). Time gates (RFC-0008 §7) apply on top: by default against the wall clock at each
|
|
165
|
+
* call; `at(now)` fixes the instant for one request (the Site Worker does, so a page and the
|
|
166
|
+
* lists on it agree); `ungated()` is the preview view, which shows gated nodes.
|
|
167
|
+
*/
|
|
168
|
+
export declare class SnapshotSource implements GraphSource {
|
|
169
|
+
#private;
|
|
170
|
+
readonly mode = "snapshot";
|
|
171
|
+
constructor(store: SiteGraphStore, snapshot: Snapshot, options?: {
|
|
172
|
+
now?: () => number;
|
|
173
|
+
shared?: Shared;
|
|
174
|
+
ungated?: boolean;
|
|
175
|
+
});
|
|
176
|
+
static open(store: SiteGraphStore, snapshotId: string): Promise<SnapshotSource>;
|
|
177
|
+
get snapshot(): Snapshot;
|
|
178
|
+
/** This snapshot as the public sees it at `now` (one instant for a whole request). */
|
|
179
|
+
at(now: number): SnapshotSource;
|
|
180
|
+
/** This snapshot with gates ignored: previews show embargoed and expired nodes (§7.3). */
|
|
181
|
+
ungated(): SnapshotSource;
|
|
182
|
+
/** True when this view ignores gates (a preview). */
|
|
183
|
+
get gatesIgnored(): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* The next instant (ms) at which anything this snapshot shows changes because of a gate, after
|
|
186
|
+
* this view's `now`; undefined when no gate lies ahead (or gates are ignored). The Site Worker
|
|
187
|
+
* caps the edge cache with it (§7.4).
|
|
188
|
+
*/
|
|
189
|
+
nextGate(): Promise<number | undefined>;
|
|
190
|
+
/**
|
|
191
|
+
* RFC-0010 read-through: when this snapshot loaded without a bundle, write one in the background
|
|
192
|
+
* (`defer` keeps the task alive, e.g. the Worker's `waitUntil`). The resolver calls it for the
|
|
193
|
+
* published snapshot only: previews and history never get a bundle. Never throws; a failed write
|
|
194
|
+
* leaves the snapshot loading node by node, and the next request tries again.
|
|
195
|
+
*/
|
|
196
|
+
persistBundle(defer: (task: Promise<unknown>) => void): void;
|
|
197
|
+
site(): Promise<Site>;
|
|
198
|
+
pages(): Promise<Page[]>;
|
|
199
|
+
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
200
|
+
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
201
|
+
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
202
|
+
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
203
|
+
search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
204
|
+
/** A published entry of this snapshot by id (any locale), if its gates are open. */
|
|
205
|
+
entryById(id: string): Promise<ContentEntry | undefined>;
|
|
206
|
+
taxonomies(): Promise<Taxonomy[]>;
|
|
207
|
+
terms(key: string): Promise<Term[]>;
|
|
208
|
+
termBySlug(key: string, slug: string): Promise<Term | undefined>;
|
|
209
|
+
vocabulary(key?: string): Promise<Term[]>;
|
|
210
|
+
entriesByFilter(filter: string, options?: {
|
|
211
|
+
locale?: string;
|
|
212
|
+
limit?: number;
|
|
213
|
+
}): Promise<ContentEntry[]>;
|
|
214
|
+
entriesByTerm(key: string, slug: string, options?: {
|
|
215
|
+
locale?: string;
|
|
216
|
+
limit?: number;
|
|
217
|
+
descendants?: boolean;
|
|
218
|
+
}): Promise<ContentEntry[]>;
|
|
219
|
+
redirectFor(path: string, locale?: string): Promise<RedirectMatch | undefined>;
|
|
220
|
+
redirects(): Promise<Redirect[]>;
|
|
221
|
+
menu(key: string): Promise<Menu | undefined>;
|
|
222
|
+
navigation(key: string, locale?: string, options?: NavigationOptions): Promise<Navigation | undefined>;
|
|
223
|
+
assets(): Promise<Asset[]>;
|
|
224
|
+
asset(id: string): Promise<Asset | undefined>;
|
|
225
|
+
assetByPrefix(prefix16: string): Promise<Asset | undefined>;
|
|
226
|
+
}
|
|
227
|
+
export {};
|