@crombolo/content 0.78.0 → 0.79.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 +3 -3
- package/src/workspace-merge-run.ts +113 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/content",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The rules every page, media and Library write follows, whoever starts it: who may, where it may go, approvals, and what it announces. No transport.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@crombolo/core": "0.
|
|
33
|
-
"@crombolo/data": "0.
|
|
32
|
+
"@crombolo/core": "0.79.1",
|
|
33
|
+
"@crombolo/data": "0.79.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
Locks,
|
|
17
17
|
type ScheduleEntryAt,
|
|
18
18
|
SystemNodes,
|
|
19
|
+
siblingsPath,
|
|
19
20
|
TransferRunRepository,
|
|
20
21
|
type Workspace,
|
|
21
22
|
WorkspaceRepository,
|
|
@@ -58,7 +59,10 @@ export interface WorkspaceMergeOptions {
|
|
|
58
59
|
* exported before it merged is known as the same change.
|
|
59
60
|
*/
|
|
60
61
|
changeKey?: string
|
|
61
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The changes from other sites this merge applies, recorded so each is applied once
|
|
64
|
+
* (story 383). The schedules each one staged are set with it (story 423).
|
|
65
|
+
*/
|
|
62
66
|
appliedChanges?: ReadonlyArray<{ key: string; name: string | null }>
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -93,6 +97,8 @@ export type WorkspaceMergeOutcome =
|
|
|
93
97
|
name: string
|
|
94
98
|
action: 'publish' | 'unpublish'
|
|
95
99
|
cultures: string[] | null
|
|
100
|
+
/** Story 423: the times it is to be published or taken down at, once approved. */
|
|
101
|
+
schedule?: ScheduleEntryAt[]
|
|
96
102
|
}>
|
|
97
103
|
done: Array<{ key: string | null; name: string; kind: string }>
|
|
98
104
|
rehearsed: boolean
|
|
@@ -434,6 +440,74 @@ export async function runWorkspaceMerge(
|
|
|
434
440
|
const done: Done['done'] = []
|
|
435
441
|
const pages: PageChange[] = []
|
|
436
442
|
const items: ChangeItemInput[] = []
|
|
443
|
+
const applying = new Set((options.appliedChanges ?? []).map((c) => c.key))
|
|
444
|
+
/**
|
|
445
|
+
* A page's schedule set in Shared and held by the merge's change. Story 423: one a
|
|
446
|
+
* workflow covers is not set: its times go with the approval its publish waits for.
|
|
447
|
+
*/
|
|
448
|
+
const schedule = async (
|
|
449
|
+
repo: DocumentRepository,
|
|
450
|
+
page: { key: string; name: string; kind: ContentKind; entries: ScheduleEntryAt[] },
|
|
451
|
+
): Promise<boolean> => {
|
|
452
|
+
if (!merged.some((m) => m.key === page.key))
|
|
453
|
+
merged.push({ key: page.key, name: page.name, published: false, unpublished: false })
|
|
454
|
+
const action = page.entries.some((e) => e.publishTime)
|
|
455
|
+
? 'publish'
|
|
456
|
+
: page.entries.some((e) => e.unpublishTime)
|
|
457
|
+
? 'unpublish'
|
|
458
|
+
: undefined
|
|
459
|
+
const waiting = forApproval.find((f) => f.key === page.key && f.action === 'publish')
|
|
460
|
+
if (action && waiting) {
|
|
461
|
+
waiting.schedule = page.entries
|
|
462
|
+
return false
|
|
463
|
+
}
|
|
464
|
+
if (action && (await options.publishRefusal?.(page.key, action))) {
|
|
465
|
+
forApproval.push({
|
|
466
|
+
key: page.key,
|
|
467
|
+
name: page.name,
|
|
468
|
+
action,
|
|
469
|
+
cultures: page.entries.some((e) => e.culture === null)
|
|
470
|
+
? null
|
|
471
|
+
: page.entries.flatMap((e) => (e.culture === null ? [] : [e.culture])),
|
|
472
|
+
schedule: page.entries,
|
|
473
|
+
})
|
|
474
|
+
return false
|
|
475
|
+
}
|
|
476
|
+
const had = await repo.scheduleEntries(page.key)
|
|
477
|
+
await repo.setSchedule(page.key, [
|
|
478
|
+
...had
|
|
479
|
+
.filter((h) => !page.entries.some((e) => e.culture === h.culture))
|
|
480
|
+
.map((h) => ({ culture: h.culture, publishTime: null, unpublishTime: null })),
|
|
481
|
+
...page.entries.map((e) => ({
|
|
482
|
+
culture: e.culture,
|
|
483
|
+
publishTime: e.publishTime ? new Date(e.publishTime) : null,
|
|
484
|
+
unpublishTime: e.unpublishTime ? new Date(e.unpublishTime) : null,
|
|
485
|
+
})),
|
|
486
|
+
])
|
|
487
|
+
await record({ type: 'scheduled', key: page.key })
|
|
488
|
+
const path = `schedules/${page.key}`
|
|
489
|
+
const held = items.findIndex((i) => i.path === path)
|
|
490
|
+
if (held >= 0) items.splice(held, 1)
|
|
491
|
+
items.push({
|
|
492
|
+
path,
|
|
493
|
+
kind: 'page',
|
|
494
|
+
class: 'none',
|
|
495
|
+
before: null,
|
|
496
|
+
after: JSON.stringify(page.entries),
|
|
497
|
+
})
|
|
498
|
+
if (!pages.some((p) => p.key === page.key)) {
|
|
499
|
+
const at = await repo.eventMarkers(page.key)
|
|
500
|
+
pages.push({
|
|
501
|
+
key: page.key,
|
|
502
|
+
kind: page.kind,
|
|
503
|
+
action: 'update',
|
|
504
|
+
beforeEventId: at?.head ?? null,
|
|
505
|
+
beforePublishedEventId: at?.published ?? null,
|
|
506
|
+
eventId: at?.head ?? null,
|
|
507
|
+
})
|
|
508
|
+
}
|
|
509
|
+
return true
|
|
510
|
+
}
|
|
437
511
|
for (const [n, workspace] of list.entries()) {
|
|
438
512
|
// Its files first, so its pages are written against the types they need.
|
|
439
513
|
if (files) {
|
|
@@ -453,41 +527,50 @@ export async function runWorkspaceMerge(
|
|
|
453
527
|
pages,
|
|
454
528
|
removed: items,
|
|
455
529
|
})
|
|
456
|
-
// Story
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
530
|
+
// Story 425: each page it made or moved, with its parent's children in order now.
|
|
531
|
+
const placed = [
|
|
532
|
+
...plan.pages
|
|
533
|
+
.filter((p) => p.page.made && p.page.kind === 'document')
|
|
534
|
+
.map((p) => p.page.key),
|
|
535
|
+
...plan.pending.flatMap(({ pending }) =>
|
|
536
|
+
pending.kind === 'move' && pending.key !== null ? [pending.key] : [],
|
|
537
|
+
),
|
|
538
|
+
]
|
|
539
|
+
for (const key of placed) {
|
|
540
|
+
const page = await shared.byKey(key)
|
|
541
|
+
if (!page) continue
|
|
542
|
+
const path = siblingsPath(page.parentKey)
|
|
543
|
+
const held = items.findIndex((i) => i.path === path)
|
|
544
|
+
if (held >= 0) items.splice(held, 1)
|
|
470
545
|
items.push({
|
|
471
|
-
path
|
|
546
|
+
path,
|
|
472
547
|
kind: 'page',
|
|
473
548
|
class: 'none',
|
|
474
549
|
before: null,
|
|
475
|
-
after: JSON.stringify(
|
|
550
|
+
after: JSON.stringify(
|
|
551
|
+
(await shared.children(page.parentKey, 0, 10_000)).items.map((n) =>
|
|
552
|
+
normaliseUuid(n.key),
|
|
553
|
+
),
|
|
554
|
+
),
|
|
476
555
|
})
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
556
|
+
}
|
|
557
|
+
// Story 423: the schedules of the changes staged in it, each naming its change.
|
|
558
|
+
for (const change of workspace.stagedChanges ?? []) {
|
|
559
|
+
if (!applying.has(change.key)) continue
|
|
560
|
+
for (const page of change.schedules ?? []) {
|
|
561
|
+
const repo = shared.ofKind(page.kind as ContentKind)
|
|
562
|
+
const here = await repo.byKey(page.key)
|
|
563
|
+
if (!here) continue
|
|
564
|
+
const name =
|
|
565
|
+
(here.variants.find((v) => v.culture === null) ?? here.variants[0])?.name ??
|
|
566
|
+
page.key
|
|
567
|
+
if (await schedule(repo, { ...page, kind: page.kind as ContentKind, name }))
|
|
568
|
+
await repo.scheduleSetBy(page.key, change.key)
|
|
487
569
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
570
|
+
}
|
|
571
|
+
// Story 414: its schedules set in Shared, and held by its change.
|
|
572
|
+
for (const page of schedules[n] ?? []) {
|
|
573
|
+
if (await schedule(shared, { ...page, kind: 'document' })) scheduled.push(page.key)
|
|
491
574
|
if (options.only !== undefined) await workspaces.dropSchedule(workspace.id, page.nodeId)
|
|
492
575
|
}
|
|
493
576
|
if (options.only === undefined)
|