@onlineapps/cookbook-core 2.1.4 → 2.1.7

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.
@@ -249,48 +249,53 @@ function validateSemantics(cookbook, version) {
249
249
  stepIds.add(stepId);
250
250
  }
251
251
 
252
- // Check nested steps - V2: all nested steps are objects keyed by step_id
253
- if (step.steps && typeof step.steps === 'object') {
254
- Object.entries(step.steps).forEach(([nestedKey, nested]) =>
255
- checkStep(nested, `${path}.steps.${nestedKey}`)
252
+ // Check nested steps
253
+ if (step.steps) {
254
+ step.steps.forEach((nested, idx) =>
255
+ checkStep(nested, `${path}.steps[${idx}]`)
256
256
  );
257
257
  }
258
- if (step.body && typeof step.body === 'object') {
259
- Object.entries(step.body).forEach(([nestedKey, nested]) =>
260
- checkStep(nested, `${path}.body.${nestedKey}`)
258
+ if (step.body) {
259
+ step.body.forEach((nested, idx) =>
260
+ checkStep(nested, `${path}.body[${idx}]`)
261
261
  );
262
262
  }
263
- if (step.branches && typeof step.branches === 'object') {
264
- Object.entries(step.branches).forEach(([branchKey, branch]) => {
265
- checkStep(branch, `${path}.branches.${branchKey}`);
263
+ if (step.branches) {
264
+ step.branches.forEach((branch, idx) => {
265
+ if (branch.steps) {
266
+ branch.steps.forEach((nested, jdx) =>
267
+ checkStep(nested, `${path}.branches[${idx}].steps[${jdx}]`)
268
+ );
269
+ }
266
270
  });
267
271
  }
268
272
  if (step.cases) {
269
273
  Object.keys(step.cases).forEach(caseKey => {
270
274
  const caseVal = step.cases[caseKey];
271
- checkStep(caseVal, `${path}.cases.${caseKey}`);
275
+ if (caseVal.steps) {
276
+ caseVal.steps.forEach((nested, idx) =>
277
+ checkStep(nested, `${path}.cases.${caseKey}.steps[${idx}]`)
278
+ );
279
+ }
272
280
  });
273
281
  }
274
282
  }
275
283
 
276
- // Check all steps - V2: steps is an OBJECT keyed by step_id, NOT an array
284
+ // Check all steps
277
285
  if (cookbook.steps) {
278
- if (Array.isArray(cookbook.steps)) {
279
- throw new CookbookValidationError('V1 FORMAT BANNED! steps must be an object keyed by step_id, not an array');
280
- }
281
- Object.entries(cookbook.steps).forEach(([stepKey, step]) =>
282
- checkStep(step, `steps.${stepKey}`)
286
+ cookbook.steps.forEach((step, idx) =>
287
+ checkStep(step, `steps[${idx}]`)
283
288
  );
284
289
  }
285
290
 
286
291
  // Check dependencies exist
287
292
  if (version === '2.0' && cookbook.steps) {
288
- Object.entries(cookbook.steps).forEach(([stepKey, step]) => {
293
+ cookbook.steps.forEach((step, idx) => {
289
294
  if (step.depends_on) {
290
295
  step.depends_on.forEach(dep => {
291
296
  if (!stepIds.has(dep)) {
292
297
  throw new CookbookValidationError(
293
- `Step '${stepKey}' depends on non-existent step_id '${dep}'`
298
+ `Step ${idx} depends on non-existent step_id '${dep}'`
294
299
  );
295
300
  }
296
301
  });