@crombolo/schema 0.56.0 → 0.58.0
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 +3 -3
- package/src/export.ts +1 -0
- package/src/index.ts +1 -0
- package/src/model.ts +3 -1
- package/src/parse.ts +22 -2
- package/src/seo-mapping.ts +58 -0
- package/src/sync.ts +2 -1
- package/src/validate.ts +2 -0
- package/src/write.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Schema-as-code for crombolo: TOML document, media and member type definitions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.58.0",
|
|
32
|
+
"@crombolo/data": "0.58.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/export.ts
CHANGED
|
@@ -113,6 +113,7 @@ export function toSchemaContentType(
|
|
|
113
113
|
}
|
|
114
114
|
if (aggregate.description) type.description = aggregate.description
|
|
115
115
|
if (aggregate.siteSearch === false) type.siteSearch = false
|
|
116
|
+
if (aggregate.seo && Object.keys(aggregate.seo).length > 0) type.seo = { ...aggregate.seo }
|
|
116
117
|
if (aggregate.siteSettings) type.siteSettings = true
|
|
117
118
|
if (aggregate.defaultComponentKey) {
|
|
118
119
|
const alias = ctx.componentAlias(aggregate.defaultComponentKey)
|
package/src/index.ts
CHANGED
package/src/model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SchemaForm, SchemaWorkflow, SiteSearchLevel } from '@crombolo/core'
|
|
1
|
+
import type { SchemaForm, SchemaWorkflow, SeoMapping, SiteSearchLevel } from '@crombolo/core'
|
|
2
2
|
import type { SchemaUserGroup } from './user-groups.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -80,6 +80,8 @@ export interface SchemaContentType {
|
|
|
80
80
|
siteSearch?: false
|
|
81
81
|
/** A site's settings (story 058): its page, a root's direct child, has no address. */
|
|
82
82
|
siteSettings?: true
|
|
83
|
+
/** `[seo]`: where its pages take their search and sharing values from (story 317). */
|
|
84
|
+
seo?: SeoMapping
|
|
83
85
|
/** Properties outside any tab. */
|
|
84
86
|
properties: SchemaProperty[]
|
|
85
87
|
/** Groups outside any tab — `[[group]]`; Umbraco's built-in media types use one. */
|
package/src/parse.ts
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
* the most common mistake a non-developer makes and silently ignoring it would
|
|
4
4
|
* hide the thing they were trying to do.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
SEO_MAPPING_FIELDS,
|
|
8
|
+
type SeoMapping,
|
|
9
|
+
SITE_SEARCH_LEVELS,
|
|
10
|
+
type SiteSearchLevel,
|
|
11
|
+
} from '@crombolo/core'
|
|
7
12
|
import {
|
|
8
13
|
type SchemaBlock,
|
|
9
14
|
type SchemaBlockAllowance,
|
|
@@ -261,7 +266,7 @@ export function parseContentType(
|
|
|
261
266
|
const root = toml(source, r)
|
|
262
267
|
if (!root) return { value: undefined, problems: r.problems }
|
|
263
268
|
const header = TYPE_KIND_FILES[kind].header
|
|
264
|
-
r.unknown(root, [header, 'tab', 'group', 'property'], '')
|
|
269
|
+
r.unknown(root, [header, 'tab', 'group', 'property', ...(kind === 'document' ? ['seo'] : [])], '')
|
|
265
270
|
const t = r.table(root[header], header)
|
|
266
271
|
if (!t) {
|
|
267
272
|
r.problem(header, `a [${header}] table is required`)
|
|
@@ -307,6 +312,7 @@ export function parseContentType(
|
|
|
307
312
|
? { siteSearch: false as const }
|
|
308
313
|
: {}),
|
|
309
314
|
...(r.bool(t, 'site-settings', path, false) ? { siteSettings: true as const } : {}),
|
|
315
|
+
...seoMapping(r, root.seo),
|
|
310
316
|
properties: r.tables(root.property, 'property').map((p, i) => property(r, p, `property[${i}]`)),
|
|
311
317
|
tabs: r.tables(root.tab, 'tab').map((x, i) => tab(r, x, `tab[${i}]`)),
|
|
312
318
|
groups: r.tables(root.group, 'group').map((g, i) => group(r, g, `group[${i}]`)),
|
|
@@ -319,6 +325,20 @@ export function parseContentType(
|
|
|
319
325
|
return { value: r.problems.length === 0 ? value : undefined, problems: r.problems }
|
|
320
326
|
}
|
|
321
327
|
|
|
328
|
+
/** `[seo]`: where the type's pages take their search and sharing values from (story 317). */
|
|
329
|
+
function seoMapping(r: Reader, raw: unknown): { seo?: SeoMapping } {
|
|
330
|
+
if (raw === undefined) return {}
|
|
331
|
+
const t = r.table(raw, 'seo')
|
|
332
|
+
if (!t) return {}
|
|
333
|
+
r.unknown(t, SEO_MAPPING_FIELDS, 'seo')
|
|
334
|
+
const seo: SeoMapping = {}
|
|
335
|
+
for (const field of SEO_MAPPING_FIELDS) {
|
|
336
|
+
const value = r.str(t, field, 'seo')
|
|
337
|
+
if (value) seo[field] = value
|
|
338
|
+
}
|
|
339
|
+
return Object.keys(seo).length > 0 ? { seo } : {}
|
|
340
|
+
}
|
|
341
|
+
|
|
322
342
|
/** `site-search` on a content type: only false, which leaves its pages out. */
|
|
323
343
|
function typeSiteSearch(r: Reader, t: Toml, path: string): false | undefined {
|
|
324
344
|
if (t['site-search'] === false) return false
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks a content type's `[seo]` table (story 317): each `{alias}` it names is
|
|
3
|
+
* a property of the type or its compositions, and `image` is a media picker's,
|
|
4
|
+
* or a media item's key.
|
|
5
|
+
*/
|
|
6
|
+
import { seoTokens } from '@crombolo/core'
|
|
7
|
+
import { effectiveProperties } from './compositions.ts'
|
|
8
|
+
import { dataTypeOf } from './generate.ts'
|
|
9
|
+
import type { SchemaContentType, SchemaSet } from './model.ts'
|
|
10
|
+
|
|
11
|
+
const MEDIA_KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
12
|
+
|
|
13
|
+
/** The properties a type's values may name, its compositions' included, and which are media pickers. */
|
|
14
|
+
export function seoMappingProperties(
|
|
15
|
+
set: SchemaSet,
|
|
16
|
+
type: SchemaContentType,
|
|
17
|
+
): Array<{ alias: string; name: string; mediaPicker: boolean }> {
|
|
18
|
+
return effectiveProperties(set, type).map((p) => ({
|
|
19
|
+
alias: p.alias,
|
|
20
|
+
name: p.name,
|
|
21
|
+
mediaPicker: dataTypeOf(set, p.type).editor === 'Umbraco.MediaPicker3',
|
|
22
|
+
}))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function seoMappingProblems(
|
|
26
|
+
set: SchemaSet,
|
|
27
|
+
type: SchemaContentType,
|
|
28
|
+
): Array<{ path: string; message: string }> {
|
|
29
|
+
const seo = type.seo
|
|
30
|
+
if (!seo) return []
|
|
31
|
+
const problems: Array<{ path: string; message: string }> = []
|
|
32
|
+
const properties = new Map(effectiveProperties(set, type).map((p) => [p.alias, p]))
|
|
33
|
+
for (const field of ['title', 'description', 'canonical'] as const) {
|
|
34
|
+
const value = seo[field]
|
|
35
|
+
if (!value) continue
|
|
36
|
+
for (const token of seoTokens(value))
|
|
37
|
+
if (token.kind === 'property' && !properties.has(token.alias))
|
|
38
|
+
problems.push({
|
|
39
|
+
path: `seo.${field}`,
|
|
40
|
+
message: `"${type.alias}" has no property "${token.alias}"`,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
// A fixed image is a media item's key.
|
|
44
|
+
if (seo.image && !MEDIA_KEY.test(seo.image)) {
|
|
45
|
+
const property = properties.get(seo.image)
|
|
46
|
+
if (!property)
|
|
47
|
+
problems.push({
|
|
48
|
+
path: 'seo.image',
|
|
49
|
+
message: `"${type.alias}" has no property "${seo.image}"`,
|
|
50
|
+
})
|
|
51
|
+
else if (dataTypeOf(set, property.type).editor !== 'Umbraco.MediaPicker3')
|
|
52
|
+
problems.push({
|
|
53
|
+
path: 'seo.image',
|
|
54
|
+
message: `"${seo.image}" is not a media picker, so it cannot be the sharing image`,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
return problems
|
|
58
|
+
}
|
package/src/sync.ts
CHANGED
|
@@ -200,7 +200,7 @@ export async function syncSchema(
|
|
|
200
200
|
if (hash === current.hash) return emptySyncReport('skipped-same')
|
|
201
201
|
if (options.mode === 'production')
|
|
202
202
|
return emptySyncReport('refused', {
|
|
203
|
-
reason: `the definitions changed without a new version (still ${set.version}); \`crombolo
|
|
203
|
+
reason: `the definitions changed without a new version (still ${set.version}); \`crombolo site build\` or \`crombolo push\` from the site gives them one, or deploy with a newer revision`,
|
|
204
204
|
})
|
|
205
205
|
}
|
|
206
206
|
|
|
@@ -582,6 +582,7 @@ export async function syncSchema(
|
|
|
582
582
|
sinceVersion: t.since ?? null,
|
|
583
583
|
siteSearch: t.siteSearch !== false,
|
|
584
584
|
siteSettings: t.siteSettings === true,
|
|
585
|
+
seo: t.seo ?? null,
|
|
585
586
|
cleanup: {
|
|
586
587
|
preventCleanup: t.cleanup.prevent,
|
|
587
588
|
keepAllVersionsNewerThanDays: t.cleanup.keepAllNewerThanDays ?? null,
|
package/src/validate.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type SchemaSet,
|
|
27
27
|
TYPE_KIND_FILES,
|
|
28
28
|
} from './model.ts'
|
|
29
|
+
import { seoMappingProblems } from './seo-mapping.ts'
|
|
29
30
|
import { type ValidateFormsOptions, validateForms } from './validate-forms.ts'
|
|
30
31
|
import { validateWorkflows } from './workflows.ts'
|
|
31
32
|
|
|
@@ -188,6 +189,7 @@ export function validateSchemaSet(set: SchemaSet, options: ValidateOptions = {})
|
|
|
188
189
|
if (!known(c)) add(file, `${header}.allow-children`, `unknown type "${c}"`)
|
|
189
190
|
if (t.collection && !dataTypeAliases.has(t.collection))
|
|
190
191
|
add(file, `${header}.collection`, `unknown data type "${t.collection}"`)
|
|
192
|
+
for (const problem of seoMappingProblems(set, t)) add(file, problem.path, problem.message)
|
|
191
193
|
}
|
|
192
194
|
for (const t of types) {
|
|
193
195
|
const cycle = findCompositionCycle(t.alias, byAlias)
|
package/src/write.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* that survive), and none of the quote or blank-line churn of general-purpose
|
|
7
7
|
* TOML serialisers. `parse(write(x))` must equal `x` — the tests hold it to that.
|
|
8
8
|
*/
|
|
9
|
+
import { SEO_MAPPING_FIELDS } from '@crombolo/core'
|
|
9
10
|
import {
|
|
10
11
|
dataTypeKeyFor,
|
|
11
12
|
isDerived,
|
|
@@ -137,6 +138,10 @@ export function writeContentType(t: SchemaContentType, kind: SchemaTypeKind = 'd
|
|
|
137
138
|
line(out, 'keep-all-newer-than-days', t.cleanup.keepAllNewerThanDays)
|
|
138
139
|
line(out, 'keep-latest-per-day-for-days', t.cleanup.keepLatestPerDayForDays)
|
|
139
140
|
}
|
|
141
|
+
if (t.seo && Object.keys(t.seo).length > 0) {
|
|
142
|
+
out.push('', '[seo]')
|
|
143
|
+
for (const field of SEO_MAPPING_FIELDS) line(out, field, t.seo[field])
|
|
144
|
+
}
|
|
140
145
|
for (const p of t.properties) writeProperty(out, 'property', p, owner)
|
|
141
146
|
for (const g of t.groups ?? []) {
|
|
142
147
|
out.push('', '[[group]]')
|