@backmatter/core 0.0.12 → 0.0.14
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 +1 -1
- package/src/block.ts +2 -3
- package/src/fields.ts +0 -3
- package/src/model.ts +2 -3
- package/src/node/create-backmatter.ts +7 -2
- package/src/node/generate.ts +2 -2
- package/src/query.ts +1 -1
- package/src/zod.ts +0 -3
package/package.json
CHANGED
package/src/block.ts
CHANGED
|
@@ -94,9 +94,8 @@ export function parseBlockSnapshot(input: unknown): BlockSnapshot {
|
|
|
94
94
|
for (const [name, fieldRaw] of Object.entries(value.fields as Record<string, unknown>)) {
|
|
95
95
|
try {
|
|
96
96
|
fields[name] = parseFieldSnapshot(fieldRaw);
|
|
97
|
-
} catch
|
|
98
|
-
|
|
99
|
-
throw new Error(`block.fields.${name}: ${msg}`);
|
|
97
|
+
} catch {
|
|
98
|
+
// Drop unknown kinds so a stored snapshot still loads.
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
return { name: value.name, fields };
|
package/src/fields.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
export type FieldKind =
|
|
4
4
|
| "text"
|
|
5
|
-
| "slug"
|
|
6
5
|
| "locale"
|
|
7
6
|
| "image"
|
|
8
7
|
| "relation"
|
|
@@ -46,7 +45,6 @@ function base<K extends FieldKind, R extends boolean, To extends string>(
|
|
|
46
45
|
|
|
47
46
|
export const field = {
|
|
48
47
|
text: <const R extends boolean = false>(opts?: Opts<R>) => base("text", opts),
|
|
49
|
-
slug: <const R extends boolean = false>(opts?: Opts<R>) => base("slug", opts),
|
|
50
48
|
locale: <const R extends boolean = false>(opts?: Opts<R>) => base("locale", opts),
|
|
51
49
|
image: <const R extends boolean = false>(opts?: Opts<R>) => base("image", opts),
|
|
52
50
|
number: <const R extends boolean = false>(opts?: Opts<R>) => base("number", opts),
|
|
@@ -72,7 +70,6 @@ export function parseFieldSnapshot(input: unknown): FieldSnapshot {
|
|
|
72
70
|
const kind = value.kind;
|
|
73
71
|
const allowed: FieldKind[] = [
|
|
74
72
|
"text",
|
|
75
|
-
"slug",
|
|
76
73
|
"locale",
|
|
77
74
|
"image",
|
|
78
75
|
"relation",
|
package/src/model.ts
CHANGED
|
@@ -194,9 +194,8 @@ export function parseSchemaSnapshot(input: unknown): SchemaSnapshot {
|
|
|
194
194
|
)) {
|
|
195
195
|
try {
|
|
196
196
|
fields[name] = parseFieldSnapshot(fieldRaw);
|
|
197
|
-
} catch
|
|
198
|
-
|
|
199
|
-
throw new Error(`schema.models[${i}].fields.${name}: ${msg}`);
|
|
197
|
+
} catch {
|
|
198
|
+
// Drop unknown kinds (e.g. leftover slug) so a stored snapshot still loads.
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
const snapshot: ModelSnapshot = { type: m.type, path: m.path, fields };
|
|
@@ -22,6 +22,11 @@ export type CreateBackmatterOptions<Models extends readonly ModelDef[] = readonl
|
|
|
22
22
|
* `@backmatter/next` turns this on.
|
|
23
23
|
*/
|
|
24
24
|
taggedApiFetch?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* When false, skip the boot-time schema PUT. Query clients (catch-all,
|
|
27
|
+
* revalidate) set this; `.backmatter/sync` leaves the default.
|
|
28
|
+
*/
|
|
29
|
+
sync?: boolean;
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
export type BackmatterClient<Models extends readonly ModelDef[] = readonly ModelDef[]> = {
|
|
@@ -59,7 +64,7 @@ function toSnapshots(models: readonly ModelDef[]): ModelSnapshot[] {
|
|
|
59
64
|
export function createBackmatter<const Models extends readonly ModelDef[]>(
|
|
60
65
|
options: CreateBackmatterOptions<Models>,
|
|
61
66
|
): BackmatterClient<Models> {
|
|
62
|
-
const { models: modelDefs, blocks: blockDefs, taggedApiFetch, ...rest } = options;
|
|
67
|
+
const { models: modelDefs, blocks: blockDefs, taggedApiFetch, sync = true, ...rest } = options;
|
|
63
68
|
const config = resolveConfig(rest);
|
|
64
69
|
const models = toSnapshots(modelDefs);
|
|
65
70
|
const siteRoot = config.siteRoot ?? process.cwd();
|
|
@@ -73,7 +78,7 @@ export function createBackmatter<const Models extends readonly ModelDef[]>(
|
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
// backmatter CLI imports the config to read models; never sync from there.
|
|
76
|
-
if (apiUrl && hostToken && workspaceId) {
|
|
81
|
+
if (sync && apiUrl && hostToken && workspaceId) {
|
|
77
82
|
if (process.env.BACKMATTER_CLI === "1") {
|
|
78
83
|
console.warn("backmatter: schema sync skipped (BACKMATTER_CLI=1)");
|
|
79
84
|
} else {
|
package/src/node/generate.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function detectSdk(root: string): string {
|
|
|
95
95
|
|
|
96
96
|
function renderCachedCmsClient(): string[] {
|
|
97
97
|
return [
|
|
98
|
-
"const raw = createBackmatter({ ...config, models });",
|
|
98
|
+
"const raw = createBackmatter({ ...config, models, sync: false });",
|
|
99
99
|
"",
|
|
100
100
|
"async function getDoc(locale: string, type: string, slug: string) {",
|
|
101
101
|
' "use cache";',
|
|
@@ -180,7 +180,7 @@ export function renderSyncBarrel(input: {
|
|
|
180
180
|
lines.push(`export const blocks = [${input.blocks.map((b) => b.name).join(", ")}] as const;`);
|
|
181
181
|
lines.push("");
|
|
182
182
|
lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
|
|
183
|
-
lines.push("export const cms = createBackmatter({ ...config, models, blocks });");
|
|
183
|
+
lines.push("export const cms = createBackmatter({ ...config, models, blocks, sync: true });");
|
|
184
184
|
return `${lines.join("\n")}\n`;
|
|
185
185
|
}
|
|
186
186
|
|
package/src/query.ts
CHANGED
|
@@ -19,7 +19,7 @@ type KeysOfKind<M extends ModelDef, K extends FieldKind> = {
|
|
|
19
19
|
[N in keyof M["fields"]]: M["fields"][N]["kind"] extends K ? N : never;
|
|
20
20
|
}[keyof M["fields"]];
|
|
21
21
|
|
|
22
|
-
type ScalarKind = "text" | "
|
|
22
|
+
type ScalarKind = "text" | "locale" | "number" | "boolean";
|
|
23
23
|
|
|
24
24
|
/** Equality filters on slug and scalar frontmatter fields. */
|
|
25
25
|
export type Where<M extends ModelDef> = Partial<
|
package/src/zod.ts
CHANGED
|
@@ -14,7 +14,6 @@ export function expectedTypeFor(kind: FieldKind): "string" | "number" | "boolean
|
|
|
14
14
|
case "blocks":
|
|
15
15
|
return "array";
|
|
16
16
|
case "text":
|
|
17
|
-
case "slug":
|
|
18
17
|
case "locale":
|
|
19
18
|
case "image":
|
|
20
19
|
case "relation":
|
|
@@ -37,8 +36,6 @@ export function exampleValueFor(kind: FieldKind): unknown {
|
|
|
37
36
|
return [];
|
|
38
37
|
case "image":
|
|
39
38
|
return "https://example.com/image.jpg";
|
|
40
|
-
case "slug":
|
|
41
|
-
return "example-slug";
|
|
42
39
|
case "locale":
|
|
43
40
|
return "en";
|
|
44
41
|
case "relation":
|