@crombolo/schema 0.62.0 → 0.64.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/config-references.ts +3 -2
- package/src/edit.ts +1 -2
- package/src/generate-delivery.ts +6 -0
- package/src/generate.ts +5 -0
- package/src/presets.ts +7 -0
- package/src/user-groups.ts +26 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.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.64.0",
|
|
32
|
+
"@crombolo/data": "0.64.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/config-references.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* where it expects one), and export writes keys back as aliases. A value shaped
|
|
6
6
|
* like a uuid is a key already and passes through either way.
|
|
7
7
|
*/
|
|
8
|
+
import { BLOCK_EDITORS } from '@crombolo/core'
|
|
8
9
|
import type { SchemaTypeKind } from './model.ts'
|
|
9
10
|
|
|
10
11
|
/** What a reference must name: an element type, or a type of one kind. */
|
|
@@ -28,8 +29,8 @@ export const CONFIG_REFERENCES: Readonly<Record<string, readonly FieldReference[
|
|
|
28
29
|
'Umbraco.ElementPicker': [{ path: ['allowedContentTypes'], many: true, kind: 'element' }],
|
|
29
30
|
'Umbraco.MediaPicker3': [{ path: ['filter'], many: true, kind: 'media' }],
|
|
30
31
|
'Umbraco.MultiNodeTreePicker': [{ path: ['filter'], many: true, kind: 'startNode' }],
|
|
31
|
-
'
|
|
32
|
-
|
|
32
|
+
// Every block editor's blocks are element types; a grid's areas name more.
|
|
33
|
+
...Object.fromEntries([...BLOCK_EDITORS].map((editor) => [editor, BLOCK_FIELDS])),
|
|
33
34
|
'Umbraco.BlockGrid': [
|
|
34
35
|
...BLOCK_FIELDS,
|
|
35
36
|
{
|
package/src/edit.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* the changed type, or the reason it cannot change. Whether the change is safe
|
|
5
5
|
* for the site's content is the check's to say, not these.
|
|
6
6
|
*/
|
|
7
|
+
import { BLOCK_EDITORS } from '@crombolo/core'
|
|
7
8
|
import {
|
|
8
9
|
allProperties,
|
|
9
10
|
type SchemaContentType,
|
|
@@ -289,8 +290,6 @@ export interface DataTypeChanges {
|
|
|
289
290
|
startNode?: string | null
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
const BLOCK_EDITORS = new Set(['Umbraco.BlockList', 'Umbraco.BlockGrid', 'Umbraco.RichText'])
|
|
293
|
-
|
|
294
293
|
/** The preset whose editor a data type uses, when there is one. */
|
|
295
294
|
const presetFor = (dataType: SchemaDataType) =>
|
|
296
295
|
Object.entries(DATA_TYPE_PRESETS).find(([, preset]) => preset.editor === dataType.editor)
|
package/src/generate-delivery.ts
CHANGED
|
@@ -94,6 +94,11 @@ export function generateDeliveryTypes(set: SchemaSet, options: DeliveryTypesOpti
|
|
|
94
94
|
const { content, settings } = blockElements(set, config, blocks)
|
|
95
95
|
return `ApiBlockGrid<${elementUnion(content)}, ${elementUnion(settings)}>`
|
|
96
96
|
}
|
|
97
|
+
// One item; null when empty, as any property here may be (story 345).
|
|
98
|
+
case 'Umbraco.SingleBlock': {
|
|
99
|
+
const { content, settings } = blockElements(set, config, blocks)
|
|
100
|
+
return `ApiBlockListItem<${elementUnion(content)}, ${elementUnion(settings)}>`
|
|
101
|
+
}
|
|
97
102
|
case 'Umbraco.ElementPicker': {
|
|
98
103
|
return `Array<${elementUnion([...new Set(keyAliases(set, config.allowedContentTypes))])}>`
|
|
99
104
|
}
|
|
@@ -212,6 +217,7 @@ export function generateDeliveryTypes(set: SchemaSet, options: DeliveryTypesOpti
|
|
|
212
217
|
const shapes = [
|
|
213
218
|
'ApiBlockGrid',
|
|
214
219
|
'ApiBlockList',
|
|
220
|
+
'ApiBlockListItem',
|
|
215
221
|
'ApiColor',
|
|
216
222
|
'ApiContentReference',
|
|
217
223
|
'ApiElement',
|
package/src/generate.ts
CHANGED
|
@@ -119,6 +119,11 @@ function tsTypeFor(set: SchemaSet, dataTypeAlias: string): string {
|
|
|
119
119
|
const { content } = blockElements(set, config, blocks)
|
|
120
120
|
return `BlockListValue<BlockGridItem & { content: ${elementUnion(content)} }>`
|
|
121
121
|
}
|
|
122
|
+
// One block, or null (story 345).
|
|
123
|
+
case 'Umbraco.SingleBlock': {
|
|
124
|
+
const { content, settings } = blockElements(set, config, blocks)
|
|
125
|
+
return `(BlockItem & { content: ${elementUnion(content)}; settings: ${settings.length ? `${elementUnion(settings)} | null` : 'PublishedElement | null'} }) | null`
|
|
126
|
+
}
|
|
122
127
|
}
|
|
123
128
|
switch (storageTypeFor(editor)) {
|
|
124
129
|
case 'Integer':
|
package/src/presets.ts
CHANGED
|
@@ -122,6 +122,13 @@ export const DATA_TYPE_PRESETS: Readonly<Record<string, Preset>> = {
|
|
|
122
122
|
takes: ['block', 'min', 'max'],
|
|
123
123
|
build: (o) => ({ config: defined({ validationLimit: limit(o) }), blocks: blocks(o) }),
|
|
124
124
|
},
|
|
125
|
+
// One block: a page's one hero or call to action (story 345).
|
|
126
|
+
'single-block': {
|
|
127
|
+
editor: 'Umbraco.SingleBlock',
|
|
128
|
+
editorUi: 'Umb.PropertyEditorUi.BlockSingle',
|
|
129
|
+
takes: ['block'],
|
|
130
|
+
build: (o) => ({ config: {}, blocks: blocks(o) }),
|
|
131
|
+
},
|
|
125
132
|
'block-grid': {
|
|
126
133
|
editor: 'Umbraco.BlockGrid',
|
|
127
134
|
editorUi: 'Umb.PropertyEditorUi.BlockGrid',
|
package/src/user-groups.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `schema/user-groups/*.toml` — user groups a site declares (story 228): what a
|
|
3
|
-
* group is (its name, sections, permission verbs and
|
|
4
|
-
* starts or who is in it, which each environment's Users section keeps. Strict
|
|
3
|
+
* group is (its name, sections, permission verbs, languages and owners), never
|
|
4
|
+
* where it starts or who is in it, which each environment's Users section keeps. Strict
|
|
5
5
|
* as the type parser is, and canonical on the way out, so
|
|
6
6
|
* `parseUserGroup(writeUserGroup(x))` equals `x`. `docs/schema-as-code.md`.
|
|
7
7
|
*/
|
|
8
8
|
import {
|
|
9
9
|
ADMIN_GROUP_ALIAS,
|
|
10
10
|
isExtensionSectionAlias,
|
|
11
|
+
isRemotePermission,
|
|
11
12
|
KNOWN_PERMISSIONS,
|
|
12
13
|
RETIRED_SECTIONS,
|
|
13
14
|
SECTION_ALIASES,
|
|
15
|
+
withoutPrunedPermissions,
|
|
14
16
|
} from '@crombolo/core'
|
|
15
17
|
import { type ParseResult, Reader, toml } from './reader.ts'
|
|
16
18
|
|
|
@@ -24,9 +26,20 @@ export interface SchemaUserGroup {
|
|
|
24
26
|
permissions: string[]
|
|
25
27
|
/** ISO codes, or every language. */
|
|
26
28
|
languages: string[] | 'all'
|
|
29
|
+
/** The aliases of the groups whose members choose who is in it (story 302). */
|
|
30
|
+
owners?: string[]
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
const KEYS = [
|
|
33
|
+
const KEYS = [
|
|
34
|
+
'alias',
|
|
35
|
+
'name',
|
|
36
|
+
'description',
|
|
37
|
+
'icon',
|
|
38
|
+
'sections',
|
|
39
|
+
'permissions',
|
|
40
|
+
'languages',
|
|
41
|
+
'owners',
|
|
42
|
+
]
|
|
30
43
|
|
|
31
44
|
export function parseUserGroup(file: string, source: string): ParseResult<SchemaUserGroup> {
|
|
32
45
|
const r = new Reader(file)
|
|
@@ -55,7 +68,8 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
55
68
|
`${path}.sections`,
|
|
56
69
|
`"${section}" is not a section: one of ${Object.keys(SECTION_ALIASES).join(', ')}, or an extension's section alias`,
|
|
57
70
|
)
|
|
58
|
-
|
|
71
|
+
// A verb story 338 took out is read as what replaced it, so a file written before still loads.
|
|
72
|
+
const permissions = withoutPrunedPermissions(r.strs(t, 'permissions', path))
|
|
59
73
|
for (const permission of permissions)
|
|
60
74
|
if (!KNOWN_PERMISSIONS.has(permission))
|
|
61
75
|
r.problem(
|
|
@@ -65,6 +79,12 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
65
79
|
let languages: string[] | 'all' = []
|
|
66
80
|
if (t.languages === 'all') languages = 'all'
|
|
67
81
|
else if (t.languages !== undefined) languages = r.strs(t, 'languages', path)
|
|
82
|
+
const owners = t.owners === undefined ? undefined : r.strs(t, 'owners', path)
|
|
83
|
+
if (owners?.length && permissions.some(isRemotePermission))
|
|
84
|
+
r.problem(
|
|
85
|
+
`${path}.owners`,
|
|
86
|
+
"a group that can move sites or install code is only an administrator's to fill, so it cannot have owners",
|
|
87
|
+
)
|
|
68
88
|
const description = r.str(t, 'description', path)
|
|
69
89
|
const icon = r.str(t, 'icon', path)
|
|
70
90
|
const value: SchemaUserGroup = {
|
|
@@ -75,6 +95,7 @@ export function parseUserGroup(file: string, source: string): ParseResult<Schema
|
|
|
75
95
|
sections,
|
|
76
96
|
permissions,
|
|
77
97
|
languages,
|
|
98
|
+
...(owners !== undefined ? { owners } : {}),
|
|
78
99
|
}
|
|
79
100
|
return { value: r.problems.length === 0 ? value : undefined, problems: r.problems }
|
|
80
101
|
}
|
|
@@ -91,5 +112,6 @@ export function writeUserGroup(group: SchemaUserGroup): string {
|
|
|
91
112
|
`permissions = ${list(group.permissions)}`,
|
|
92
113
|
`languages = ${group.languages === 'all' ? '"all"' : list(group.languages)}`,
|
|
93
114
|
)
|
|
115
|
+
if (group.owners !== undefined) out.push(`owners = ${list(group.owners)}`)
|
|
94
116
|
return `${out.join('\n')}\n`
|
|
95
117
|
}
|