@hollware/nuxt 1.0.0-rc.7 → 1.0.0-rc.9

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/index.d.mts CHANGED
@@ -39,8 +39,6 @@ export interface ModuleOptions {
39
39
  webhookSecret?: string;
40
40
  }
41
41
  export declare const name = "@hollware/nuxt";
42
- /** The routes of the site that read Hollware for its pages, on the server. */
43
- export declare const ROUTES: readonly [readonly ['/_hollware/site', 'site'], readonly ['/_hollware/entries/:collection', 'entries'], readonly ['/_hollware/entry/:collection/:locale/:slug', 'entry'], readonly ['/_hollware/translations/:collection/:group', 'translations']];
44
42
  declare const _default: import("nuxt/schema").NuxtModule<ModuleOptions, ModuleOptions, false>;
45
43
  //#endregion
46
44
  export { type PageEntry, _default as default };
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
- import { PREVIEW_HEADER } from "./runtime/tags.mjs";
1
+ import { secondsCacheRules } from "./route-rules.mjs";
2
2
  import { addComponent, addImports, addPlugin, addServerHandler, addServerImports, addServerPlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
3
3
  //#region src/index.ts
4
4
  const name = "@hollware/nuxt";
5
- /** The routes of the site that read Hollware for its pages, on the server. */
6
5
  const ROUTES = [
7
6
  ["/_hollware/site", "site"],
8
7
  ["/_hollware/entries/:collection", "entries"],
@@ -71,23 +70,11 @@ var src_default = defineNuxtModule({
71
70
  handler: resolve("./runtime/server/routes/webhook")
72
71
  });
73
72
  }
74
- if (typeof options.cache === "number" && options.cache > 0) {
75
- const pages = { cache: {
76
- swr: true,
77
- maxAge: options.cache,
78
- varies: [PREVIEW_HEADER]
79
- } };
80
- const routes = {
81
- swr: false,
82
- cache: false
83
- };
84
- nuxt.options.routeRules = {
85
- "/**": pages,
86
- "/_hollware/**": routes,
87
- ...nuxt.options.routeRules
88
- };
89
- }
73
+ if (typeof options.cache === "number" && options.cache > 0) nuxt.options.routeRules = {
74
+ ...secondsCacheRules(options.cache),
75
+ ...nuxt.options.routeRules
76
+ };
90
77
  }
91
78
  });
92
79
  //#endregion
93
- export { ROUTES, src_default as default, name };
80
+ export { src_default as default, name };
@@ -0,0 +1,17 @@
1
+ import { PREVIEW_HEADER } from "./runtime/tags.mjs";
2
+ //#region src/route-rules.ts
3
+ function secondsCacheRules(seconds) {
4
+ return {
5
+ "/**": { cache: {
6
+ swr: true,
7
+ maxAge: seconds,
8
+ varies: [PREVIEW_HEADER]
9
+ } },
10
+ "/_hollware/**": {
11
+ swr: false,
12
+ cache: false
13
+ }
14
+ };
15
+ }
16
+ //#endregion
17
+ export { secondsCacheRules };
@@ -1,11 +1,6 @@
1
1
  import { PropType } from "vue";
2
2
  //#region src/runtime/components/HollwareContent.d.ts
3
- /**
4
- * The body of an entry: the Comark document Hollware stored when it was written, rendered with
5
- * `@comark/vue`. `components` maps the names of the entry's components to the site's own.
6
- */
7
3
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
8
- /** An entry as `useHollwareEntry` gives it, with its `document`. */
9
4
  entry: {
10
5
  type: PropType<{
11
6
  document?: unknown;
@@ -19,7 +14,6 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
19
14
  }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
20
15
  [key: string]: any;
21
16
  }> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
22
- /** An entry as `useHollwareEntry` gives it, with its `document`. */
23
17
  entry: {
24
18
  type: PropType<{
25
19
  document?: unknown;
@@ -1,14 +1,9 @@
1
1
  import { defineComponent, h } from "vue";
2
2
  import { MarkdownDocument } from "@comark/vue";
3
3
  //#region src/runtime/components/HollwareContent.ts
4
- /**
5
- * The body of an entry: the Comark document Hollware stored when it was written, rendered with
6
- * `@comark/vue`. `components` maps the names of the entry's components to the site's own.
7
- */
8
4
  var HollwareContent_default = defineComponent({
9
5
  name: "HollwareContent",
10
6
  props: {
11
- /** An entry as `useHollwareEntry` gives it, with its `document`. */
12
7
  entry: {
13
8
  type: Object,
14
9
  default: null
@@ -1,18 +1,11 @@
1
- import { PropType } from "vue";
2
1
  import { imageOf } from "@hollware/client";
2
+ import { PropType } from "vue";
3
3
  //#region src/runtime/components/HollwareImage.d.ts
4
- /**
5
- * The image a frontmatter field holds, such as the cover of a post: an `<img>` with its alt, its
6
- * size and the `srcset` of the copies Hollware made of it. An attribute given on the component
7
- * wins. Nothing renders when the field holds no image.
8
- */
9
4
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
10
- /** An entry or a summary as `useHollwareEntry` or `useHollwareEntries` gives it. */
11
5
  entry: {
12
6
  type: PropType<Parameters<typeof imageOf>[0]>;
13
7
  default: null;
14
8
  };
15
- /** The frontmatter field that holds the image, such as `img` or `cover`. */
16
9
  field: {
17
10
  type: StringConstructor;
18
11
  required: true;
@@ -20,12 +13,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
20
13
  }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
21
14
  [key: string]: any;
22
15
  }> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
23
- /** An entry or a summary as `useHollwareEntry` or `useHollwareEntries` gives it. */
24
16
  entry: {
25
17
  type: PropType<Parameters<typeof imageOf>[0]>;
26
18
  default: null;
27
19
  };
28
- /** The frontmatter field that holds the image, such as `img` or `cover`. */
29
20
  field: {
30
21
  type: StringConstructor;
31
22
  required: true;
@@ -1,20 +1,13 @@
1
- import { defineComponent, h } from "vue";
2
1
  import { imageOf } from "@hollware/client";
2
+ import { defineComponent, h } from "vue";
3
3
  //#region src/runtime/components/HollwareImage.ts
4
- /**
5
- * The image a frontmatter field holds, such as the cover of a post: an `<img>` with its alt, its
6
- * size and the `srcset` of the copies Hollware made of it. An attribute given on the component
7
- * wins. Nothing renders when the field holds no image.
8
- */
9
4
  var HollwareImage_default = defineComponent({
10
5
  name: "HollwareImage",
11
6
  props: {
12
- /** An entry or a summary as `useHollwareEntry` or `useHollwareEntries` gives it. */
13
7
  entry: {
14
8
  type: Object,
15
9
  default: null
16
10
  },
17
- /** The frontmatter field that holds the image, such as `img` or `cover`. */
18
11
  field: {
19
12
  type: String,
20
13
  required: true
@@ -1,40 +1,26 @@
1
1
  import { PageEntry } from "./types.mjs";
2
2
  import { MaybeRefOrGetter } from "vue";
3
3
  //#region src/runtime/composables.d.ts
4
- /**
5
- * An entry, with its Comark document; `data` is null while it loads, `error` a 404 when it is not
6
- * published. A visitor who opened the admin's "Preview on the site" link has the token in the
7
- * `hollware_preview` cookie (the server exchanged it for the link's `?hollware-preview=`), and the
8
- * `/_hollware/entry` route reads the latest revision of that entry instead: a draft too. The page
9
- * then answers `no-store`; a token that does not hold (expired, of another entry) is an error,
10
- * never the published version, and when Hollware says it expired or is invalid the response
11
- * clears the cookie.
12
- */
13
4
  export declare function useHollwareEntry(collection: MaybeRefOrGetter<string>, locale: MaybeRefOrGetter<string>, slug: MaybeRefOrGetter<string>): import("nuxt/app").AsyncData<{
14
5
  outcome: 'ok';
15
6
  entry: PageEntry;
16
7
  } | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
17
- /** A page of the published entries of a collection, newest first. */
18
8
  export declare function useHollwareEntries(collection: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<{
19
9
  locale?: string;
20
10
  tag?: string;
21
11
  limit?: number;
22
12
  cursor?: string;
23
- }>,
24
- /** `lazy: true` renders without waiting for the answer, as `useFetch` does. */
25
- fetching?: {
13
+ }>, fetching?: {
26
14
  lazy?: boolean;
27
15
  }): import("nuxt/app").AsyncData<{
28
16
  outcome: 'ok';
29
17
  entries: PageEntry[];
30
18
  nextCursor: string | null;
31
19
  } | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
32
- /** The entries of a translation group, one per locale. */
33
20
  export declare function useHollwareTranslations(collection: MaybeRefOrGetter<string>, group: MaybeRefOrGetter<string>): import("nuxt/app").AsyncData<{
34
21
  outcome: 'ok';
35
22
  entries: PageEntry[];
36
23
  } | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
37
- /** The site: its locales, its collections and their schemas. */
38
24
  export declare function useHollwareSite(): import("nuxt/app").AsyncData<{
39
25
  outcome: "ok";
40
26
  site: {
@@ -3,25 +3,9 @@ import { appendResponseHeader } from "h3";
3
3
  import { useFetch, useRequestEvent } from "nuxt/app";
4
4
  import { computed, toValue } from "vue";
5
5
  //#region src/runtime/composables.ts
6
- /**
7
- * The published content of the site, for a page: each reads the site's own `/_hollware/` route,
8
- * which reads Hollware on the server, so no token reaches the browser. They are `useFetch`, so the
9
- * page renders on the server with the answer and the browser does not ask again. On the server,
10
- * each records on the page's request the cache tags of what it read (S8).
11
- */
12
- /** The request of the page being rendered, on the server; none in the browser. */
13
6
  function pageRequest() {
14
7
  return import.meta.server ? useRequestEvent() : void 0;
15
8
  }
16
- /**
17
- * An entry, with its Comark document; `data` is null while it loads, `error` a 404 when it is not
18
- * published. A visitor who opened the admin's "Preview on the site" link has the token in the
19
- * `hollware_preview` cookie (the server exchanged it for the link's `?hollware-preview=`), and the
20
- * `/_hollware/entry` route reads the latest revision of that entry instead: a draft too. The page
21
- * then answers `no-store`; a token that does not hold (expired, of another entry) is an error,
22
- * never the published version, and when Hollware says it expired or is invalid the response
23
- * clears the cookie.
24
- */
25
9
  function useHollwareEntry(collection, locale, slug) {
26
10
  const path = computed(() => `/_hollware/entry/${encodeURIComponent(toValue(collection))}/${encodeURIComponent(toValue(locale))}/${encodeURIComponent(toValue(slug))}`);
27
11
  const event = pageRequest();
@@ -36,7 +20,6 @@ function useHollwareEntry(collection, locale, slug) {
36
20
  }
37
21
  });
38
22
  }
39
- /** A page of the published entries of a collection, newest first. */
40
23
  function useHollwareEntries(collection, options = {}, fetching = {}) {
41
24
  const path = computed(() => `/_hollware/entries/${encodeURIComponent(toValue(collection))}`);
42
25
  const event = pageRequest();
@@ -49,7 +32,6 @@ function useHollwareEntries(collection, options = {}, fetching = {}) {
49
32
  }
50
33
  });
51
34
  }
52
- /** The entries of a translation group, one per locale. */
53
35
  function useHollwareTranslations(collection, group) {
54
36
  const path = computed(() => `/_hollware/translations/${encodeURIComponent(toValue(collection))}/${encodeURIComponent(toValue(group))}`);
55
37
  const event = pageRequest();
@@ -58,7 +40,6 @@ function useHollwareTranslations(collection, group) {
58
40
  return answer;
59
41
  } });
60
42
  }
61
- /** The site: its locales, its collections and their schemas. */
62
43
  function useHollwareSite() {
63
44
  const event = pageRequest();
64
45
  return useFetch("/_hollware/site", { transform: (answer) => {
@@ -1,16 +1,7 @@
1
1
  import { H3Event } from "h3";
2
2
  //#region src/runtime/server/answer.d.ts
3
- /**
4
- * Hollware's answer as the site's own: a `not_found` outcome is a 404, a refusal of the read API
5
- * keeps its status, and the rest is the answer. Pages revalidate it: it is published content, and
6
- * a publication purges nothing on the site's side.
7
- */
8
3
  export declare function answer<Value extends {
9
4
  outcome: string;
10
5
  }>(event: H3Event, read: () => Promise<Value>): Promise<Value>;
11
- /**
12
- * An entry for a page: its verdict, its revision and its last publication stay on the server, as
13
- * the page sends what it read to the browser in its payload.
14
- */
15
6
  export declare function forPage(entry: unknown): Record<string, unknown> | undefined;
16
7
  //#endregion
@@ -1,11 +1,6 @@
1
- import { createError, setResponseHeader } from "h3";
2
1
  import { HollwareClientError } from "@hollware/client";
2
+ import { createError, setResponseHeader } from "h3";
3
3
  //#region src/runtime/server/answer.ts
4
- /**
5
- * Hollware's answer as the site's own: a `not_found` outcome is a 404, a refusal of the read API
6
- * keeps its status, and the rest is the answer. Pages revalidate it: it is published content, and
7
- * a publication purges nothing on the site's side.
8
- */
9
4
  async function answer(event, read) {
10
5
  let value;
11
6
  try {
@@ -24,7 +19,6 @@ async function answer(event, read) {
24
19
  setResponseHeader(event, "cache-control", "no-cache");
25
20
  return value;
26
21
  }
27
- /** The fields of an entry that a page shows: what a reader sees, and not how it was checked. */
28
22
  const PUBLIC_FIELDS = [
29
23
  "id",
30
24
  "collection",
@@ -38,10 +32,6 @@ const PUBLIC_FIELDS = [
38
32
  "document",
39
33
  "images"
40
34
  ];
41
- /**
42
- * An entry for a page: its verdict, its revision and its last publication stay on the server, as
43
- * the page sends what it read to the browser in its payload.
44
- */
45
35
  function forPage(entry) {
46
36
  if (typeof entry !== "object" || entry === null) return void 0;
47
37
  return Object.fromEntries(PUBLIC_FIELDS.filter((field) => field in entry).map((field) => [field, Reflect.get(entry, field)]));
@@ -1,10 +1,4 @@
1
1
  //#region src/runtime/server/cache.d.ts
2
- /**
3
- * The cache of `hollware.cache: 'purge'` (S8): a response that read Hollware and answered 200 is
4
- * kept by Cloudflare's Workers Cache, which serves it again without running the Worker, tagged with
5
- * what it showed, until an event of Hollware purges one of its tags (`/_hollware/webhook`). The
6
- * browser keeps nothing: only the edge does (`cloudflare-cdn-cache-control`). A preview is never kept.
7
- */
8
2
  declare const _default: import("nitropack").NitroAppPlugin;
9
3
  //#endregion
10
4
  export { _default as default };
@@ -2,12 +2,6 @@ import { edgeHeaders, tagsOf } from "../tags.mjs";
2
2
  import { previewTokenFromCookie } from "@hollware/client";
3
3
  import { defineNitroPlugin } from "nitropack/runtime";
4
4
  //#region src/runtime/server/cache.ts
5
- /**
6
- * The cache of `hollware.cache: 'purge'` (S8): a response that read Hollware and answered 200 is
7
- * kept by Cloudflare's Workers Cache, which serves it again without running the Worker, tagged with
8
- * what it showed, until an event of Hollware purges one of its tags (`/_hollware/webhook`). The
9
- * browser keeps nothing: only the edge does (`cloudflare-cdn-cache-control`). A preview is never kept.
10
- */
11
5
  var cache_default = defineNitroPlugin((nitroApp) => {
12
6
  nitroApp.hooks.hook("beforeResponse", (event) => {
13
7
  if (previewTokenFromCookie(event.node.req.headers.cookie) !== void 0) return;
@@ -1,11 +1,4 @@
1
1
  //#region src/runtime/server/preview-exchange.d.ts
2
- /**
3
- * The link of the admin's "Preview on the site" (`?hollware-preview=<token>`) is exchanged for a
4
- * cookie, so the token is in a URL once: a `303` to the same URL without the parameter, with the
5
- * token in `hollware_preview` (HttpOnly, SameSite=Lax, an hour, Secure but on http://localhost and
6
- * http://127.0.0.1), `no-store` and `Referrer-Policy: no-referrer`. The token is not checked here:
7
- * Hollware does, when the page reads. A value not shaped like a token sets no cookie.
8
- */
9
2
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void> | undefined>;
10
3
  //#endregion
11
4
  export { _default as default };
@@ -1,14 +1,7 @@
1
1
  import { requestUrl } from "./url.mjs";
2
- import { defineEventHandler, sendRedirect, setResponseHeader } from "h3";
3
2
  import { exchangeHeaders, exchangePreviewLink } from "@hollware/client";
3
+ import { defineEventHandler, sendRedirect, setResponseHeader } from "h3";
4
4
  //#region src/runtime/server/preview-exchange.ts
5
- /**
6
- * The link of the admin's "Preview on the site" (`?hollware-preview=<token>`) is exchanged for a
7
- * cookie, so the token is in a URL once: a `303` to the same URL without the parameter, with the
8
- * token in `hollware_preview` (HttpOnly, SameSite=Lax, an hour, Secure but on http://localhost and
9
- * http://127.0.0.1), `no-store` and `Referrer-Policy: no-referrer`. The token is not checked here:
10
- * Hollware does, when the page reads. A value not shaped like a token sets no cookie.
11
- */
12
5
  var preview_exchange_default = defineEventHandler((event) => {
13
6
  if (event.method !== "GET" && event.method !== "HEAD") return;
14
7
  const url = requestUrl(event);
@@ -1,12 +1,4 @@
1
1
  //#region src/runtime/server/preview.d.ts
2
- /**
3
- * A request that carries a preview token (the `hollware_preview` cookie, see `preview-exchange`)
4
- * reads the latest revision of an entry, and nothing may keep what it answers: the response is
5
- * `no-store` and has no cache tag, so neither the browser nor Workers Cache keeps it, and the
6
- * request gets a header of its own for Nitro's cache (`hollware.cache: <seconds>`) to vary on, so
7
- * it neither reads nor fills the entry that every other request of the path shares. Any request
8
- * without a token has no such header, whatever it sent.
9
- */
10
2
  declare const _default: import("nitropack").NitroAppPlugin;
11
3
  //#endregion
12
4
  export { _default as default };
@@ -1,21 +1,11 @@
1
- import { PREVIEW_HEADER } from "../tags.mjs";
2
- import { removeResponseHeader, setResponseHeader } from "h3";
1
+ import { markPreviewRequest } from "../tags.mjs";
3
2
  import { previewTokenFromCookie } from "@hollware/client";
3
+ import { removeResponseHeader, setResponseHeader } from "h3";
4
4
  import { defineNitroPlugin } from "nitropack/runtime";
5
5
  //#region src/runtime/server/preview.ts
6
- /**
7
- * A request that carries a preview token (the `hollware_preview` cookie, see `preview-exchange`)
8
- * reads the latest revision of an entry, and nothing may keep what it answers: the response is
9
- * `no-store` and has no cache tag, so neither the browser nor Workers Cache keeps it, and the
10
- * request gets a header of its own for Nitro's cache (`hollware.cache: <seconds>`) to vary on, so
11
- * it neither reads nor fills the entry that every other request of the path shares. Any request
12
- * without a token has no such header, whatever it sent.
13
- */
14
6
  var preview_default = defineNitroPlugin((nitroApp) => {
15
7
  nitroApp.hooks.hook("request", (event) => {
16
- const headers = event.node.req.headers;
17
- if (previewTokenFromCookie(headers.cookie) === void 0) delete headers[PREVIEW_HEADER];
18
- else headers[PREVIEW_HEADER] = crypto.randomUUID();
8
+ markPreviewRequest(event.node.req.headers);
19
9
  });
20
10
  nitroApp.hooks.hook("beforeResponse", (event) => {
21
11
  if (previewTokenFromCookie(event.node.req.headers.cookie) === void 0) return;
@@ -1,11 +1,6 @@
1
- import { H3Event } from "h3";
2
1
  import { HollwareReader } from "@hollware/client";
2
+ import { H3Event } from "h3";
3
3
  //#region src/runtime/server/reader.d.ts
4
- /**
5
- * The site's reader of Hollware for a request: the service binding when the Worker has it, else
6
- * HTTP with the URL and the read token of the config. A site with neither gets a 500 that says
7
- * which to set.
8
- */
9
4
  export declare function useHollware(event: H3Event): {
10
5
  site: string;
11
6
  reader: HollwareReader;
@@ -1,16 +1,11 @@
1
1
  import { entryTags, groupTags, listTags, recordTags, siteTags } from "../tags.mjs";
2
- import { createError } from "h3";
3
2
  import { createClient } from "@hollware/client";
3
+ import { createError } from "h3";
4
4
  import { useRuntimeConfig } from "nitropack/runtime";
5
5
  //#region src/runtime/server/reader.ts
6
6
  function isReader(value) {
7
7
  return typeof value === "object" && value !== null && "getEntry" in value;
8
8
  }
9
- /**
10
- * The site's reader of Hollware for a request: the service binding when the Worker has it, else
11
- * HTTP with the URL and the read token of the config. A site with neither gets a 500 that says
12
- * which to set.
13
- */
14
9
  function useHollware(event) {
15
10
  const config = useRuntimeConfig(event)["hollware"];
16
11
  const env = event.context["cloudflare"]?.env;
@@ -31,10 +26,6 @@ function useHollware(event) {
31
26
  statusMessage: `Hollware: the Worker has no binding ${config.binding}, and hollware.url with a read token (NUXT_HOLLWARE_TOKEN) is not set.`
32
27
  });
33
28
  }
34
- /**
35
- * The reader, recording on the request the cache tags of what each read answered (S8): a route of
36
- * the site's own that reads through `useHollware` is tagged with no work of its own.
37
- */
38
29
  function tagging(event, reader) {
39
30
  return {
40
31
  ...reader,
@@ -1,8 +1,8 @@
1
1
  import { answer, forPage } from "../answer.mjs";
2
2
  import { requestUrl } from "../url.mjs";
3
3
  import { useHollware } from "../reader.mjs";
4
- import { appendResponseHeader, createError, defineEventHandler, getHeader, getRouterParam } from "h3";
5
4
  import { clearedPreviewCookie, isPreviewRefusal, isSecureRequest, previewTokenFromCookie } from "@hollware/client";
5
+ import { appendResponseHeader, createError, defineEventHandler, getHeader, getRouterParam } from "h3";
6
6
  //#region src/runtime/server/routes/entry.ts
7
7
  var entry_default = defineEventHandler(async (event) => {
8
8
  const { site, reader } = useHollware(event);
@@ -1,8 +1,4 @@
1
1
  import { H3Event } from "h3";
2
2
  //#region src/runtime/server/url.d.ts
3
- /**
4
- * The URL the visitor asked for. On Workers it is the one of the Request itself, whose scheme and
5
- * host are the real ones; elsewhere h3 builds it from the `Host` header.
6
- */
7
3
  export declare function requestUrl(event: H3Event): URL;
8
4
  //#endregion
@@ -1,9 +1,5 @@
1
1
  import { getRequestURL } from "h3";
2
2
  //#region src/runtime/server/url.ts
3
- /**
4
- * The URL the visitor asked for. On Workers it is the one of the Request itself, whose scheme and
5
- * host are the real ones; elsewhere h3 builds it from the `Host` header.
6
- */
7
3
  function requestUrl(event) {
8
4
  const request = event.context["cloudflare"]?.request;
9
5
  const url = typeof request === "object" && request !== null ? Reflect.get(request, "url") : void 0;
@@ -1,5 +1,4 @@
1
1
  //#region src/runtime/tags.d.ts
2
- /** What a request holds of its own, whether Nuxt's or h3's: its context. */
3
2
  interface Tagged {
4
3
  readonly context: Record<string, unknown>;
5
4
  }
@@ -8,26 +7,13 @@ export declare function tagsOf(event: Tagged): string[];
8
7
  interface Entryish {
9
8
  readonly id?: unknown;
10
9
  }
11
- /** The tags of an entry read alone. */
12
10
  export declare function entryTags(entry: Entryish | undefined): string[];
13
- /** The tags of a list: the list itself, in its locale or every one, and each entry it shows. */
14
11
  export declare function listTags(collection: string, locale: string | undefined, entries: readonly Entryish[]): string[];
15
- /** The tags of the translations of a group. */
16
12
  export declare function groupTags(collection: string, group: string, entries: readonly Entryish[]): string[];
17
13
  export declare function siteTags(): string[];
18
- /** How long the edge keeps a page no event purges: a year, the most it keeps anything. */
19
14
  export declare const EDGE_SECONDS = 31536000;
20
- /**
21
- * The headers that let the edge keep a response, tagged with what it showed: only a GET that
22
- * answered 200 and read Hollware. An error, a redirect or a write is never kept, nor a response
23
- * that read nothing to purge it by. The browser keeps nothing; only the edge does.
24
- */
25
15
  export declare function edgeHeaders(tags: readonly string[], status: number, method: string): Readonly<Record<string, string>> | null;
26
- /**
27
- * A request header that only the preview plugin sets, and that Nitro's cache (`cache: <seconds>`)
28
- * varies on: a preview gets a fresh value each time, so it never reads or fills the entry that
29
- * every other request of the same path shares.
30
- */
31
16
  export declare const PREVIEW_HEADER = "x-hollware-preview";
17
+ export declare function markPreviewRequest(headers: Record<string, string | string[] | undefined>): void;
32
18
  //#endregion
33
19
  export {};
@@ -1,11 +1,6 @@
1
+ import { previewTokenFromCookie } from "@hollware/client";
1
2
  import { EVERY_LOCALE, SITE_TAG, entryTag, groupTag, listTag } from "@hollware/core";
2
3
  //#region src/runtime/tags.ts
3
- /**
4
- * The cache tags of a response (S8): what it showed of Hollware, in the names of the contract of
5
- * `@hollware/core`, gathered on its request as each read answers, and written as `Cache-Tag` once
6
- * it is rendered. A page gathers the tags of every read it made; a route of `/_hollware/` those of
7
- * its own.
8
- */
9
4
  const KEY = "hollwareTags";
10
5
  function recordTags(event, tags) {
11
6
  if (event === void 0 || tags.length === 0) return;
@@ -21,28 +16,19 @@ function tagsOf(event) {
21
16
  function idsOf(entries) {
22
17
  return entries.flatMap((entry) => typeof entry.id === "string" ? [entryTag(entry.id)] : []);
23
18
  }
24
- /** The tags of an entry read alone. */
25
19
  function entryTags(entry) {
26
20
  return entry === void 0 ? [] : idsOf([entry]);
27
21
  }
28
- /** The tags of a list: the list itself, in its locale or every one, and each entry it shows. */
29
22
  function listTags(collection, locale, entries) {
30
23
  return [listTag(collection, locale ?? EVERY_LOCALE), ...idsOf(entries)];
31
24
  }
32
- /** The tags of the translations of a group. */
33
25
  function groupTags(collection, group, entries) {
34
26
  return [groupTag(collection, group), ...idsOf(entries)];
35
27
  }
36
28
  function siteTags() {
37
29
  return [SITE_TAG];
38
30
  }
39
- /** How long the edge keeps a page no event purges: a year, the most it keeps anything. */
40
31
  const EDGE_SECONDS = 31536e3;
41
- /**
42
- * The headers that let the edge keep a response, tagged with what it showed: only a GET that
43
- * answered 200 and read Hollware. An error, a redirect or a write is never kept, nor a response
44
- * that read nothing to purge it by. The browser keeps nothing; only the edge does.
45
- */
46
32
  function edgeHeaders(tags, status, method) {
47
33
  if (tags.length === 0 || status !== 200 || method !== "GET") return null;
48
34
  return {
@@ -51,11 +37,11 @@ function edgeHeaders(tags, status, method) {
51
37
  "cloudflare-cdn-cache-control": `max-age=${EDGE_SECONDS}`
52
38
  };
53
39
  }
54
- /**
55
- * A request header that only the preview plugin sets, and that Nitro's cache (`cache: <seconds>`)
56
- * varies on: a preview gets a fresh value each time, so it never reads or fills the entry that
57
- * every other request of the same path shares.
58
- */
59
40
  const PREVIEW_HEADER = "x-hollware-preview";
41
+ function markPreviewRequest(headers) {
42
+ const cookie = headers["cookie"];
43
+ if (previewTokenFromCookie(typeof cookie === "string" ? cookie : void 0) === void 0) delete headers[PREVIEW_HEADER];
44
+ else headers[PREVIEW_HEADER] = crypto.randomUUID();
45
+ }
60
46
  //#endregion
61
- export { EDGE_SECONDS, PREVIEW_HEADER, edgeHeaders, entryTags, groupTags, listTags, recordTags, siteTags, tagsOf };
47
+ export { EDGE_SECONDS, PREVIEW_HEADER, edgeHeaders, entryTags, groupTags, listTags, markPreviewRequest, recordTags, siteTags, tagsOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hollware/nuxt",
3
- "version": "1.0.0-rc.7",
3
+ "version": "1.0.0-rc.9",
4
4
  "description": "Read Hollware from a Nuxt site, over a service binding or HTTP.",
5
5
  "homepage": "https://hollware.com",
6
6
  "bugs": {
@@ -28,9 +28,9 @@
28
28
  "provenance": true
29
29
  },
30
30
  "dependencies": {
31
- "@comark/vue": "0.7.0",
32
- "@hollware/client": "1.0.0-rc.7",
33
- "@hollware/core": "1.0.0-rc.7",
31
+ "@comark/vue": "0.8.1",
32
+ "@hollware/client": "1.0.0-rc.9",
33
+ "@hollware/core": "1.0.0-rc.9",
34
34
  "@nuxt/kit": "4.6.2"
35
35
  },
36
36
  "devDependencies": {