@crombolo/content 0.80.0 → 0.81.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/content",
3
- "version": "0.80.0",
3
+ "version": "0.81.0",
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.80.0",
33
- "@crombolo/data": "0.80.0"
32
+ "@crombolo/core": "0.81.0",
33
+ "@crombolo/data": "0.81.0"
34
34
  }
35
35
  }
@@ -259,7 +259,8 @@ export type MediaOperations = ReturnType<typeof createMediaOperations>
259
259
  export function createMediaOperations(options: MediaOperationsOptions) {
260
260
  const { db, events } = options
261
261
  const repo = new DocumentRepository(db, { ...options.repository, kind: 'media' })
262
- const nodes = new NodeRepository(db)
262
+ // Story 436: a key the workspace holds its own of answers its own.
263
+ const nodes = new NodeRepository(db, { workspace: options.repository?.workspace })
263
264
  const types = new ContentTypeRepository(db, { kind: 'media' })
264
265
  const nodeId = options.repository?.nodeId
265
266
 
package/src/operations.ts CHANGED
@@ -209,7 +209,8 @@ export function createDocumentOperations(options: DocumentOperationsOptions) {
209
209
  const repo = new DocumentRepository(db, options.repository)
210
210
  /** Set for a workspace's operations (story 375): nothing they write reaches Shared. */
211
211
  const workspace = options.repository?.workspace
212
- const nodes = new NodeRepository(db)
212
+ // Story 436: a key the workspace holds its own of answers its own.
213
+ const nodes = new NodeRepository(db, { workspace })
213
214
  const types = new ContentTypeRepository(db, {
214
215
  kind: repo.kind === 'media' ? 'media' : 'document',
215
216
  })
@@ -160,6 +160,9 @@ async function recordChange(
160
160
  options.only !== undefined
161
161
  ? `${ONLY_NAMES[options.onlyKind ?? 'publish']} "${merged[0]?.name ?? done[0]?.name ?? 'a page'}"`
162
162
  : list.map((w) => w.name).join(', ')
163
+ // Story 436: a change another workspace's merge applied already is held, and not again.
164
+ const held = await changes.held((options.appliedChanges ?? []).map((c) => c.key))
165
+ const isHeld = (key: string) => held.has(normaliseUuid(key))
163
166
  const id = await changes.begin({
164
167
  kind: 'merge',
165
168
  name,
@@ -167,10 +170,11 @@ async function recordChange(
167
170
  appliedBy: options.userKey,
168
171
  workspaceKey: first.key,
169
172
  key:
170
- options.changeKey ??
173
+ (options.changeKey && !isHeld(options.changeKey) ? options.changeKey : undefined) ??
171
174
  (list.length === 1 && options.only === undefined ? first.key : undefined),
172
175
  })
173
- for (const applied of options.appliedChanges ?? []) await changes.applied(applied, id)
176
+ for (const applied of options.appliedChanges ?? [])
177
+ if (!isHeld(applied.key)) await changes.applied(applied, id)
174
178
  for (const item of items) await changes.item(id, item)
175
179
  const runs = new TransferRunRepository(tx)
176
180
  for (const page of pages)
@@ -223,6 +227,12 @@ const KIND_OF: Record<string, (typeof KINDS)[number]> = {
223
227
  [ObjectTypes.WorkspaceDocumentBlueprint]: 'blueprint',
224
228
  }
225
229
 
230
+ const BINS: readonly number[] = [
231
+ SystemNodes.ContentRecycleBin,
232
+ SystemNodes.MediaRecycleBin,
233
+ SystemNodes.ElementRecycleBin,
234
+ ]
235
+
226
236
  async function planFor(
227
237
  shared: DocumentRepository,
228
238
  workspaces: WorkspaceRepository,
@@ -239,7 +249,9 @@ async function planFor(
239
249
  if (!node) continue
240
250
  const kind = KIND_OF[node.objectType ?? ''] ?? 'document'
241
251
  p.objectKind = kind
242
- if (!node.trashed)
252
+ // Story 430: a move recorded while the page stood in the bin takes it out.
253
+ const leaves = p.kind === 'move' && p.baseParentId !== null && BINS.includes(p.baseParentId)
254
+ if (!node.trashed || leaves)
243
255
  where.set(p.nodeId, {
244
256
  parentId: node.parentId,
245
257
  head: await shared.ofKind(kind).sharedHeadEvent(node.id),
@@ -664,6 +676,27 @@ async function apply(
664
676
  removed: ChangeItemInput[]
665
677
  },
666
678
  ): Promise<void> {
679
+ const keyOf = async (id: number | null) =>
680
+ id === null || id === SystemNodes.Root ? null : ((await sharedAll.nodes.byId(id))?.key ?? null)
681
+ // Story 430: out of the recycle bin first, as a page in it cannot be published.
682
+ const outOfBin = new Map<
683
+ number,
684
+ {
685
+ from: { parentKey: string | null; trashed: boolean }
686
+ before: Awaited<ReturnType<DocumentRepository['eventMarkers']>>
687
+ }
688
+ >()
689
+ for (const { pending } of plan.pending) {
690
+ if (pending.kind !== 'move' || pending.key === null) continue
691
+ const shared = sharedAll.ofKind(pending.objectKind ?? 'document')
692
+ const node = await shared.nodes.byId(pending.nodeId)
693
+ if (!node?.trashed) continue
694
+ const from = { parentKey: await keyOf(node.parentId ?? null), trashed: true }
695
+ const before = await shared.eventMarkers(pending.key)
696
+ await shared.move(pending.key, await keyOf(pending.targetParentId))
697
+ await record({ type: 'moved', key: pending.key, from })
698
+ outOfBin.set(pending.nodeId, { from, before })
699
+ }
667
700
  for (const pagePlan of plan.pages) {
668
701
  const { page } = pagePlan
669
702
  // Each kind through its own repository: pages, media, Library items (story 390).
@@ -718,8 +751,6 @@ async function apply(
718
751
  })
719
752
  }
720
753
 
721
- const keyOf = async (id: number | null) =>
722
- id === null || id === SystemNodes.Root ? null : ((await sharedAll.nodes.byId(id))?.key ?? null)
723
754
  // Story 411: each parent's children's order before its first reorder, for the change.
724
755
  const orders = new Map<string, { parentKey: string | null; before: string[] }>()
725
756
  const childKeys = async (parentKey: string | null) =>
@@ -728,7 +759,8 @@ async function apply(
728
759
  const key = pending.key
729
760
  if (pending.kind === 'gone' || key === null) continue
730
761
  const shared = sharedAll.ofKind(pending.objectKind ?? 'document')
731
- const before = await shared.eventMarkers(key)
762
+ const left = pending.kind === 'move' ? outOfBin.get(pending.nodeId) : undefined
763
+ const before = left ? left.before : await shared.eventMarkers(key)
732
764
  // A delete takes the page's history with it: its change keeps the page as it stood (story 383).
733
765
  // Story 411: so does one moved to the bin, which the bin may empty before the change is taken.
734
766
  if (pending.kind === 'delete' || pending.kind === 'trash') {
@@ -744,18 +776,24 @@ async function apply(
744
776
  }
745
777
  if (pending.kind === 'move') {
746
778
  const node = await shared.nodes.byId(pending.nodeId)
747
- const from = {
779
+ const from = left?.from ?? {
748
780
  parentKey: await keyOf(node?.parentId ?? null),
749
781
  trashed: node?.trashed ?? false,
750
782
  }
751
783
  const to = await keyOf(pending.targetParentId)
752
- await shared.move(key, to)
753
- await record({ type: 'moved', key, from })
784
+ if (!left) {
785
+ await shared.move(key, to)
786
+ await record({ type: 'moved', key, from })
787
+ }
754
788
  const published = (await shared.byKey(key))?.published ?? false
755
789
  out.removed.push(
756
790
  placeItem(
757
791
  key,
758
- { ...from, published, ...(from.trashed ? { trashed: true } : {}) },
792
+ {
793
+ ...from,
794
+ published: from.trashed ? false : published,
795
+ ...(from.trashed ? { trashed: true } : {}),
796
+ },
759
797
  { parentKey: to, published },
760
798
  ),
761
799
  )
@@ -767,7 +805,8 @@ async function apply(
767
805
  await shared.sort(parentKey, [{ key, sortOrder: pending.sortOrder }])
768
806
  await record({ type: 'sorted', parentKey })
769
807
  } else if (pending.kind === 'trash') {
770
- await shared.moveToRecycleBin(key)
808
+ // One that went with its branch stays in it.
809
+ if (!(await shared.nodes.byId(pending.nodeId))?.trashed) await shared.moveToRecycleBin(key)
771
810
  await record({ type: 'trashed', key })
772
811
  } else if (pending.kind === 'delete') {
773
812
  await shared.delete(key)