@estiva-app/interop 0.102.1 → 0.103.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": "@estiva-app/interop",
3
- "version": "0.102.1",
3
+ "version": "0.103.0",
4
4
  "description": "Render and act on another app's objects from its published NIP-89 manifest. The owner defines the projection; the consumer decides how it looks.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -47,6 +47,9 @@ export {
47
47
  archivedAncestorOf,
48
48
  isClosedStatus,
49
49
  progressOf,
50
+ progressOfStages,
51
+ statusStageOf,
52
+ stageTagOf,
50
53
  type Stage,
51
54
  archiveImpact,
52
55
  type Archive,
package/src/projection.ts CHANGED
@@ -2433,8 +2433,13 @@ function foldChanges(changes: SignedEvent[], rule: RecordsRule, root: SignedEven
2433
2433
  return fields
2434
2434
  }
2435
2435
 
2436
- /** The stage an event (a change or a root) gives `field`: `["stage", <field>, <stage>]`, one of the four. */
2437
- function stageTagOf(event: SignedEvent, field: string): Stage | undefined {
2436
+ /**
2437
+ * The stage an event (a change or a root) gives `field`: `["stage", <field>, <stage>]`,
2438
+ * one of the four (SPEC §6.2). Exported for an app that folds its own changes
2439
+ * (Ship, EAC-3): read it from the event the field's current value came from,
2440
+ * never from an older one, and pass it to {@link statusStageOf}.
2441
+ */
2442
+ export function stageTagOf(event: Pick<SignedEvent, 'tags'>, field: string): Stage | undefined {
2438
2443
  return asStage(event.tags.find((t) => t[0] === 'stage' && t[1] === field)?.[2])
2439
2444
  }
2440
2445
 
@@ -5703,6 +5708,32 @@ function stageOf(
5703
5708
  return stageByWords(raw, label)
5704
5709
  }
5705
5710
 
5711
+ /**
5712
+ * The stage a project's or an issue's `status` counts by, for an app that folds
5713
+ * its own changes rather than resolving a slot (Ship, the agent; EAC-3). The
5714
+ * same three readings {@link ResolvedSlot.stage} carries: `written`, the stage
5715
+ * on the change or root that set the current value ({@link stageTagOf}); else
5716
+ * the base type's directory stage for the id; else the words. For a kind that
5717
+ * is not a base type no manifest is at hand to say the field is staged, so
5718
+ * `written` is not read and the words decide, as a slot with no staged
5719
+ * vocabulary does.
5720
+ *
5721
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-companys-statuses-are-its-own-layer-of-a-types-properties.md
5722
+ */
5723
+ export function statusStageOf(kind: number, value: string, written?: Stage): Stage | undefined {
5724
+ // No slot spec and no manifest: only a base type's directory makes the field staged.
5725
+ return stageOf(kind, STATUS_SLOT, {} as SlotSpec, {} as Manifest, value, value, asStage(written))
5726
+ }
5727
+
5728
+ /**
5729
+ * Done over every one not dropped, from each one's stage: {@link progressOf}'s
5730
+ * count, for an app that holds stages rather than resolved slots. A stage
5731
+ * `undefined` (an unknown word) is in the total and not done.
5732
+ */
5733
+ export function progressOfStages(stages: readonly (Stage | undefined)[]): { done: number; total: number } {
5734
+ return { done: stages.filter((stage) => stage === 'done').length, total: stages.filter((stage) => stage !== 'dropped').length }
5735
+ }
5736
+
5706
5737
  /** Finished work, done or dropped: `[` puts a closed issue after an open one (PEE-21). */
5707
5738
  const isClosed = (stage: Stage | undefined) => stage === 'done' || stage === 'dropped'
5708
5739
 
@@ -5727,8 +5758,7 @@ export function isClosedStatus(slot: ResolvedSlot | undefined): boolean {
5727
5758
  */
5728
5759
  export function progressOf(children: readonly { slots: { status?: ResolvedSlot } }[]): { done: number; total: number } | undefined {
5729
5760
  if (!children.length || children.some((child) => !child.slots.status)) return undefined
5730
- const stages = children.map((child) => child.slots.status?.stage)
5731
- return { done: stages.filter((stage) => stage === 'done').length, total: stages.filter((stage) => stage !== 'dropped').length }
5761
+ return progressOfStages(children.map((child) => child.slots.status?.stage))
5732
5762
  }
5733
5763
 
5734
5764
  /**