@backmatter/next 0.0.54 → 0.0.57
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/config.cjs +3 -3
- package/dist/loader.cjs +3 -3
- package/package.json +3 -3
- package/src/cached-doc.ts +19 -6
- package/src/revalidate.ts +3 -1
- package/src/routes.ts +8 -1
package/dist/config.cjs
CHANGED
|
@@ -466,14 +466,14 @@ function renderCachedCmsClient(typeArgs) {
|
|
|
466
466
|
"",
|
|
467
467
|
"async function cachedGetDoc(type: string, slug: string) {",
|
|
468
468
|
' "use cache";',
|
|
469
|
-
|
|
469
|
+
" cacheLife(cacheLifeProfile(config));",
|
|
470
470
|
" cacheTag(...contentCacheTags(type, slug));",
|
|
471
471
|
" return raw.getDoc(type, slug);",
|
|
472
472
|
"}",
|
|
473
473
|
"",
|
|
474
474
|
"async function cachedListDocs(filter?: { type?: string }) {",
|
|
475
475
|
' "use cache";',
|
|
476
|
-
|
|
476
|
+
" cacheLife(cacheLifeProfile(config));",
|
|
477
477
|
" cacheTag(...listCacheTags(filter?.type));",
|
|
478
478
|
" return raw.listDocs(filter);",
|
|
479
479
|
"}",
|
|
@@ -505,7 +505,7 @@ function renderModelsBarrel(input) {
|
|
|
505
505
|
const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
|
|
506
506
|
const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
|
|
507
507
|
if (nextHost) {
|
|
508
|
-
lines.push('import { contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
|
|
508
|
+
lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
|
|
509
509
|
lines.push('import { currentPreviewContent } from "@backmatter/next/preview-content";');
|
|
510
510
|
lines.push('import { cacheLife, cacheTag } from "next/cache";');
|
|
511
511
|
}
|
package/dist/loader.cjs
CHANGED
|
@@ -459,14 +459,14 @@ function renderCachedCmsClient(typeArgs) {
|
|
|
459
459
|
"",
|
|
460
460
|
"async function cachedGetDoc(type: string, slug: string) {",
|
|
461
461
|
' "use cache";',
|
|
462
|
-
|
|
462
|
+
" cacheLife(cacheLifeProfile(config));",
|
|
463
463
|
" cacheTag(...contentCacheTags(type, slug));",
|
|
464
464
|
" return raw.getDoc(type, slug);",
|
|
465
465
|
"}",
|
|
466
466
|
"",
|
|
467
467
|
"async function cachedListDocs(filter?: { type?: string }) {",
|
|
468
468
|
' "use cache";',
|
|
469
|
-
|
|
469
|
+
" cacheLife(cacheLifeProfile(config));",
|
|
470
470
|
" cacheTag(...listCacheTags(filter?.type));",
|
|
471
471
|
" return raw.listDocs(filter);",
|
|
472
472
|
"}",
|
|
@@ -498,7 +498,7 @@ function renderModelsBarrel(input) {
|
|
|
498
498
|
const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
|
|
499
499
|
const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
|
|
500
500
|
if (nextHost) {
|
|
501
|
-
lines.push('import { contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
|
|
501
|
+
lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
|
|
502
502
|
lines.push('import { currentPreviewContent } from "@backmatter/next/preview-content";');
|
|
503
503
|
lines.push('import { cacheLife, cacheTag } from "next/cache";');
|
|
504
504
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backmatter/next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"description": "Experimental Next.js adapter for Backmatter. APIs will break. Not ready for production.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"test": "bun test"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@backmatter/core": "^0.0.
|
|
50
|
+
"@backmatter/core": "^0.0.44",
|
|
51
51
|
"@mdx-js/mdx": "^3.1.1",
|
|
52
52
|
"remark-gfm": "^4.0.1",
|
|
53
|
-
"@backmatter/studio": "^0.0.
|
|
53
|
+
"@backmatter/studio": "^0.0.34"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"next": ">=16.3.0",
|
package/src/cached-doc.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
// packages/next/src/cached-doc.ts
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
contentCacheTags,
|
|
5
|
+
DEFAULT_CACHE_LIFE,
|
|
6
|
+
listCacheTags,
|
|
7
|
+
type BackmatterDoc,
|
|
8
|
+
type BackmatterDocSummary,
|
|
9
|
+
type CacheLifeProfile,
|
|
10
|
+
} from "@backmatter/core";
|
|
4
11
|
|
|
5
12
|
export type CacheFns = {
|
|
6
|
-
cacheLife: (profile:
|
|
13
|
+
cacheLife: (profile: CacheLifeProfile) => void;
|
|
7
14
|
cacheTag: (...tags: string[]) => void;
|
|
8
15
|
};
|
|
9
16
|
|
|
@@ -16,6 +23,12 @@ export type PublishedRender = (type: string, slug: string) => Promise<ReactNode>
|
|
|
16
23
|
let registeredGetDoc: GetDocFn | null = null;
|
|
17
24
|
let registeredListDocs: ListDocsFn | null = null;
|
|
18
25
|
let registeredPublishedRender: PublishedRender | null = null;
|
|
26
|
+
let registeredCacheLife: CacheLifeProfile = DEFAULT_CACHE_LIFE;
|
|
27
|
+
|
|
28
|
+
/** `createCatchAll` registers the host's `cacheLife` from backmatter.config. */
|
|
29
|
+
export function registerCacheLife(profile: CacheLifeProfile): void {
|
|
30
|
+
registeredCacheLife = profile;
|
|
31
|
+
}
|
|
19
32
|
|
|
20
33
|
/** Called from `createBackmatter` so `"use cache"` only closes over serializable args. */
|
|
21
34
|
export function registerCachedDocGet(getDoc: GetDocFn): void {
|
|
@@ -56,7 +69,7 @@ export async function getCachedDoc(
|
|
|
56
69
|
): Promise<BackmatterDoc | null> {
|
|
57
70
|
"use cache";
|
|
58
71
|
const fns = cache ?? (await loadCacheFns());
|
|
59
|
-
fns.cacheLife(
|
|
72
|
+
fns.cacheLife(registeredCacheLife);
|
|
60
73
|
fns.cacheTag(...contentCacheTags(type, slug));
|
|
61
74
|
const getDoc = registeredGetDoc;
|
|
62
75
|
if (!getDoc) {
|
|
@@ -71,7 +84,7 @@ export async function getCachedDocs(
|
|
|
71
84
|
): Promise<BackmatterDocSummary[]> {
|
|
72
85
|
"use cache";
|
|
73
86
|
const fns = cache ?? (await loadCacheFns());
|
|
74
|
-
fns.cacheLife(
|
|
87
|
+
fns.cacheLife(registeredCacheLife);
|
|
75
88
|
fns.cacheTag(...listCacheTags(type));
|
|
76
89
|
const listDocs = registeredListDocs;
|
|
77
90
|
if (!listDocs) {
|
|
@@ -91,7 +104,7 @@ export async function getCachedPublished(
|
|
|
91
104
|
): Promise<ReactNode> {
|
|
92
105
|
"use cache";
|
|
93
106
|
const fns = cache ?? (await loadCacheFns());
|
|
94
|
-
fns.cacheLife(
|
|
107
|
+
fns.cacheLife(registeredCacheLife);
|
|
95
108
|
fns.cacheTag(...contentCacheTags(type, slug));
|
|
96
109
|
const render = registeredPublishedRender;
|
|
97
110
|
if (!render) {
|
|
@@ -107,6 +120,6 @@ export async function cachedRouteParams<T extends object>(
|
|
|
107
120
|
): Promise<T> {
|
|
108
121
|
"use cache";
|
|
109
122
|
const fns = cache ?? (await loadCacheFns());
|
|
110
|
-
fns.cacheLife(
|
|
123
|
+
fns.cacheLife(registeredCacheLife);
|
|
111
124
|
return await params;
|
|
112
125
|
}
|
package/src/revalidate.ts
CHANGED
|
@@ -57,7 +57,9 @@ export function createRevalidateRoute(
|
|
|
57
57
|
const { revalidatePath, revalidateTag } = cache ?? (await loadNextCache());
|
|
58
58
|
const paths = pathsForCommittedDocs(cms.models, body.docs ?? []);
|
|
59
59
|
for (const path of paths) revalidatePath(path);
|
|
60
|
-
|
|
60
|
+
const tags = revalidateTagsForCommit(body);
|
|
61
|
+
for (const tag of tags.expire) revalidateTag(tag, { expire: 0 });
|
|
62
|
+
for (const tag of tags.refresh) revalidateTag(tag, "max");
|
|
61
63
|
if (body.full) revalidatePath("/", "layout");
|
|
62
64
|
return Response.json({ ok: true, paths });
|
|
63
65
|
};
|
package/src/routes.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Fragment, Suspense, createElement, type ReactNode } from "react";
|
|
|
7
7
|
import { HeldPreview, HoldPreview } from "./preview-hold";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_TEMPLATE_SLUG,
|
|
10
|
+
cacheLifeProfile,
|
|
10
11
|
isBlockGallerySegments,
|
|
11
12
|
isRoutable,
|
|
12
13
|
isTemplateSlug,
|
|
@@ -24,7 +25,12 @@ import {
|
|
|
24
25
|
import type { BackmatterClient } from "@backmatter/core/node/create-backmatter";
|
|
25
26
|
import { fetchPreviewDoc } from "@backmatter/core/preview";
|
|
26
27
|
import type { MdxComponents } from "./mdx-compile";
|
|
27
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
cachedRouteParams,
|
|
30
|
+
getCachedPublished,
|
|
31
|
+
registerCacheLife,
|
|
32
|
+
registerPublishedRender,
|
|
33
|
+
} from "./cached-doc";
|
|
28
34
|
import type { BlockComponents, BlockFallbacks } from "./page-render";
|
|
29
35
|
import { renderLayoutDoc, type DocLayout } from "./layout-doc";
|
|
30
36
|
import { previewContentForCheckout, runWithPreviewContent } from "./preview-content";
|
|
@@ -195,6 +201,7 @@ export function createCatchAll<Models extends readonly ModelDef[]>(
|
|
|
195
201
|
): CatchAllRoute {
|
|
196
202
|
const models = cms.models as readonly ModelDef[];
|
|
197
203
|
const byType = new Map(models.map((m) => [m.type, m]));
|
|
204
|
+
registerCacheLife(cacheLifeProfile(cms.config));
|
|
198
205
|
|
|
199
206
|
const resolve: CatchAllRoute["resolve"] = (segments) => {
|
|
200
207
|
const pathname = `/${(segments ?? []).join("/")}`;
|