@estiva-app/interop 0.103.0 → 0.104.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.103.0",
3
+ "version": "0.104.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
@@ -50,6 +50,7 @@ export {
50
50
  progressOfStages,
51
51
  statusStageOf,
52
52
  stageTagOf,
53
+ stageTagFor,
53
54
  type Stage,
54
55
  archiveImpact,
55
56
  type Archive,
package/src/projection.ts CHANGED
@@ -2443,6 +2443,29 @@ export function stageTagOf(event: Pick<SignedEvent, 'tags'>, field: string): Sta
2443
2443
  return asStage(event.tags.find((t) => t[0] === 'stage' && t[1] === field)?.[2])
2444
2444
  }
2445
2445
 
2446
+ /**
2447
+ * The tag a change (or a root) that sets `field` to `value` carries last: the
2448
+ * stage of the option the writer offered, `["stage", <field>, <stage>]` (SPEC
2449
+ * §6.2, §7.3). `options` are the ones the writer offered it from — its own
2450
+ * vocabulary, or the layer of §7.4 it read. None when the value is cleared
2451
+ * (`''`), is not among the options, or its option carries no stage of the four:
2452
+ * a writer never guesses what a status means. {@link stageTagOf} reads it back.
2453
+ *
2454
+ * Exported for an app that builds its own changes (Ship, EAC-4); a
2455
+ * manifest-declared action gets it from {@link buildActionEvent}.
2456
+ *
2457
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-companys-statuses-are-its-own-layer-of-a-types-properties.md
2458
+ */
2459
+ export function stageTagFor(
2460
+ field: string,
2461
+ value: string,
2462
+ options: readonly { value: string; stage?: string }[] | undefined,
2463
+ ): ['stage', string, Stage] | undefined {
2464
+ if (value === '') return undefined
2465
+ const stage = asStage(options?.find((option) => option.value === value)?.stage)
2466
+ return stage ? ['stage', field, stage] : undefined
2467
+ }
2468
+
2446
2469
  /**
2447
2470
  * The fields one change sets under `rule`: one per `set` when it carries any
2448
2471
  * (SPEC §6.2, applied at the change's time as that many one-field changes),
@@ -6378,6 +6401,13 @@ function buildCreationEvent(args: {
6378
6401
  // Each person the new root names, once, where the relay indexes them — the
6379
6402
  // property's own tag is not indexed (SPEC §11.8, decided 2026-10-05).
6380
6403
  for (const person of people) tags.push(['p', person])
6404
+ // What each chosen option means, last (§6.2's `stage`, §7.3): a creation
6405
+ // that sets a staged property, such as a status, carries its stage on the root.
6406
+ for (const [name, held] of Object.entries(value)) {
6407
+ const vocabName = properties[name]?.enum
6408
+ const stage = vocabName ? stageTagFor(name, held, args.vocabularies?.[vocabName]) : undefined
6409
+ if (stage) tags.push(stage)
6410
+ }
6381
6411
 
6382
6412
  return {
6383
6413
  pubkey: args.pubkey,
@@ -6781,10 +6811,10 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
6781
6811
  }
6782
6812
  // What the chosen option means, last (§6.2's `stage`): a status says
6783
6813
  // whether it is open, started, done or dropped, whichever app reads it.
6784
- const stage = declared.emits.field && declared.input?.enum
6785
- ? manifest.vocabularies?.[declared.input.enum]?.find((entry) => entry.value === value)?.stage
6814
+ const stage = declared.emits.field && declared.input?.enum && typeof value === 'string'
6815
+ ? stageTagFor(declared.emits.field, value, manifest.vocabularies?.[declared.input.enum])
6786
6816
  : undefined
6787
- if (declared.emits.field && stage && STAGES.has(stage as Stage)) tags.push(['stage', declared.emits.field, stage])
6817
+ if (stage) tags.push(stage)
6788
6818
 
6789
6819
  return {
6790
6820
  pubkey: args.pubkey,