@crombolo/server 0.52.2 → 0.53.2
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 +13 -13
- package/src/adapters/content.ts +23 -1
- package/src/approvals-api.ts +15 -7
- package/src/config.ts +1 -1
- package/src/ports.ts +2 -1
- package/src/seed/compile.ts +62 -15
- package/src/seed/export.ts +44 -5
- package/src/seed/read.ts +23 -6
- package/src/seed/values.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.2",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@crombolo/api-delivery": "0.
|
|
35
|
-
"@crombolo/api-management": "0.
|
|
36
|
-
"@crombolo/auth": "0.
|
|
37
|
-
"@crombolo/backoffice-host": "0.
|
|
38
|
-
"@crombolo/common": "0.
|
|
39
|
-
"@crombolo/content": "0.
|
|
40
|
-
"@crombolo/contracts": "0.
|
|
41
|
-
"@crombolo/core": "0.
|
|
42
|
-
"@crombolo/data": "0.
|
|
43
|
-
"@crombolo/render": "0.
|
|
44
|
-
"@crombolo/schema": "0.
|
|
45
|
-
"@crombolo/transfer": "0.
|
|
34
|
+
"@crombolo/api-delivery": "0.53.2",
|
|
35
|
+
"@crombolo/api-management": "0.53.2",
|
|
36
|
+
"@crombolo/auth": "0.53.2",
|
|
37
|
+
"@crombolo/backoffice-host": "0.53.2",
|
|
38
|
+
"@crombolo/common": "0.53.2",
|
|
39
|
+
"@crombolo/content": "0.53.2",
|
|
40
|
+
"@crombolo/contracts": "0.53.2",
|
|
41
|
+
"@crombolo/core": "0.53.2",
|
|
42
|
+
"@crombolo/data": "0.53.2",
|
|
43
|
+
"@crombolo/render": "0.53.2",
|
|
44
|
+
"@crombolo/schema": "0.53.2",
|
|
45
|
+
"@crombolo/transfer": "0.53.2",
|
|
46
46
|
"@logtape/logtape": "^2.3.8",
|
|
47
47
|
"@opentelemetry/api": "1.10.0",
|
|
48
48
|
"@opentelemetry/context-async-hooks": "3.0.0",
|
package/src/adapters/content.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
type ContentTypeRepositoryOptions,
|
|
33
33
|
DataTypeRepository,
|
|
34
34
|
type Db,
|
|
35
|
+
FORM_LIBRARY_FOLDER,
|
|
35
36
|
FolderRepository,
|
|
36
37
|
Locks,
|
|
37
38
|
type NodeRepository,
|
|
@@ -199,6 +200,19 @@ export interface ContentTypePortOptions extends ContentTypeRepositoryOptions {
|
|
|
199
200
|
componentFiles?: ComponentFileStore
|
|
200
201
|
}
|
|
201
202
|
|
|
203
|
+
/** Whether a tree item is the folder holding the types made from forms, and nothing else. */
|
|
204
|
+
async function madeFromForms(db: Db, item: TreeItem): Promise<boolean> {
|
|
205
|
+
if (!item.isFolder || item.name !== FORM_LIBRARY_FOLDER) return false
|
|
206
|
+
const rows = await db.q
|
|
207
|
+
.selectFrom('node as folder')
|
|
208
|
+
.innerJoin('node as child', 'child.parent_id', 'folder.id')
|
|
209
|
+
.leftJoin('content_type as type', 'type.node_id', 'child.id')
|
|
210
|
+
.select('type.form_key')
|
|
211
|
+
.where('folder.unique_id', '=', item.key)
|
|
212
|
+
.execute()
|
|
213
|
+
return rows.length > 0 && rows.every((row) => row.form_key)
|
|
214
|
+
}
|
|
215
|
+
|
|
202
216
|
export function createContentTypePort(
|
|
203
217
|
db: Db,
|
|
204
218
|
schemaFiles?: SchemaFiles,
|
|
@@ -508,7 +522,15 @@ export function createContentTypePort(
|
|
|
508
522
|
'renameFolder',
|
|
509
523
|
'deleteFolder',
|
|
510
524
|
]),
|
|
511
|
-
treeRoot:
|
|
525
|
+
async treeRoot(paging: TreePage): Promise<Page<TreeItem>> {
|
|
526
|
+
const page = await tree.treeRoot(paging)
|
|
527
|
+
if (kind !== 'document') return page
|
|
528
|
+
// Forms sit beside content types in Structure, so the types made from them
|
|
529
|
+
// aren't shown twice. Library and the pickers read them directly.
|
|
530
|
+
const shown: TreeItem[] = []
|
|
531
|
+
for (const item of page.items) if (!(await madeFromForms(db, item))) shown.push(item)
|
|
532
|
+
return { total: page.total - (page.items.length - shown.length), items: shown }
|
|
533
|
+
},
|
|
512
534
|
treeChildren: tree.treeChildren,
|
|
513
535
|
|
|
514
536
|
async root(paging: SkipTake): Promise<Page<TreeItem>> {
|
package/src/approvals-api.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
11
11
|
import { dirname, join } from 'node:path'
|
|
12
|
-
import type
|
|
12
|
+
import { hasSection, type Principal } from '@crombolo/api-management/domain'
|
|
13
13
|
import type { SchemaWorkflow } from '@crombolo/core'
|
|
14
14
|
import {
|
|
15
15
|
type ApprovalScheduleEntry,
|
|
@@ -51,6 +51,10 @@ export async function syncWorkflowFiles(db: Db, schemaDir: string) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/** What saving a workflow would do to the requests in flight under it. */
|
|
54
|
+
/** Setting up workflows, which a group can be given (story 296). Deciding on a page is separate. */
|
|
55
|
+
const mayDesignWorkflows = (principal: Principal): boolean =>
|
|
56
|
+
principal.isAdmin || hasSection(principal, 'workflowSetup')
|
|
57
|
+
|
|
54
58
|
async function changePreview(approvals: Approvals, principal: Principal, workflow: SchemaWorkflow) {
|
|
55
59
|
const id = workflow.key ?? workflow.alias
|
|
56
60
|
const stored = (await approvals.workflows()).find(
|
|
@@ -152,8 +156,8 @@ export async function handleApprovalsApi(
|
|
|
152
156
|
file ? folderOf(ctx.schemaDir, 'workflows', file) : ''
|
|
153
157
|
const folders = /^workflows\/(tree-folders|tree-move)$/.exec(path)
|
|
154
158
|
if (folders) {
|
|
155
|
-
if (!principal
|
|
156
|
-
return json({ ok: false, message: '
|
|
159
|
+
if (!mayDesignWorkflows(principal))
|
|
160
|
+
return json({ ok: false, message: 'You do not have access to set up workflows.' }, 403)
|
|
157
161
|
const response = await folderAction('workflows', folders[1] as string, request, {
|
|
158
162
|
schemaDir: ctx.schemaDir,
|
|
159
163
|
writable: ctx.writable,
|
|
@@ -171,8 +175,12 @@ export async function handleApprovalsApi(
|
|
|
171
175
|
folder: folderIn(loaded.files.get(`workflow:${s.workflow.alias}`)),
|
|
172
176
|
})),
|
|
173
177
|
folders: foldersIn(ctx.schemaDir, 'workflows'),
|
|
174
|
-
readOnlyBecause: ctx.writable
|
|
175
|
-
|
|
178
|
+
readOnlyBecause: ctx.writable
|
|
179
|
+
? mayDesignWorkflows(principal)
|
|
180
|
+
? null
|
|
181
|
+
: 'permission'
|
|
182
|
+
: 'site',
|
|
183
|
+
editable: ctx.writable && mayDesignWorkflows(principal),
|
|
176
184
|
groups: (await new UserGroupRepository(ctx.db).all()).map((g) => ({
|
|
177
185
|
alias: g.alias,
|
|
178
186
|
name: g.name,
|
|
@@ -183,8 +191,8 @@ export async function handleApprovalsApi(
|
|
|
183
191
|
|
|
184
192
|
match = /^workflows\/([^/]+)(\/preview)?$/.exec(path)
|
|
185
193
|
if (match) {
|
|
186
|
-
if (!principal
|
|
187
|
-
return json({ ok: false, message: '
|
|
194
|
+
if (!mayDesignWorkflows(principal))
|
|
195
|
+
return json({ ok: false, message: 'You do not have access to set up workflows.' }, 403)
|
|
188
196
|
const alias = decodeURIComponent(match[1] as string)
|
|
189
197
|
const here = loadSchemaDirectory(ctx.schemaDir).files.get(`workflow:${alias}`)
|
|
190
198
|
const file = here ?? join(ctx.schemaDir, 'workflows', fileNameFor(alias))
|
package/src/config.ts
CHANGED
|
@@ -1091,7 +1091,7 @@ export function describeDatabase(
|
|
|
1091
1091
|
}
|
|
1092
1092
|
}
|
|
1093
1093
|
|
|
1094
|
-
export const VERSION = '0.
|
|
1094
|
+
export const VERSION = '0.53.2'
|
|
1095
1095
|
|
|
1096
1096
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1097
1097
|
/** A positive number from a setting, else the default. */
|
package/src/ports.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import type { EventSink } from '@crombolo/content'
|
|
28
28
|
import {
|
|
29
29
|
CORE_SECTION_ALIASES,
|
|
30
|
+
clientSections,
|
|
30
31
|
DEFAULT_UPLOAD_SETTINGS,
|
|
31
32
|
hasAccessToSensitiveData,
|
|
32
33
|
isUploadAllowed,
|
|
@@ -255,7 +256,7 @@ function createCurrentUserPort(
|
|
|
255
256
|
hasAccessToSensitiveData: hasAccessToSensitiveData(principal.groups),
|
|
256
257
|
fallbackPermissions: principal.permissions,
|
|
257
258
|
permissions,
|
|
258
|
-
allowedSections: principal
|
|
259
|
+
allowedSections: clientSections(principal),
|
|
259
260
|
userGroupIds: principal.groupKeys.map((id) => ({ id })),
|
|
260
261
|
}
|
|
261
262
|
},
|
package/src/seed/compile.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
type BundleNode,
|
|
36
36
|
type BundleValue,
|
|
37
37
|
type ContentSet,
|
|
38
|
+
ELEMENT_FOLDER_TYPE,
|
|
38
39
|
referenceCandidates,
|
|
39
40
|
writeBundle,
|
|
40
41
|
writeBundlePackage,
|
|
@@ -47,6 +48,7 @@ import { lineOf } from './lines.ts'
|
|
|
47
48
|
import {
|
|
48
49
|
DICTIONARY_FILE,
|
|
49
50
|
kindDir,
|
|
51
|
+
nameFromSegment,
|
|
50
52
|
readSeed,
|
|
51
53
|
readSeedDictionary,
|
|
52
54
|
type SeedFinding,
|
|
@@ -67,12 +69,6 @@ export interface SeedBuild {
|
|
|
67
69
|
dictionary?: DictionaryEntry[]
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
/** A word for a file name: `about-us` → `About us`. */
|
|
71
|
-
const nameFromSegment = (segment: string) => {
|
|
72
|
-
const words = segment.replace(/[-_]+/g, ' ').trim()
|
|
73
|
-
return words.charAt(0).toUpperCase() + words.slice(1)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
72
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
77
73
|
typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date)
|
|
78
74
|
|
|
@@ -214,16 +210,42 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
214
210
|
}
|
|
215
211
|
const libraryKey = async (ref: string, why: string) => {
|
|
216
212
|
const seeded = libraryByPath.get(trimPath(ref))
|
|
217
|
-
if (seeded) return keyOf.get(seeded)
|
|
213
|
+
if (seeded) return seeded.folder ? undefined : keyOf.get(seeded)
|
|
218
214
|
if (looksLikeKey(ref)) return normaliseUuid(ref)
|
|
219
215
|
return siteNode(ref, ObjectTypes.Element, why)
|
|
220
216
|
}
|
|
217
|
+
const forms = loadSchemaDirectory(config.schemaDir).set.forms ?? []
|
|
218
|
+
/** A Library form by its path, else a form by its alias: what a form picker stores. */
|
|
219
|
+
const formKey = async (ref: string, why: string) => {
|
|
220
|
+
if (looksLikeKey(ref)) return normaliseUuid(ref)
|
|
221
|
+
const seeded = libraryByPath.get(trimPath(ref))
|
|
222
|
+
if (seeded && !seeded.folder) {
|
|
223
|
+
const type =
|
|
224
|
+
typeof seeded.data.type === 'string'
|
|
225
|
+
? await typeOf(documentTypes, seeded.data.type)
|
|
226
|
+
: undefined
|
|
227
|
+
return type?.formKey ? keyOf.get(seeded) : undefined
|
|
228
|
+
}
|
|
229
|
+
const form = forms.find((f) => f.alias.toLowerCase() === trimPath(ref))
|
|
230
|
+
if (form) return form.key ?? form.alias
|
|
231
|
+
const key = await siteNode(ref, ObjectTypes.Element, why)
|
|
232
|
+
if (!key) return undefined
|
|
233
|
+
const rows = await db.q
|
|
234
|
+
.selectFrom('node as n')
|
|
235
|
+
.innerJoin('content as c', 'c.node_id', 'n.id')
|
|
236
|
+
.innerJoin('content_type as ct', 'ct.node_id', 'c.content_type_id')
|
|
237
|
+
.select('ct.form_key')
|
|
238
|
+
.where('n.unique_id', '=', key)
|
|
239
|
+
.execute()
|
|
240
|
+
return rows[0]?.form_key ? key : undefined
|
|
241
|
+
}
|
|
221
242
|
|
|
222
243
|
// ---------------------------------------------------------------- values
|
|
223
244
|
const { convert } = valueWriter(lookup, {
|
|
224
245
|
content: contentKey,
|
|
225
246
|
media: mediaRef,
|
|
226
247
|
library: libraryKey,
|
|
248
|
+
form: formKey,
|
|
227
249
|
linkedMedia: async (path) => {
|
|
228
250
|
const media = mediaByPath.get(path.toLowerCase())
|
|
229
251
|
return media ? keyOf.get(media) : undefined
|
|
@@ -292,6 +314,29 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
292
314
|
for (const item of tree.items) {
|
|
293
315
|
const key = keyOf.get(item) as string
|
|
294
316
|
let type = typeOfItem.get(item)
|
|
317
|
+
if (item.kind === 'library' && item.folder) {
|
|
318
|
+
// A Library folder: a name and a place, as story 283 carries it.
|
|
319
|
+
bundleNodes.push({
|
|
320
|
+
key,
|
|
321
|
+
kind: 'element-folder',
|
|
322
|
+
contentType: { ...ELEMENT_FOLDER_TYPE },
|
|
323
|
+
parent: item.parent
|
|
324
|
+
? (keyOf.get(libraryByPath.get(item.parent.toLowerCase()) as SeedItem) ?? null)
|
|
325
|
+
: null,
|
|
326
|
+
sortOrder: 0,
|
|
327
|
+
template: null,
|
|
328
|
+
variants: [
|
|
329
|
+
{
|
|
330
|
+
culture: null,
|
|
331
|
+
segment: null,
|
|
332
|
+
name: nameOf(item)[0]?.name ?? item.path,
|
|
333
|
+
published: false,
|
|
334
|
+
},
|
|
335
|
+
],
|
|
336
|
+
values: [],
|
|
337
|
+
})
|
|
338
|
+
continue
|
|
339
|
+
}
|
|
295
340
|
if (item.kind !== 'media') {
|
|
296
341
|
if (typeof item.data.type !== 'string') {
|
|
297
342
|
find(item, [], 'no-type', 'an item names its content type: type = "<alias>"')
|
|
@@ -444,14 +489,16 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
444
489
|
if (template) usedComponents.add(template)
|
|
445
490
|
// Media has no published state: it is live as soon as it lands.
|
|
446
491
|
const published = item.kind !== 'media' && item.data.published !== false
|
|
447
|
-
const parent =
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
492
|
+
const parent = !item.parent
|
|
493
|
+
? null
|
|
494
|
+
: (keyOf.get(
|
|
495
|
+
(item.kind === 'media'
|
|
496
|
+
? mediaByPath
|
|
497
|
+
: item.kind === 'library'
|
|
498
|
+
? libraryByPath
|
|
499
|
+
: contentByPath
|
|
500
|
+
).get(item.parent.toLowerCase()) as SeedItem,
|
|
501
|
+
) ?? null)
|
|
455
502
|
const names = nameOf(item)
|
|
456
503
|
// A renamed file is a new key: say so where a page of that name is already here.
|
|
457
504
|
if (item.kind === 'content') {
|
package/src/seed/export.ts
CHANGED
|
@@ -22,7 +22,14 @@ import {
|
|
|
22
22
|
} from '@crombolo/data'
|
|
23
23
|
import type { MediaFileStore } from '../media-files.ts'
|
|
24
24
|
import { seedKey } from './keys.ts'
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
CONTENT_FILES_DIR,
|
|
27
|
+
KIND_DIRS,
|
|
28
|
+
kindDir,
|
|
29
|
+
LIBRARY_FOLDER_FILE,
|
|
30
|
+
nameFromSegment,
|
|
31
|
+
type SeedKind,
|
|
32
|
+
} from './read.ts'
|
|
26
33
|
import { schemaLookup, shorthandReader } from './values.ts'
|
|
27
34
|
|
|
28
35
|
/** A URL segment from a name: `About us` → `about-us`. */
|
|
@@ -150,10 +157,31 @@ export async function exportSeed(
|
|
|
150
157
|
}
|
|
151
158
|
for (const [index, root] of options.pages.entries()) await walkPages(root, null, index)
|
|
152
159
|
|
|
160
|
+
/** Library folders, which are directories rather than files (story 242). */
|
|
161
|
+
const libraryFolders = new Set<string>()
|
|
153
162
|
if (options.library) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
163
|
+
const walkLibrary = async (parentId: number, parent: string | null) => {
|
|
164
|
+
const folders = await nodes.children(
|
|
165
|
+
parentId,
|
|
166
|
+
ObjectTypes.ElementContainer,
|
|
167
|
+
0,
|
|
168
|
+
Number.MAX_SAFE_INTEGER,
|
|
169
|
+
)
|
|
170
|
+
for (const [index, folder] of folders.items.entries()) {
|
|
171
|
+
libraryFolders.add(folder.key)
|
|
172
|
+
const path = place('library', folder, parent, index, segmentOf(folder.text ?? folder.key))
|
|
173
|
+
await walkLibrary(folder.id, path)
|
|
174
|
+
}
|
|
175
|
+
const elements = await nodes.children(
|
|
176
|
+
parentId,
|
|
177
|
+
ObjectTypes.Element,
|
|
178
|
+
0,
|
|
179
|
+
Number.MAX_SAFE_INTEGER,
|
|
180
|
+
)
|
|
181
|
+
for (const [index, element] of elements.items.entries())
|
|
182
|
+
place('library', element, parent, index, segmentOf(element.text ?? element.key))
|
|
183
|
+
}
|
|
184
|
+
await walkLibrary(-1, null)
|
|
157
185
|
}
|
|
158
186
|
|
|
159
187
|
const mediaFile = new Map<string, string>()
|
|
@@ -237,8 +265,19 @@ export async function exportSeed(
|
|
|
237
265
|
}
|
|
238
266
|
|
|
239
267
|
for (const { kind, node, path, order } of entries) {
|
|
240
|
-
const doc = await repos[kind].byKey(node.key)
|
|
241
268
|
const derived = seedKey(`${kind}/${path}`)
|
|
269
|
+
if (kind === 'library' && libraryFolders.has(node.key)) {
|
|
270
|
+
// A folder is its directory; `.folder.toml` only for what the directory can't say.
|
|
271
|
+
mkdirSync(under(`library/${path}`), { recursive: true })
|
|
272
|
+
const own: string[] = []
|
|
273
|
+
if (normaliseUuid(node.key) !== derived) own.push(`key = ${JSON.stringify(node.key)}`)
|
|
274
|
+
const segment = path.split('/').at(-1) as string
|
|
275
|
+
if ((node.text ?? '') !== nameFromSegment(segment))
|
|
276
|
+
own.push(`name = ${JSON.stringify(node.text ?? '')}`)
|
|
277
|
+
if (own.length > 0) write(`library/${path}/${LIBRARY_FOLDER_FILE}`, `${own.join('\n')}\n`)
|
|
278
|
+
continue
|
|
279
|
+
}
|
|
280
|
+
const doc = await repos[kind].byKey(node.key)
|
|
242
281
|
const lines: string[] = []
|
|
243
282
|
if (kind === 'media') {
|
|
244
283
|
const src = mediaFile.get(node.key)
|
package/src/seed/read.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface SeedItem {
|
|
|
40
40
|
data: Record<string, unknown>
|
|
41
41
|
/** A media file's bytes. */
|
|
42
42
|
bytes?: Uint8Array
|
|
43
|
-
/** A
|
|
43
|
+
/** A folder: a directory under `content/media/` or `content/library/`. */
|
|
44
44
|
folder?: boolean
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -58,6 +58,9 @@ export interface SeedTree {
|
|
|
58
58
|
|
|
59
59
|
const SKIPPED = (name: string) => name.startsWith('.')
|
|
60
60
|
|
|
61
|
+
/** What keeps a Library folder's key, when it isn't the one its path gives. */
|
|
62
|
+
export const LIBRARY_FOLDER_FILE = '.folder.toml'
|
|
63
|
+
|
|
61
64
|
/**
|
|
62
65
|
* The line a TOML syntax error is on: the first prefix of the file that does
|
|
63
66
|
* not parse. The parser's own position is not always the file's.
|
|
@@ -118,12 +121,20 @@ export function readSeed(siteDir: string): SeedTree {
|
|
|
118
121
|
const path = join(dir, name)
|
|
119
122
|
if (statSync(path).isDirectory()) {
|
|
120
123
|
if (kind === 'library') {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
// A Library folder (story 242). `.folder.toml` in it keeps a key of its own.
|
|
125
|
+
const itemPath = parent ? `${parent}/${name}` : name
|
|
126
|
+
const own = join(path, LIBRARY_FOLDER_FILE)
|
|
127
|
+
const parsed = existsSync(own) ? parse(own) : undefined
|
|
128
|
+
items.push({
|
|
129
|
+
kind,
|
|
130
|
+
path: itemPath,
|
|
131
|
+
parent,
|
|
132
|
+
file: parsed ? shown(own) : null,
|
|
133
|
+
text: parsed?.text ?? '',
|
|
134
|
+
data: parsed?.data ?? {},
|
|
135
|
+
folder: true,
|
|
126
136
|
})
|
|
137
|
+
content(kind, path, itemPath)
|
|
127
138
|
continue
|
|
128
139
|
}
|
|
129
140
|
if (!names.includes(`${name}.toml`))
|
|
@@ -216,3 +227,9 @@ export function readSeedDictionary(siteDir: string) {
|
|
|
216
227
|
/** Whether a site has content files at all, where they are or where they were. */
|
|
217
228
|
export const hasSeed = (siteDir: string) =>
|
|
218
229
|
existsSync(join(siteDir, CONTENT_FILES_DIR)) || existsSync(join(siteDir, 'seed'))
|
|
230
|
+
|
|
231
|
+
/** A word for a file name: `about-us` → `About us`. */
|
|
232
|
+
export const nameFromSegment = (segment: string) => {
|
|
233
|
+
const words = segment.replace(/[-_]+/g, ' ').trim()
|
|
234
|
+
return words.charAt(0).toUpperCase() + words.slice(1)
|
|
235
|
+
}
|
package/src/seed/values.ts
CHANGED
|
@@ -82,6 +82,8 @@ export interface ValueRefs {
|
|
|
82
82
|
content(ref: string, why: string): Promise<string | undefined>
|
|
83
83
|
media(ref: string, why: string): Promise<{ key: string; typeAlias: string } | undefined>
|
|
84
84
|
library(ref: string, why: string): Promise<string | undefined>
|
|
85
|
+
/** A form picker's value: a Library form's path, or a form's alias or key (story 242). */
|
|
86
|
+
form(ref: string, why: string): Promise<string | undefined>
|
|
85
87
|
/** A link's path as media, before it is tried as a page. */
|
|
86
88
|
linkedMedia(ref: string): Promise<string | undefined>
|
|
87
89
|
}
|
|
@@ -296,6 +298,16 @@ export function valueWriter(lookup: SchemaLookup, refs: ValueRefs) {
|
|
|
296
298
|
}
|
|
297
299
|
return { ok: true, value: keys }
|
|
298
300
|
}
|
|
301
|
+
case 'Crombolo.FormPicker': {
|
|
302
|
+
if (typeof raw !== 'string')
|
|
303
|
+
return fail("a form picker takes a Library form's path, or a form's alias")
|
|
304
|
+
const key = await refs.form(raw, why)
|
|
305
|
+
if (!key)
|
|
306
|
+
return fail(
|
|
307
|
+
`"${raw}" is not a Library form or a form, in the content files or on the site`,
|
|
308
|
+
)
|
|
309
|
+
return { ok: true, value: key }
|
|
310
|
+
}
|
|
299
311
|
case 'Umbraco.MultiUrlPicker': {
|
|
300
312
|
const links: unknown[] = []
|
|
301
313
|
for (const entry of list(raw)) {
|
|
@@ -404,6 +416,10 @@ export function shorthandReader(
|
|
|
404
416
|
if (paths.length === 0 || paths.some((p) => p === undefined)) return value
|
|
405
417
|
return paths.length === 1 ? paths[0] : paths
|
|
406
418
|
}
|
|
419
|
+
case 'Crombolo.FormPicker': {
|
|
420
|
+
if (typeof value !== 'string') return value
|
|
421
|
+
return (await where(value, 'library')) ?? value
|
|
422
|
+
}
|
|
407
423
|
case 'Umbraco.MultiUrlPicker': {
|
|
408
424
|
if (!Array.isArray(value)) return value
|
|
409
425
|
const out: unknown[] = []
|