@backmatter/core 0.0.28 → 0.0.30
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/model.ts +36 -0
- package/src/zod.ts +0 -3
package/package.json
CHANGED
package/src/model.ts
CHANGED
|
@@ -257,7 +257,43 @@ export function serializeSchema(
|
|
|
257
257
|
return snapshot;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
/** Remove `{locale}` path/route segments from rows stored before locale removal. */
|
|
261
|
+
export function stripLocaleTemplateSegments(template: string): string {
|
|
262
|
+
return template.split("/").filter((part) => part !== "{locale}").join("/");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function migrateLegacySchemaInput(input: unknown): unknown {
|
|
266
|
+
if (!input || typeof input !== "object") return input;
|
|
267
|
+
const value = input as Record<string, unknown>;
|
|
268
|
+
if (!Array.isArray(value.models)) return input;
|
|
269
|
+
return {
|
|
270
|
+
...value,
|
|
271
|
+
models: value.models.map((raw) => {
|
|
272
|
+
if (!raw || typeof raw !== "object") return raw;
|
|
273
|
+
const model = raw as Record<string, unknown>;
|
|
274
|
+
const next: Record<string, unknown> = { ...model };
|
|
275
|
+
if (typeof model.path === "string") {
|
|
276
|
+
next.path = stripLocaleTemplateSegments(model.path);
|
|
277
|
+
}
|
|
278
|
+
if (typeof model.route === "string") {
|
|
279
|
+
next.route = stripLocaleTemplateSegments(model.route);
|
|
280
|
+
}
|
|
281
|
+
if (model.fields && typeof model.fields === "object" && !Array.isArray(model.fields)) {
|
|
282
|
+
const fields = { ...(model.fields as Record<string, unknown>) };
|
|
283
|
+
for (const [key, snap] of Object.entries(fields)) {
|
|
284
|
+
if (snap && typeof snap === "object" && (snap as FieldSnapshot).kind === "locale") {
|
|
285
|
+
delete fields[key];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
next.fields = fields;
|
|
289
|
+
}
|
|
290
|
+
return next;
|
|
291
|
+
}),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
260
295
|
export function parseSchemaSnapshot(input: unknown): SchemaSnapshot {
|
|
296
|
+
input = migrateLegacySchemaInput(input);
|
|
261
297
|
if (!input || typeof input !== "object") {
|
|
262
298
|
throw new Error("schema must be an object");
|
|
263
299
|
}
|
package/src/zod.ts
CHANGED
|
@@ -20,7 +20,6 @@ export function expectedTypeFor(
|
|
|
20
20
|
case "object":
|
|
21
21
|
return "object";
|
|
22
22
|
case "text":
|
|
23
|
-
case "locale":
|
|
24
23
|
case "image":
|
|
25
24
|
case "media":
|
|
26
25
|
case "relation":
|
|
@@ -48,8 +47,6 @@ export function exampleValueFor(kind: FieldKind): unknown {
|
|
|
48
47
|
return "https://example.com/image.jpg";
|
|
49
48
|
case "media":
|
|
50
49
|
return "https://cdn.backmatter.app/img/med_018f6b3e-7c2a-7b1d-8e4f-9a0b1c2d3e4f";
|
|
51
|
-
case "locale":
|
|
52
|
-
return "en";
|
|
53
50
|
case "relation":
|
|
54
51
|
return "related-slug";
|
|
55
52
|
case "text":
|