@toolproof-npm/shared 0.1.112 → 0.1.113

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.
@@ -1,5 +1,9 @@
1
1
  import { CONSTANTS } from '@toolproof-npm/shared/constants';
2
2
  import { getNewIdentity } from '@toolproof-npm/shared/server';
3
+ function assertNonEmpty(arr, msg) {
4
+ if (arr.length === 0)
5
+ throw new Error(msg);
6
+ }
3
7
  const mintNewRoleBindingMap = async (existingMap) => {
4
8
  const newMap = {};
5
9
  await Promise.all(Object.keys(existingMap).map(async (resourceRoleRef) => {
@@ -77,11 +81,15 @@ export const createBranchStepFromJobPairs = async (cases) => {
77
81
  when: whenWorkStep
78
82
  };
79
83
  }));
84
+ assertNonEmpty(casesWithWorkSteps, 'createBranchStepFromJobPairs requires at least one case');
85
+ const casesTuple = casesWithWorkSteps;
80
86
  // Assemble the branch step
87
+ const canonicalWhatExecutionRef = casesWithWorkSteps?.[0]?.what?.execution?.identity;
81
88
  return {
82
89
  identity: branchStepIdentity,
83
90
  kind: CONSTANTS.STEPS.branch,
84
- cases: casesWithWorkSteps
91
+ cases: casesTuple,
92
+ canonicalWhatExecutionRef: canonicalWhatExecutionRef ? String(canonicalWhatExecutionRef) : undefined
85
93
  };
86
94
  };
87
95
  // DOC: Helper function to clone a ForStep with new identities for steps and executions, preserving job references and bindings
@@ -184,9 +192,19 @@ export const cloneWhileStep = async (whileStep) => {
184
192
  // Note: We intentionally do NOT clone executions/steps here because BranchStep (Option A) does not repeat cases.
185
193
  export const cloneBranchStep = async (branchStep, casesOverride) => {
186
194
  const newBranchStepIdentity = await getNewIdentity(CONSTANTS.STEPS.branch);
195
+ const cases = casesOverride ?? branchStep.cases;
196
+ const priorCanonical = branchStep.canonicalWhatExecutionRef;
197
+ const canonicalStillExists = priorCanonical
198
+ ? (cases ?? []).some((c) => String(c?.what?.execution?.identity ?? '') === String(priorCanonical))
199
+ : false;
200
+ const fallbackCanonical = (cases ?? [])?.[0]?.what?.execution?.identity;
201
+ const canonicalWhatExecutionRef = canonicalStillExists
202
+ ? priorCanonical
203
+ : (fallbackCanonical ? String(fallbackCanonical) : undefined);
187
204
  return {
188
205
  identity: newBranchStepIdentity,
189
206
  kind: CONSTANTS.STEPS.branch,
190
- cases: casesOverride ?? branchStep.cases,
207
+ cases,
208
+ canonicalWhatExecutionRef,
191
209
  };
192
210
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/shared",
3
- "version": "0.1.112",
3
+ "version": "0.1.113",
4
4
  "description": "Core library utilities for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",
@@ -56,7 +56,7 @@
56
56
  "typescript": "^5.9.3"
57
57
  },
58
58
  "dependencies": {
59
- "@toolproof-npm/schema": "^0.1.75",
59
+ "@toolproof-npm/schema": "^0.1.76",
60
60
  "firebase-admin": "^13.6.0"
61
61
  },
62
62
  "scripts": {