@crombolo/server 0.45.0 → 0.46.1
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/media.ts +37 -43
- package/src/config.ts +1 -1
- package/src/core.ts +11 -0
- package/src/index.ts +1 -0
- package/src/marketplace.ts +82 -14
- package/src/no-nodes.ts +1 -1
- package/src/node-operations.ts +3 -0
- package/src/owner-jobs.ts +6 -0
- package/src/provenance.ts +43 -15
- package/src/seed/compile.ts +16 -287
- package/src/seed/export.ts +9 -150
- package/src/seed/index.ts +1 -0
- package/src/seed/values.ts +509 -0
- package/src/server.ts +45 -25
- package/src/webhook-edit.ts +70 -0
package/src/seed/compile.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
ComponentRepository,
|
|
19
19
|
ContentTypeRepository,
|
|
20
20
|
currentSchemaState,
|
|
21
|
-
DataTypeRepository,
|
|
22
21
|
type Db,
|
|
23
22
|
LanguageRepository,
|
|
24
23
|
looksLikeKey,
|
|
@@ -39,9 +38,10 @@ import {
|
|
|
39
38
|
} from '@crombolo/transfer'
|
|
40
39
|
import { createMediaPort } from '../adapters/media.ts'
|
|
41
40
|
import { type CromboloConfig, VERSION } from '../config.ts'
|
|
42
|
-
import {
|
|
41
|
+
import { SEED_NAMESPACE, seedKey, uuidV5 } from './keys.ts'
|
|
43
42
|
import { lineOf } from './lines.ts'
|
|
44
43
|
import { kindDir, readSeed, type SeedFinding, type SeedItem } from './read.ts'
|
|
44
|
+
import { schemaLookup, valueWriter } from './values.ts'
|
|
45
45
|
|
|
46
46
|
export interface SeedBuild {
|
|
47
47
|
findings: SeedFinding[]
|
|
@@ -63,11 +63,6 @@ const nameFromSegment = (segment: string) => {
|
|
|
63
63
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
64
64
|
typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date)
|
|
65
65
|
|
|
66
|
-
const BLOCK_LAYOUT = {
|
|
67
|
-
'Umbraco.BlockList': 'Umbraco.BlockList',
|
|
68
|
-
'Umbraco.BlockGrid': 'Umbraco.BlockGrid',
|
|
69
|
-
} as const
|
|
70
|
-
|
|
71
66
|
export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedBuild> {
|
|
72
67
|
const tree = readSeed(config.siteDir)
|
|
73
68
|
const findings: SeedFinding[] = [...tree.findings]
|
|
@@ -77,7 +72,6 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
77
72
|
const state = await currentSchemaState(db)
|
|
78
73
|
const documentTypes = new ContentTypeRepository(db)
|
|
79
74
|
const mediaTypes = new ContentTypeRepository(db, { kind: 'media' })
|
|
80
|
-
const dataTypes = new DataTypeRepository(db)
|
|
81
75
|
const components = new ComponentRepository(db)
|
|
82
76
|
const nodes = new NodeRepository(db)
|
|
83
77
|
const port = createMediaPort(db, {
|
|
@@ -118,31 +112,11 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
118
112
|
const mediaByPath = byPath('media')
|
|
119
113
|
|
|
120
114
|
// ------------------------------------------------------ the site's schema
|
|
121
|
-
const
|
|
122
|
-
const typeOf =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
const editorCache = new Map<string, Map<string, { editor: string; variesByCulture: boolean }>>()
|
|
128
|
-
const editorsOf = async (repo: ContentTypeRepository, type: ContentTypeAggregate) => {
|
|
129
|
-
const cached = editorCache.get(type.key)
|
|
130
|
-
if (cached) return cached
|
|
131
|
-
const properties = await repo.resolveProperties(type.key)
|
|
132
|
-
const editorByType = new Map(
|
|
133
|
-
(await dataTypes.byKeys(properties.map((p) => p.dataTypeKey))).map((d) => [
|
|
134
|
-
d.key,
|
|
135
|
-
d.editorAlias,
|
|
136
|
-
]),
|
|
137
|
-
)
|
|
138
|
-
const out = new Map<string, { editor: string; variesByCulture: boolean }>()
|
|
139
|
-
for (const property of properties) {
|
|
140
|
-
const editor = editorByType.get(property.dataTypeKey)
|
|
141
|
-
if (editor) out.set(property.alias, { editor, variesByCulture: property.variesByCulture })
|
|
142
|
-
}
|
|
143
|
-
editorCache.set(type.key, out)
|
|
144
|
-
return out
|
|
145
|
-
}
|
|
115
|
+
const lookup = schemaLookup(db)
|
|
116
|
+
const typeOf = (repo: ContentTypeRepository, alias: string) =>
|
|
117
|
+
lookup.typeOf(repo === mediaTypes ? 'media' : 'document', alias)
|
|
118
|
+
const editorsOf = (repo: ContentTypeRepository, type: ContentTypeAggregate) =>
|
|
119
|
+
lookup.editorsOf(repo === mediaTypes ? 'media' : 'document', type)
|
|
146
120
|
|
|
147
121
|
/** Content on the site the seed does not declare, by path or key, for a reference to point at. */
|
|
148
122
|
const expected = new Map<string, { key: string; objectType: string; name: string; why: string }>()
|
|
@@ -187,253 +161,15 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
187
161
|
}
|
|
188
162
|
|
|
189
163
|
// ---------------------------------------------------------------- values
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (typeof raw === 'string') html = Bun.markdown.html(raw)
|
|
200
|
-
else if (isRecord(raw) && typeof raw.markdown === 'string')
|
|
201
|
-
html = Bun.markdown.html(raw.markdown)
|
|
202
|
-
else if (isRecord(raw) && 'markup' in raw) return { ok: true, value: raw }
|
|
203
|
-
else return fail('rich text is Markdown, or { html = "…" }')
|
|
204
|
-
const links = [...html.matchAll(/href="(\/[^"#?]*)"/g)]
|
|
205
|
-
for (const [whole, path] of links) {
|
|
206
|
-
const key = await contentKey(path as string, why)
|
|
207
|
-
if (key) html = html.replace(whole, `href="/{localLink:${key}}"`)
|
|
208
|
-
}
|
|
209
|
-
return { ok: true, value: { markup: html, blocks: null } }
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const blocks = async (
|
|
213
|
-
editor: keyof typeof BLOCK_LAYOUT,
|
|
214
|
-
raw: unknown,
|
|
215
|
-
owner: string,
|
|
216
|
-
where: string,
|
|
217
|
-
): Promise<Converted> => {
|
|
218
|
-
if (!Array.isArray(raw)) {
|
|
219
|
-
if (isRecord(raw) && 'layout' in raw) return { ok: true, value: raw }
|
|
220
|
-
return fail('blocks are a list of { type = "<element alias>", values = { … } }')
|
|
221
|
-
}
|
|
222
|
-
const layout: Record<string, unknown>[] = []
|
|
223
|
-
const contentData: unknown[] = []
|
|
224
|
-
const settingsData: unknown[] = []
|
|
225
|
-
for (const [index, entry] of raw.entries()) {
|
|
226
|
-
if (!isRecord(entry) || typeof entry.type !== 'string')
|
|
227
|
-
return fail(`block ${index + 1} has no type`)
|
|
228
|
-
const element = await typeOf(documentTypes, entry.type)
|
|
229
|
-
if (!element?.isElement)
|
|
230
|
-
return fail(`block ${index + 1}: there is no element type "${entry.type}"`)
|
|
231
|
-
const contentKey =
|
|
232
|
-
typeof entry.key === 'string' && looksLikeKey(entry.key)
|
|
233
|
-
? normaliseUuid(entry.key)
|
|
234
|
-
: blockKey(owner, `${where}/${index}`)
|
|
235
|
-
const values = await elementValues(element, entry.values, owner, `${where}/${index}`)
|
|
236
|
-
if (!values.ok) return fail(`block ${index + 1}: ${values.message}`)
|
|
237
|
-
contentData.push({ key: contentKey, contentTypeKey: element.key, values: values.value })
|
|
238
|
-
const item: Record<string, unknown> = { contentKey }
|
|
239
|
-
if (isRecord(entry.settings)) {
|
|
240
|
-
const settingsType =
|
|
241
|
-
typeof entry.settings.type === 'string'
|
|
242
|
-
? await typeOf(documentTypes, entry.settings.type)
|
|
243
|
-
: undefined
|
|
244
|
-
if (!settingsType?.isElement)
|
|
245
|
-
return fail(`block ${index + 1}: settings need a type, an element type`)
|
|
246
|
-
const settingsKey =
|
|
247
|
-
typeof entry.settings.key === 'string' && looksLikeKey(entry.settings.key)
|
|
248
|
-
? normaliseUuid(entry.settings.key)
|
|
249
|
-
: blockKey(owner, `${where}/${index}/settings`)
|
|
250
|
-
const settings = await elementValues(
|
|
251
|
-
settingsType,
|
|
252
|
-
entry.settings.values,
|
|
253
|
-
owner,
|
|
254
|
-
`${where}/${index}/settings`,
|
|
255
|
-
)
|
|
256
|
-
if (!settings.ok) return fail(`block ${index + 1} settings: ${settings.message}`)
|
|
257
|
-
settingsData.push({
|
|
258
|
-
key: settingsKey,
|
|
259
|
-
contentTypeKey: settingsType.key,
|
|
260
|
-
values: settings.value,
|
|
261
|
-
})
|
|
262
|
-
item.settingsKey = settingsKey
|
|
263
|
-
}
|
|
264
|
-
if (editor === 'Umbraco.BlockGrid') {
|
|
265
|
-
item.columnSpan = typeof entry.columns === 'number' ? entry.columns : 12
|
|
266
|
-
item.rowSpan = typeof entry.rows === 'number' ? entry.rows : 1
|
|
267
|
-
item.areas = Array.isArray(entry.areas) ? entry.areas : []
|
|
268
|
-
}
|
|
269
|
-
layout.push(item)
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
ok: true,
|
|
273
|
-
value: { layout: { [BLOCK_LAYOUT[editor]]: layout }, contentData, settingsData },
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const elementValues = async (
|
|
278
|
-
element: ContentTypeAggregate,
|
|
279
|
-
raw: unknown,
|
|
280
|
-
owner: string,
|
|
281
|
-
where: string,
|
|
282
|
-
): Promise<Converted> => {
|
|
283
|
-
if (raw === undefined) return { ok: true, value: [] }
|
|
284
|
-
if (!isRecord(raw)) return fail('values is a table')
|
|
285
|
-
const editors = await editorsOf(documentTypes, element)
|
|
286
|
-
const out: Array<{ alias: string; value: unknown }> = []
|
|
287
|
-
for (const [alias, value] of Object.entries(raw)) {
|
|
288
|
-
const property = editors.get(alias)
|
|
289
|
-
if (!property) return fail(`"${element.alias}" has no property "${alias}"`)
|
|
290
|
-
const converted = await convert(property.editor, value, owner, `${where}/${alias}`)
|
|
291
|
-
if (!converted.ok) return fail(`${alias}: ${converted.message}`)
|
|
292
|
-
out.push({ alias, value: converted.value })
|
|
293
|
-
}
|
|
294
|
-
return { ok: true, value: out }
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const list = (raw: unknown) => (Array.isArray(raw) ? raw : [raw])
|
|
298
|
-
|
|
299
|
-
const convert = async (
|
|
300
|
-
editor: string,
|
|
301
|
-
raw: unknown,
|
|
302
|
-
owner: string,
|
|
303
|
-
where: string,
|
|
304
|
-
): Promise<Converted> => {
|
|
305
|
-
const why = `named by a value in ${where}`
|
|
306
|
-
switch (editor) {
|
|
307
|
-
case 'Umbraco.TextBox':
|
|
308
|
-
case 'Umbraco.TextArea':
|
|
309
|
-
return typeof raw === 'string' || typeof raw === 'number'
|
|
310
|
-
? { ok: true, value: String(raw) }
|
|
311
|
-
: fail('a text value is a string')
|
|
312
|
-
case 'Umbraco.RichText':
|
|
313
|
-
case 'Umbraco.TinyMCE':
|
|
314
|
-
return richText(raw, why)
|
|
315
|
-
case 'Umbraco.TrueFalse':
|
|
316
|
-
return typeof raw === 'boolean'
|
|
317
|
-
? { ok: true, value: raw }
|
|
318
|
-
: fail('a toggle is true or false')
|
|
319
|
-
case 'Umbraco.Integer':
|
|
320
|
-
case 'Umbraco.Decimal':
|
|
321
|
-
case 'Umbraco.Slider':
|
|
322
|
-
return typeof raw === 'number' ? { ok: true, value: raw } : fail('a number is a number')
|
|
323
|
-
case 'Umbraco.DateTime':
|
|
324
|
-
case 'Umbraco.DateTimeWithTimeZone': {
|
|
325
|
-
// Bun's TOML gives a Temporal value (a PlainDate, an Instant) for a TOML
|
|
326
|
-
// date, which writes itself as ISO 8601.
|
|
327
|
-
const text =
|
|
328
|
-
raw instanceof Date
|
|
329
|
-
? raw.toISOString()
|
|
330
|
-
: isTemporalDate(raw)
|
|
331
|
-
? String(raw)
|
|
332
|
-
: typeof raw === 'string'
|
|
333
|
-
? raw
|
|
334
|
-
: undefined
|
|
335
|
-
const at = text === undefined ? Number.NaN : new Date(text).getTime()
|
|
336
|
-
if (text === undefined || Number.isNaN(at))
|
|
337
|
-
return fail('a date is a TOML date or an ISO 8601 string')
|
|
338
|
-
// A date picker stores Umbraco's wall clock, as a save does, so a seed
|
|
339
|
-
// exported and applied again is unchanged; one with a zone keeps ISO.
|
|
340
|
-
return {
|
|
341
|
-
ok: true,
|
|
342
|
-
value:
|
|
343
|
-
editor === 'Umbraco.DateTime'
|
|
344
|
-
? new Date(at).toISOString().slice(0, 19).replace('T', ' ')
|
|
345
|
-
: text,
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
case 'Umbraco.Tags':
|
|
349
|
-
return list(raw).every((tag) => typeof tag === 'string')
|
|
350
|
-
? { ok: true, value: list(raw) }
|
|
351
|
-
: fail('tags are a list of strings')
|
|
352
|
-
case 'Umbraco.ContentPicker': {
|
|
353
|
-
if (typeof raw !== 'string') return fail('a content picker takes a content path')
|
|
354
|
-
const key = await contentKey(raw, why)
|
|
355
|
-
return key
|
|
356
|
-
? { ok: true, value: `umb://document/${key.replaceAll('-', '')}` }
|
|
357
|
-
: fail(`"${raw}" is not a page in the content files or on the site`)
|
|
358
|
-
}
|
|
359
|
-
case 'Umbraco.MediaPicker3': {
|
|
360
|
-
if (isRecord(raw) || (Array.isArray(raw) && raw.some(isRecord)))
|
|
361
|
-
return { ok: true, value: raw }
|
|
362
|
-
const picks: unknown[] = []
|
|
363
|
-
for (const ref of list(raw)) {
|
|
364
|
-
if (typeof ref !== 'string') return fail('a media picker takes media paths')
|
|
365
|
-
const media = await mediaRef(ref, why)
|
|
366
|
-
if (!media) return fail(`"${ref}" is not media in the content files or on the site`)
|
|
367
|
-
picks.push({
|
|
368
|
-
key: pickKey(media.key),
|
|
369
|
-
mediaKey: media.key,
|
|
370
|
-
mediaTypeAlias: media.typeAlias,
|
|
371
|
-
crops: [],
|
|
372
|
-
focalPoint: null,
|
|
373
|
-
})
|
|
374
|
-
}
|
|
375
|
-
return { ok: true, value: picks }
|
|
376
|
-
}
|
|
377
|
-
case 'Umbraco.ElementPicker': {
|
|
378
|
-
const keys: string[] = []
|
|
379
|
-
for (const ref of list(raw)) {
|
|
380
|
-
if (typeof ref !== 'string') return fail('an element picker takes Library paths')
|
|
381
|
-
const key = await libraryKey(ref, why)
|
|
382
|
-
if (!key)
|
|
383
|
-
return fail(`"${ref}" is not a Library element in the content files or on the site`)
|
|
384
|
-
keys.push(key)
|
|
385
|
-
}
|
|
386
|
-
return { ok: true, value: keys }
|
|
387
|
-
}
|
|
388
|
-
case 'Umbraco.MultiUrlPicker': {
|
|
389
|
-
const links: unknown[] = []
|
|
390
|
-
for (const entry of list(raw)) {
|
|
391
|
-
const link = typeof entry === 'string' ? { path: entry } : entry
|
|
392
|
-
if (!isRecord(link))
|
|
393
|
-
return fail('a link is a path, a URL, or { path | url, name, target }')
|
|
394
|
-
// A link as the editor stores it, as `bundle export --source` writes one.
|
|
395
|
-
if ('unique' in link || 'type' in link) {
|
|
396
|
-
links.push(link)
|
|
397
|
-
continue
|
|
398
|
-
}
|
|
399
|
-
const target = typeof link.target === 'string' ? link.target : null
|
|
400
|
-
const url = typeof link.url === 'string' ? link.url : undefined
|
|
401
|
-
const path = typeof link.path === 'string' ? link.path : undefined
|
|
402
|
-
if (path && /^[a-z]+:\/\//i.test(path)) {
|
|
403
|
-
links.push({
|
|
404
|
-
unique: null,
|
|
405
|
-
type: 'external',
|
|
406
|
-
name: link.name ?? path,
|
|
407
|
-
target,
|
|
408
|
-
url: path,
|
|
409
|
-
})
|
|
410
|
-
continue
|
|
411
|
-
}
|
|
412
|
-
if (url) {
|
|
413
|
-
links.push({ unique: null, type: 'external', name: link.name ?? url, target, url })
|
|
414
|
-
continue
|
|
415
|
-
}
|
|
416
|
-
if (!path) return fail('a link needs a path or a url')
|
|
417
|
-
const media = mediaByPath.get(trimPath(path))
|
|
418
|
-
const key = media ? keyOf.get(media) : await contentKey(path, why)
|
|
419
|
-
if (!key)
|
|
420
|
-
return fail(`"${path}" is not a page or media in the content files or on the site`)
|
|
421
|
-
links.push({
|
|
422
|
-
unique: key,
|
|
423
|
-
type: media ? 'media' : 'document',
|
|
424
|
-
name: typeof link.name === 'string' ? link.name : '',
|
|
425
|
-
target,
|
|
426
|
-
})
|
|
427
|
-
}
|
|
428
|
-
return { ok: true, value: links }
|
|
429
|
-
}
|
|
430
|
-
case 'Umbraco.BlockList':
|
|
431
|
-
case 'Umbraco.BlockGrid':
|
|
432
|
-
return blocks(editor, raw, owner, where)
|
|
433
|
-
default:
|
|
434
|
-
return { ok: true, value: raw }
|
|
435
|
-
}
|
|
436
|
-
}
|
|
164
|
+
const { convert } = valueWriter(lookup, {
|
|
165
|
+
content: contentKey,
|
|
166
|
+
media: mediaRef,
|
|
167
|
+
library: libraryKey,
|
|
168
|
+
linkedMedia: async (path) => {
|
|
169
|
+
const media = mediaByPath.get(path.toLowerCase())
|
|
170
|
+
return media ? keyOf.get(media) : undefined
|
|
171
|
+
},
|
|
172
|
+
})
|
|
437
173
|
|
|
438
174
|
// ------------------------------------------------------------- the nodes
|
|
439
175
|
const mediaTypeAlias = new Map<SeedItem, string>()
|
|
@@ -767,10 +503,3 @@ export async function compileSeed(db: Db, config: CromboloConfig): Promise<SeedB
|
|
|
767
503
|
})
|
|
768
504
|
return { findings, set, blobs, files, counts }
|
|
769
505
|
}
|
|
770
|
-
|
|
771
|
-
/** A TOML date as Bun's parser gives it: a Temporal value whose ISO form is a date. */
|
|
772
|
-
function isTemporalDate(raw: unknown): boolean {
|
|
773
|
-
if (typeof raw !== 'object' || raw === null || raw instanceof Date) return false
|
|
774
|
-
const text = String(raw)
|
|
775
|
-
return /^\d{4}-\d{2}-\d{2}/.test(text) && !Number.isNaN(new Date(text).getTime())
|
|
776
|
-
}
|
package/src/seed/export.ts
CHANGED
|
@@ -14,17 +14,16 @@ import { mkdirSync, writeFileSync } from 'node:fs'
|
|
|
14
14
|
import { join, resolve, sep } from 'node:path'
|
|
15
15
|
import { mediaFileOf, normaliseUuid, ObjectTypes } from '@crombolo/core'
|
|
16
16
|
import {
|
|
17
|
-
ContentTypeRepository,
|
|
18
17
|
currentSchemaState,
|
|
19
|
-
DataTypeRepository,
|
|
20
18
|
type Db,
|
|
21
19
|
DocumentRepository,
|
|
22
20
|
NodeRepository,
|
|
23
21
|
type NodeRow,
|
|
24
22
|
} from '@crombolo/data'
|
|
25
23
|
import type { MediaFileStore } from '../media-files.ts'
|
|
26
|
-
import {
|
|
24
|
+
import { seedKey } from './keys.ts'
|
|
27
25
|
import { CONTENT_FILES_DIR, KIND_DIRS, kindDir, type SeedKind } from './read.ts'
|
|
26
|
+
import { schemaLookup, shorthandReader } from './values.ts'
|
|
28
27
|
|
|
29
28
|
/** A URL segment from a name: `About us` → `about-us`. */
|
|
30
29
|
export const segmentOf = (name: string) =>
|
|
@@ -67,10 +66,6 @@ export function tomlValue(value: unknown): string | undefined {
|
|
|
67
66
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
68
67
|
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
69
68
|
|
|
70
|
-
const PICKER = /^umb:\/\/document\/([0-9a-f]{32})$/i
|
|
71
|
-
const dashed = (hex: string) =>
|
|
72
|
-
`${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
|
|
73
|
-
|
|
74
69
|
/** What a media item's own properties are, which its file stands for in a seed. */
|
|
75
70
|
const FILE_PROPERTIES = new Set([
|
|
76
71
|
'umbracoFile',
|
|
@@ -108,9 +103,6 @@ export async function exportSeed(
|
|
|
108
103
|
media: new DocumentRepository(db, { nodeState, kind: 'media' }),
|
|
109
104
|
}
|
|
110
105
|
const nodes = new NodeRepository(db)
|
|
111
|
-
const documentTypes = new ContentTypeRepository(db)
|
|
112
|
-
const mediaTypes = new ContentTypeRepository(db, { kind: 'media' })
|
|
113
|
-
const dataTypes = new DataTypeRepository(db)
|
|
114
106
|
|
|
115
107
|
const typeAliases = new Map<string, string>()
|
|
116
108
|
const aliasOf = async (typeKey: string) => {
|
|
@@ -126,26 +118,13 @@ export async function exportSeed(
|
|
|
126
118
|
}
|
|
127
119
|
return typeAliases.get(key) as string
|
|
128
120
|
}
|
|
129
|
-
const
|
|
130
|
-
const editorsOf = async (typeKey: string, media = false) =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const byType = new Map(
|
|
136
|
-
(await dataTypes.byKeys(properties.map((p) => p.dataTypeKey))).map((d) => [
|
|
137
|
-
d.key,
|
|
138
|
-
d.editorAlias,
|
|
139
|
-
]),
|
|
121
|
+
const lookup = schemaLookup(db)
|
|
122
|
+
const editorsOf = async (typeKey: string, media = false) =>
|
|
123
|
+
new Map(
|
|
124
|
+
[
|
|
125
|
+
...(await lookup.editorsOf(media ? 'media' : 'document', { key: normaliseUuid(typeKey) })),
|
|
126
|
+
].map(([alias, p]) => [alias, p.editor]),
|
|
140
127
|
)
|
|
141
|
-
const out = new Map<string, string>()
|
|
142
|
-
for (const property of properties) {
|
|
143
|
-
const editor = byType.get(property.dataTypeKey)
|
|
144
|
-
if (editor) out.set(property.alias, editor)
|
|
145
|
-
}
|
|
146
|
-
editorCache.set(key, out)
|
|
147
|
-
return out
|
|
148
|
-
}
|
|
149
128
|
|
|
150
129
|
// --------------------------------------------------- every node's place
|
|
151
130
|
type Kind = 'content' | 'library' | 'media'
|
|
@@ -201,127 +180,7 @@ export async function exportSeed(
|
|
|
201
180
|
}
|
|
202
181
|
|
|
203
182
|
// -------------------------------------------------- values, as shorthand
|
|
204
|
-
const shorthand =
|
|
205
|
-
switch (editor) {
|
|
206
|
-
case 'Umbraco.RichText':
|
|
207
|
-
case 'Umbraco.TinyMCE':
|
|
208
|
-
return isRecord(value) && typeof value.markup === 'string' && value.blocks == null
|
|
209
|
-
? { html: value.markup }
|
|
210
|
-
: value
|
|
211
|
-
case 'Umbraco.ContentPicker': {
|
|
212
|
-
const picked = typeof value === 'string' ? PICKER.exec(value) : null
|
|
213
|
-
if (!picked) return value
|
|
214
|
-
const key = dashed((picked[1] as string).toLowerCase())
|
|
215
|
-
const path = where(key, 'content')
|
|
216
|
-
return path ? `/${path}` : key
|
|
217
|
-
}
|
|
218
|
-
case 'Umbraco.MediaPicker3': {
|
|
219
|
-
if (!Array.isArray(value)) return value
|
|
220
|
-
const paths = value.map((pick) =>
|
|
221
|
-
isRecord(pick) &&
|
|
222
|
-
typeof pick.mediaKey === 'string' &&
|
|
223
|
-
pick.key === pickKey(pick.mediaKey) &&
|
|
224
|
-
Array.isArray(pick.crops) &&
|
|
225
|
-
pick.crops.length === 0 &&
|
|
226
|
-
pick.focalPoint == null
|
|
227
|
-
? where(pick.mediaKey, 'media')
|
|
228
|
-
: undefined,
|
|
229
|
-
)
|
|
230
|
-
if (paths.length === 0 || paths.some((p) => p === undefined)) return value
|
|
231
|
-
const full = paths.map((p) => `/${p}`)
|
|
232
|
-
return full.length === 1 ? full[0] : full
|
|
233
|
-
}
|
|
234
|
-
case 'Umbraco.ElementPicker': {
|
|
235
|
-
if (!Array.isArray(value)) return value
|
|
236
|
-
const paths = value.map((key) =>
|
|
237
|
-
typeof key === 'string' ? where(key, 'library') : undefined,
|
|
238
|
-
)
|
|
239
|
-
if (paths.length === 0 || paths.some((p) => p === undefined)) return value
|
|
240
|
-
return paths.length === 1 ? paths[0] : paths
|
|
241
|
-
}
|
|
242
|
-
case 'Umbraco.MultiUrlPicker': {
|
|
243
|
-
if (!Array.isArray(value)) return value
|
|
244
|
-
return value.map((link) => {
|
|
245
|
-
if (!isRecord(link)) return link
|
|
246
|
-
const target = link.target ?? null
|
|
247
|
-
if (
|
|
248
|
-
link.type === 'document' &&
|
|
249
|
-
typeof link.unique === 'string' &&
|
|
250
|
-
target === null &&
|
|
251
|
-
!link.url &&
|
|
252
|
-
!link.queryString
|
|
253
|
-
) {
|
|
254
|
-
const path = where(link.unique, 'content')
|
|
255
|
-
if (path && (link.name === '' || link.name == null)) return `/${path}`
|
|
256
|
-
if (path && typeof link.name === 'string') return { path: `/${path}`, name: link.name }
|
|
257
|
-
}
|
|
258
|
-
if (link.type === 'external' && typeof link.url === 'string' && target === null)
|
|
259
|
-
return { url: link.url, name: link.name ?? link.url }
|
|
260
|
-
return link
|
|
261
|
-
})
|
|
262
|
-
}
|
|
263
|
-
case 'Umbraco.BlockList':
|
|
264
|
-
case 'Umbraco.BlockGrid':
|
|
265
|
-
return blocks(editor, value)
|
|
266
|
-
default:
|
|
267
|
-
return value
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/** Blocks as `{ type, key, values, settings }`, when their layout is plain enough to say so. */
|
|
272
|
-
const blocks = async (editor: string, value: unknown): Promise<unknown> => {
|
|
273
|
-
if (!isRecord(value) || !isRecord(value.layout) || !Array.isArray(value.contentData))
|
|
274
|
-
return value
|
|
275
|
-
const layout = value.layout[editor]
|
|
276
|
-
if (!Array.isArray(layout)) return value
|
|
277
|
-
const content = new Map(
|
|
278
|
-
(value.contentData as unknown[]).filter(isRecord).map((d) => [String(d.key), d]),
|
|
279
|
-
)
|
|
280
|
-
const settings = new Map(
|
|
281
|
-
((value.settingsData as unknown[] | undefined) ?? [])
|
|
282
|
-
.filter(isRecord)
|
|
283
|
-
.map((d) => [String(d.key), d]),
|
|
284
|
-
)
|
|
285
|
-
const out: unknown[] = []
|
|
286
|
-
for (const item of layout) {
|
|
287
|
-
if (!isRecord(item)) return value
|
|
288
|
-
const data = content.get(String(item.contentKey))
|
|
289
|
-
if (!data || typeof data.contentTypeKey !== 'string') return value
|
|
290
|
-
if (editor === 'Umbraco.BlockGrid' && Array.isArray(item.areas) && item.areas.length > 0)
|
|
291
|
-
return value
|
|
292
|
-
const entry: Record<string, unknown> = {
|
|
293
|
-
type: await aliasOf(data.contentTypeKey),
|
|
294
|
-
key: item.contentKey,
|
|
295
|
-
values: await elementValues(data),
|
|
296
|
-
}
|
|
297
|
-
if (typeof item.settingsKey === 'string') {
|
|
298
|
-
const setting = settings.get(item.settingsKey)
|
|
299
|
-
if (!setting || typeof setting.contentTypeKey !== 'string') return value
|
|
300
|
-
entry.settings = {
|
|
301
|
-
type: await aliasOf(setting.contentTypeKey),
|
|
302
|
-
key: item.settingsKey,
|
|
303
|
-
values: await elementValues(setting),
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (editor === 'Umbraco.BlockGrid') {
|
|
307
|
-
entry.columns = item.columnSpan
|
|
308
|
-
entry.rows = item.rowSpan
|
|
309
|
-
}
|
|
310
|
-
out.push(entry)
|
|
311
|
-
}
|
|
312
|
-
return out
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const elementValues = async (data: Record<string, unknown>) => {
|
|
316
|
-
const editors = await editorsOf(String(data.contentTypeKey))
|
|
317
|
-
const out: Record<string, unknown> = {}
|
|
318
|
-
for (const v of (data.values as unknown[] | undefined) ?? []) {
|
|
319
|
-
if (!isRecord(v) || typeof v.alias !== 'string') continue
|
|
320
|
-
const editor = editors.get(v.alias)
|
|
321
|
-
out[v.alias] = editor ? await shorthand(editor, v.value) : v.value
|
|
322
|
-
}
|
|
323
|
-
return out
|
|
324
|
-
}
|
|
183
|
+
const { shorthand } = shorthandReader(lookup, aliasOf, where)
|
|
325
184
|
|
|
326
185
|
// --------------------------------------------------------- the files
|
|
327
186
|
const written: string[] = []
|
package/src/seed/index.ts
CHANGED