@backmatter/next 0.0.39 → 0.0.40

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 CHANGED
@@ -190,7 +190,7 @@ function detectSdk(root) {
190
190
  } catch {}
191
191
  return "@backmatter/core/node";
192
192
  }
193
- function renderCachedCmsClient() {
193
+ function renderCachedCmsClient(typeArgs) {
194
194
  return [
195
195
  "const raw = createBackmatter({ ...config, models, sync: false });",
196
196
  "",
@@ -225,12 +225,14 @@ function renderCachedCmsClient() {
225
225
  " ...raw,",
226
226
  " getDoc,",
227
227
  " listDocs,",
228
- ` query: createQuery(models, { getDoc, listDocs }),`,
228
+ ` query: createQuery${typeArgs}(models, { getDoc, listDocs }),`,
229
229
  "};"
230
230
  ];
231
231
  }
232
232
  function renderModelsBarrel(input) {
233
233
  const nextHost = input.sdk === "@backmatter/next";
234
+ const blocks = input.blocks ?? [];
235
+ const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
234
236
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
235
237
  if (nextHost) {
236
238
  lines.push('import { contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
@@ -245,15 +247,21 @@ function renderModelsBarrel(input) {
245
247
  for (const m of input.models) {
246
248
  lines.push(`import ${m.importName} from "${importSpecifier(input.outDir, m.file)}";`);
247
249
  }
250
+ for (const block of blocks) {
251
+ lines.push(`import type ${block.name} from "${importSpecifier(input.outDir, block.file)}";`);
252
+ }
248
253
  lines.push("");
249
254
  lines.push(`export const models = [${input.models.map((m) => m.importName).join(", ")}] as const;`);
250
255
  lines.push("export type Models = typeof models;");
256
+ if (blocks.length > 0) {
257
+ lines.push(`type Blocks = readonly [${blocks.map((block) => `typeof ${block.name}`).join(", ")}];`);
258
+ }
251
259
  lines.push("");
252
260
  if (nextHost) {
253
- lines.push(...renderCachedCmsClient());
261
+ lines.push(...renderCachedCmsClient(typeArgs));
254
262
  } else {
255
263
  lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
256
- lines.push("export const cms = createBackmatter({ ...config, models });");
264
+ lines.push(`export const cms = createBackmatter${typeArgs}({ ...config, models });`);
257
265
  }
258
266
  return `${lines.join(`
259
267
  `)}
@@ -425,7 +433,7 @@ function generate(options) {
425
433
  const configFile = findConfigFile(root);
426
434
  const write = options.write ?? true;
427
435
  const rendered = {
428
- "index.ts": renderModelsBarrel({ outDir, models, configFile, sdk }),
436
+ "index.ts": renderModelsBarrel({ outDir, models, blocks, configFile, sdk }),
429
437
  "blocks.ts": renderBlocksBarrel({ outDir, blocks }),
430
438
  "block-fallbacks.ts": renderBlockFallbacksBarrel({ outDir, fallbacks }),
431
439
  "mdx.ts": renderMdxBarrel({ outDir, mdx }),
package/dist/loader.cjs CHANGED
@@ -183,7 +183,7 @@ function detectSdk(root) {
183
183
  } catch {}
184
184
  return "@backmatter/core/node";
185
185
  }
186
- function renderCachedCmsClient() {
186
+ function renderCachedCmsClient(typeArgs) {
187
187
  return [
188
188
  "const raw = createBackmatter({ ...config, models, sync: false });",
189
189
  "",
@@ -218,12 +218,14 @@ function renderCachedCmsClient() {
218
218
  " ...raw,",
219
219
  " getDoc,",
220
220
  " listDocs,",
221
- ` query: createQuery(models, { getDoc, listDocs }),`,
221
+ ` query: createQuery${typeArgs}(models, { getDoc, listDocs }),`,
222
222
  "};"
223
223
  ];
224
224
  }
225
225
  function renderModelsBarrel(input) {
226
226
  const nextHost = input.sdk === "@backmatter/next";
227
+ const blocks = input.blocks ?? [];
228
+ const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
227
229
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
228
230
  if (nextHost) {
229
231
  lines.push('import { contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
@@ -238,15 +240,21 @@ function renderModelsBarrel(input) {
238
240
  for (const m of input.models) {
239
241
  lines.push(`import ${m.importName} from "${importSpecifier(input.outDir, m.file)}";`);
240
242
  }
243
+ for (const block of blocks) {
244
+ lines.push(`import type ${block.name} from "${importSpecifier(input.outDir, block.file)}";`);
245
+ }
241
246
  lines.push("");
242
247
  lines.push(`export const models = [${input.models.map((m) => m.importName).join(", ")}] as const;`);
243
248
  lines.push("export type Models = typeof models;");
249
+ if (blocks.length > 0) {
250
+ lines.push(`type Blocks = readonly [${blocks.map((block) => `typeof ${block.name}`).join(", ")}];`);
251
+ }
244
252
  lines.push("");
245
253
  if (nextHost) {
246
- lines.push(...renderCachedCmsClient());
254
+ lines.push(...renderCachedCmsClient(typeArgs));
247
255
  } else {
248
256
  lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
249
- lines.push("export const cms = createBackmatter({ ...config, models });");
257
+ lines.push(`export const cms = createBackmatter${typeArgs}({ ...config, models });`);
250
258
  }
251
259
  return `${lines.join(`
252
260
  `)}
@@ -418,7 +426,7 @@ function generate(options) {
418
426
  const configFile = findConfigFile(root);
419
427
  const write = options.write ?? true;
420
428
  const rendered = {
421
- "index.ts": renderModelsBarrel({ outDir, models, configFile, sdk }),
429
+ "index.ts": renderModelsBarrel({ outDir, models, blocks, configFile, sdk }),
422
430
  "blocks.ts": renderBlocksBarrel({ outDir, blocks }),
423
431
  "block-fallbacks.ts": renderBlockFallbacksBarrel({ outDir, fallbacks }),
424
432
  "mdx.ts": renderMdxBarrel({ outDir, mdx }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backmatter/next",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
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.33",
50
+ "@backmatter/core": "^0.0.34",
51
51
  "@mdx-js/mdx": "^3.1.1",
52
52
  "remark-gfm": "^4.0.1",
53
- "@backmatter/studio": "^0.0.16"
53
+ "@backmatter/studio": "^0.0.17"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "next": ">=16.3.0",