@backmatter/core 0.0.47 → 0.0.49

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backmatter/core",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "description": "Experimental Backmatter SDK. APIs will break. Not ready for production.",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/src/block.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  // packages/core/src/block.ts
2
2
  import {
3
3
  type FieldDef,
4
- type FieldKind,
5
4
  type FieldSnapshot,
6
5
  parseFieldSnapshot,
7
6
  serializeField,
package/src/fields.ts CHANGED
@@ -99,8 +99,6 @@ type Opts<R extends boolean> = {
99
99
  description?: string;
100
100
  };
101
101
 
102
- type TextOpts<R extends boolean> = Opts<R> & { options?: string[] };
103
-
104
102
  type NumberOpts<R extends boolean> = Opts<R> & {
105
103
  min?: number;
106
104
  max?: number;
package/src/model.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  // packages/core/src/model.ts
2
2
  import {
3
3
  type FieldDef,
4
- type FieldKind,
5
4
  type FieldSnapshot,
6
5
  parseFieldSnapshot,
7
6
  serializeField,
package/src/node/cli.ts CHANGED
@@ -277,7 +277,7 @@ export default defineConfig({
277
277
  function renderCatchAllPage(): string {
278
278
  return `// ${CATCH_ALL_DIR}/page.tsx — mounts every model at its route, including / via indexSlug.
279
279
  import { cacheLife } from "next/cache";
280
- import { cacheLifeProfile } from "@backmatter/core";
280
+ import { cacheLifeProfile, type CacheLifeProfile } from "@backmatter/core";
281
281
  import { createCatchAll } from "@backmatter/next/routes";
282
282
  import { cms } from "${REGISTRY_SPECIFIER}";
283
283
  import { components as mdxComponents } from "${REGISTRY_SPECIFIER}/mdx";
@@ -292,11 +292,14 @@ const route = createCatchAll(cms, { components, blocks: blockLoaders, fallbacks:
292
292
 
293
293
  export const generateStaticParams = route.generateStaticParams;
294
294
 
295
+ // Next types cacheLife against this host's profile names; the config may name any of them.
296
+ const contentCacheLife = cacheLife as (profile: CacheLifeProfile) => void;
297
+
295
298
  async function cachedParams<T extends { backmatter?: string[] }>(
296
299
  params: Promise<T> | T,
297
300
  ): Promise<T> {
298
301
  "use cache";
299
- cacheLife(cacheLifeProfile(cms.config));
302
+ contentCacheLife(cacheLifeProfile(cms.config));
300
303
  return params;
301
304
  }
302
305
 
@@ -630,5 +633,5 @@ export async function main(argv: string[]): Promise<number> {
630
633
  }
631
634
 
632
635
  if (import.meta.main) {
633
- main(process.argv.slice(2)).then((code) => process.exit(code));
636
+ void main(process.argv.slice(2)).then((code) => process.exit(code));
634
637
  }
@@ -105,16 +105,19 @@ function renderCachedCmsClient(typeArgs: string): string[] {
105
105
  return [
106
106
  "const raw = createBackmatter({ ...config, models, sync: false });",
107
107
  "",
108
+ "// Next types cacheLife against this host's profile names; the config may name any of them.",
109
+ "const contentCacheLife = cacheLife as (profile: CacheLifeProfile) => void;",
110
+ "",
108
111
  "async function cachedGetDoc(type: string, slug: string) {",
109
112
  ' "use cache";',
110
- " cacheLife(cacheLifeProfile(config));",
113
+ " contentCacheLife(cacheLifeProfile(config));",
111
114
  " cacheTag(...contentCacheTags(type, slug));",
112
115
  " return raw.getDoc(type, slug);",
113
116
  "}",
114
117
  "",
115
118
  "async function cachedListDocs(filter?: { type?: string }) {",
116
119
  ' "use cache";',
117
- " cacheLife(cacheLifeProfile(config));",
120
+ " contentCacheLife(cacheLifeProfile(config));",
118
121
  " cacheTag(...listCacheTags(filter?.type));",
119
122
  " return raw.listDocs(filter);",
120
123
  "}",
@@ -153,7 +156,7 @@ export function renderModelsBarrel(input: {
153
156
  const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
154
157
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
155
158
  if (nextHost) {
156
- lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
159
+ lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags, type CacheLifeProfile } from "@backmatter/core";');
157
160
  lines.push('import { currentPreviewContent } from "@backmatter/next/preview-content";');
158
161
  lines.push('import { cacheLife, cacheTag } from "next/cache";');
159
162
  }
package/src/query.ts CHANGED
@@ -438,7 +438,7 @@ async function selected(
438
438
  export function createQuery<
439
439
  const Models extends readonly ModelDef[],
440
440
  const Blocks extends readonly BlockDef[] = [],
441
- >(models: Models, loader: DocLoader, blocks?: Blocks): Query<Models, Blocks> {
441
+ >(models: Models, loader: DocLoader, _blocks?: Blocks): Query<Models, Blocks> {
442
442
  const byType = new Map<string, ModelDef>(models.map((m) => [m.type, m]));
443
443
 
444
444
  function slugForGet(type: string, arg?: string): string {
package/src/validate.ts CHANGED
@@ -63,7 +63,7 @@ function isMissingValue(value: unknown, field: FieldSnapshot | undefined): boole
63
63
  }
64
64
 
65
65
  function issueMessage(
66
- issue: z.core.$ZodIssue | z.ZodIssue,
66
+ issue: z.core.$ZodIssue,
67
67
  model: Pick<ModelSnapshot, "fields">,
68
68
  data: Frontmatter,
69
69
  objects: ObjectSnapshot[],
@@ -17,6 +17,9 @@ function fixFor(field: string, rest: string): string | undefined {
17
17
  if (rest.includes("media URL")) return "Use a URL from the media library.";
18
18
  const relation = rest.match(/^must name a (\S+) document$/);
19
19
  if (relation) return `Pick an existing ${relation[1]} document.`;
20
+ if (rest === "must be a document route" || rest.startsWith("must be a route of ")) {
21
+ return "Link to a page that exists, or create that page first.";
22
+ }
20
23
  return undefined;
21
24
  }
22
25