@usearazzo/runner 1.0.1-alpha.33 → 1.0.1-alpha.34

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +10 -1
  3. package/dist/arazzo-runner.browser.js +1112 -231
  4. package/dist/arazzo-runner.browser.min.js +1 -1
  5. package/package.json +16 -15
  6. package/src/ArazzoRunner.cjs +26 -3
  7. package/src/ArazzoRunner.mjs +26 -3
  8. package/src/client/OpenAPIOperationResponse.cjs +9 -0
  9. package/src/client/OpenAPIOperationResponse.mjs +9 -0
  10. package/src/document/APIDocument.cjs +53 -0
  11. package/src/document/APIDocument.mjs +53 -0
  12. package/src/executor/OpenAPIOperationExecutor.cjs +66 -6
  13. package/src/executor/OpenAPIOperationExecutor.mjs +66 -6
  14. package/src/executor/StepExecutor.cjs +16 -2
  15. package/src/executor/StepExecutor.mjs +16 -2
  16. package/src/executor/StepRetryRunner.cjs +5 -3
  17. package/src/executor/StepRetryRunner.mjs +5 -3
  18. package/src/executor/StepTransitionInterpreter.cjs +1 -1
  19. package/src/executor/StepTransitionInterpreter.mjs +1 -1
  20. package/src/executor/WorkflowCallStack.cjs +1 -1
  21. package/src/executor/WorkflowCallStack.mjs +1 -1
  22. package/src/executor/WorkflowExecutor.cjs +269 -53
  23. package/src/executor/WorkflowExecutor.mjs +269 -53
  24. package/src/index.cjs +7 -0
  25. package/src/index.mjs +2 -0
  26. package/src/observability/ArazzoRunnerEvent.cjs +5 -0
  27. package/src/observability/ArazzoRunnerEvent.mjs +1 -0
  28. package/src/observability/DocumentRegistryEvent.cjs +5 -0
  29. package/src/observability/DocumentRegistryEvent.mjs +1 -0
  30. package/src/observability/EventChannel.cjs +96 -0
  31. package/src/observability/EventChannel.mjs +91 -0
  32. package/src/observability/OpenAPIOperationEvent.cjs +5 -0
  33. package/src/observability/OpenAPIOperationEvent.mjs +1 -0
  34. package/src/observability/Redactor.cjs +213 -0
  35. package/src/observability/Redactor.mjs +208 -0
  36. package/src/observability/WorkflowExecutionEvent.cjs +5 -0
  37. package/src/observability/WorkflowExecutionEvent.mjs +1 -0
  38. package/src/registry/DocumentRegistry.cjs +22 -3
  39. package/src/registry/DocumentRegistry.mjs +22 -3
  40. package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
  41. package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
  42. package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
  43. package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
  44. package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
  45. package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
  46. package/types/runner.d.ts +705 -5
@@ -1,5 +1,6 @@
1
1
  import { toValue } from '@speclynx/apidom-core';
2
2
  import { isPlainObject } from 'ramda-adjunct';
3
+ import ShortUniqueId from 'short-unique-id';
3
4
  import { isArrayElement, isObjectElement, isStringElement } from '@speclynx/apidom-datamodel';
4
5
  import { isFailureActionElement, isParameterElement, isStepElement, isSuccessActionElement } from '@speclynx/apidom-ns-arazzo-1';
5
6
  import RuntimeExpressionEvaluator from "../expression/RuntimeExpressionEvaluator.mjs";
@@ -16,6 +17,7 @@ import StepTransitionInterpreter, { actionTargets } from "./StepTransitionInterp
16
17
  import ExecutionError from "../errors/ExecutionError.mjs";
17
18
  import ResolverError from "../errors/ResolverError.mjs";
18
19
  import { throwIfAborted } from "./abort.mjs";
20
+ import EventChannel from "../observability/EventChannel.mjs";
19
21
  /**
20
22
  * Options for the WorkflowExecutor.
21
23
  * @public
@@ -103,6 +105,14 @@ export function settledResult(result) {
103
105
  * travel together into everything it delegates to.
104
106
  */
105
107
 
108
+ /**
109
+ * What every event of one workflow invocation shares.
110
+ */
111
+
112
+ /**
113
+ * What every step-scoped event of one step shares.
114
+ */
115
+
106
116
  /**
107
117
  * Executes an Arazzo workflow: the stateful loop that turns "run one step" into
108
118
  * "run a workflow".
@@ -148,6 +158,14 @@ class WorkflowExecutor {
148
158
  static #DEFAULT_MAX_STEPS = 1000;
149
159
  static #DEFAULT_MAX_WORKFLOW_DEPTH = 32;
150
160
  static #DEFAULT_NOW = () => performance.now();
161
+ /**
162
+ * Generates each run's `runId`: random rather than counted, so the events
163
+ * of runs in different processes stay apart once collected in one place.
164
+ * It needs no Web Crypto, which browsers offer only on secure pages.
165
+ */
166
+ static #RUN_IDS = new ShortUniqueId({
167
+ length: 12
168
+ });
151
169
  static #EXECUTE_OPTION_KEYS = new Set(['inputs', 'executeOptions', 'dependencyInputs', 'runDependencies', 'signal']);
152
170
  #document;
153
171
  #registry;
@@ -162,6 +180,7 @@ class WorkflowExecutor {
162
180
  #retryRunner;
163
181
  #interpreter = new StepTransitionInterpreter();
164
182
  #workflowLocatorNormalizer;
183
+ #events;
165
184
  constructor(options) {
166
185
  this.#document = options.document;
167
186
  this.#registry = options.registry;
@@ -170,6 +189,10 @@ class WorkflowExecutor {
170
189
  this.#maxSteps = options.maxSteps ?? WorkflowExecutor.#DEFAULT_MAX_STEPS;
171
190
  this.#maxWorkflowDepth = options.maxWorkflowDepth ?? WorkflowExecutor.#DEFAULT_MAX_WORKFLOW_DEPTH;
172
191
  this.#now = options.now ?? WorkflowExecutor.#DEFAULT_NOW;
192
+ this.#events = EventChannel.open({
193
+ observer: options.observer,
194
+ now: this.#now
195
+ });
173
196
  this.#stepExecutor = options.stepExecutor;
174
197
  this.#retryRunner = new StepRetryRunner({
175
198
  sleep: options.sleep
@@ -193,7 +216,9 @@ class WorkflowExecutor {
193
216
  signal
194
217
  } = options;
195
218
  const executeOptions = this.#executeOptionsByName(options.executeOptions ?? {});
219
+ const runId = `run-${WorkflowExecutor.#RUN_IDS.randomUUID()}`;
196
220
  const scope = {
221
+ runId,
197
222
  // the signal is put into every step's opaque bag, because that bag is
198
223
  // how anything reaches the transport: the executor's own checks stop the
199
224
  // run at the next boundary, and this is what cancels the request already
@@ -202,7 +227,9 @@ class WorkflowExecutor {
202
227
  // leave the run walking on.
203
228
  executeOptions: (locator, step) => ({
204
229
  ...this.#executeOptionsFor(executeOptions, locator, step),
205
- signal
230
+ signal,
231
+ // set over any entry's own, like the signal: it names this run.
232
+ runId
206
233
  }),
207
234
  dependencyInputs: options.dependencyInputs ?? {},
208
235
  runDependencies: options.runDependencies ?? true,
@@ -320,7 +347,22 @@ class WorkflowExecutor {
320
347
  workflowId,
321
348
  callStack: nested
322
349
  });
323
- const workflow = await this.#resolveWorkflow(locator, scope);
350
+ const frame = {
351
+ runId: scope.runId,
352
+ workflowId,
353
+ path: nested.path
354
+ };
355
+ // extracted before `workflow-start`: a workflow its document does not
356
+ // define never starts, and the event can say where the one it runs is.
357
+ const extracted = this.#extractWorkflow(locator);
358
+ // emitted before normalization, so its events nest inside this workflow's.
359
+ this.#events?.emit({
360
+ type: 'workflow-start',
361
+ ...frame,
362
+ via,
363
+ location: locator.document.locationOf(extracted)
364
+ }, startedAt);
365
+ const workflow = await this.#resolveWorkflow(locator, extracted, scope, frame);
324
366
  const state = new WorkflowExecutionState({
325
367
  inputs
326
368
  });
@@ -329,7 +371,8 @@ class WorkflowExecutor {
329
371
  document: locator.document,
330
372
  state,
331
373
  callStack: nested,
332
- via
374
+ via,
375
+ frame
333
376
  };
334
377
 
335
378
  // validated before any prerequisite runs: a malformed `steps` is an
@@ -392,7 +435,16 @@ class WorkflowExecutor {
392
435
  // separate from `subWorkflows` because a reference belongs to the retry
393
436
  // that invoked it, not to the step's own target.
394
437
  const retryReferences = [];
395
- const attempt = this.#chargedAttempt(this.#stepAttempt(step, stepId, invocation, scope, subWorkflows), invocation, scope, stepId);
438
+ const stepFrame = {
439
+ ...frame,
440
+ stepId
441
+ };
442
+ this.#events?.emit({
443
+ type: 'step-start',
444
+ ...stepFrame,
445
+ location: invocation.document.locationOf(step)
446
+ }, stepStartedAt);
447
+ const attempt = this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(step, stepId, invocation, scope, subWorkflows), stepFrame), invocation, scope, stepId);
396
448
 
397
449
  // the retry runner settles any `retry` actions, so `action` is the terminal
398
450
  // action a retry chain resolved to and `attempts` is how many times the step
@@ -405,15 +457,51 @@ class WorkflowExecutor {
405
457
  stepId,
406
458
  workflowId,
407
459
  signal: scope.signal,
408
- runReference: this.#retryReference(steps, stepId, invocation, scope, retryReferences)
460
+ runReference: this.#retryReference(steps, stepFrame, invocation, scope, retryReferences),
461
+ onRetry: (retry, delayMs, attempt) => {
462
+ const decided = {
463
+ ...stepFrame,
464
+ attempt
465
+ };
466
+ this.#events?.emit({
467
+ type: 'action-selected',
468
+ ...decided,
469
+ action: retry,
470
+ transition: {
471
+ kind: 'retry'
472
+ },
473
+ location: invocation.document.locationOf(retry)
474
+ });
475
+ if (delayMs > 0) {
476
+ this.#events?.emit({
477
+ type: 'retry-wait',
478
+ ...decided,
479
+ delayMs
480
+ });
481
+ }
482
+ }
483
+ });
484
+ const transition = this.#interpreter.interpret(action, outcome.successful, {
485
+ workflowId,
486
+ stepId
487
+ });
488
+ this.#events?.emit({
489
+ type: 'action-selected',
490
+ ...stepFrame,
491
+ attempt: attempts,
492
+ action,
493
+ transition,
494
+ location: action === undefined ? undefined : invocation.document.locationOf(action)
409
495
  });
410
496
  state.setStepOutputs(outcome.stepId, outcome.outputs);
497
+ const stepSettledAt = this.#now();
411
498
  trace.push({
412
499
  stepId: outcome.stepId,
500
+ location: invocation.document.locationOf(step),
413
501
  successful: outcome.successful,
414
502
  action,
415
503
  attempts,
416
- durationMs: this.#now() - stepStartedAt,
504
+ durationMs: stepSettledAt - stepStartedAt,
417
505
  successCriteria: outcome.successCriteria,
418
506
  actionCriteria: outcome.actionCriteria,
419
507
  ...(subWorkflows.length > 0 ? {
@@ -423,10 +511,12 @@ class WorkflowExecutor {
423
511
  retryReferences
424
512
  } : {})
425
513
  });
426
- const transition = this.#interpreter.interpret(action, outcome.successful, {
427
- workflowId,
428
- stepId
429
- });
514
+ this.#events?.emit({
515
+ type: 'step-settled',
516
+ ...stepFrame,
517
+ successful: outcome.successful,
518
+ attempts
519
+ }, stepSettledAt);
430
520
  switch (transition.kind) {
431
521
  case 'next':
432
522
  index += 1;
@@ -472,7 +562,7 @@ class WorkflowExecutor {
472
562
  break stepLoop;
473
563
  default:
474
564
  {
475
- // exhaustiveness guard: a Transition kind added above without a case
565
+ // exhaustiveness guard: a StepTransition kind added above without a case
476
566
  // here would otherwise fall through silently instead of failing
477
567
  // loudly — `transition` is provably `never` once every kind above
478
568
  // has its own case, which TypeScript checks at compile time.
@@ -516,33 +606,39 @@ class WorkflowExecutor {
516
606
  * the shape up front, independent of resolving it.
517
607
  */
518
608
  async #result(invocation, workflow, steps, outcome, dependencies, startedAt) {
609
+ const settledAt = this.#now();
519
610
  const shared = {
520
611
  workflowId: invocation.workflowId,
521
612
  steps,
522
- durationMs: this.#now() - startedAt,
613
+ durationMs: settledAt - startedAt,
523
614
  ...(dependencies.length > 0 ? {
524
615
  dependencies
525
616
  } : {})
526
617
  };
527
- if (outcome.kind === 'transferred') {
528
- return {
529
- ...shared,
530
- outputs: {},
531
- status: 'transferred',
532
- // computed once, here, rather than left for a caller to chase via
533
- // `settledResult` — `transferredTo` already carries its own
534
- // `settledStatus`, itself computed the same way when it was built,
535
- // so this is O(1) per hop rather than a walk of the whole chain.
536
- settledStatus: outcome.transferredTo.settledStatus,
537
- transferredTo: outcome.transferredTo
538
- };
539
- }
540
- return {
618
+ const result = outcome.kind === 'transferred' ? {
619
+ ...shared,
620
+ outputs: {},
621
+ status: 'transferred',
622
+ // computed once, here, rather than left for a caller to chase via
623
+ // `settledResult` — `transferredTo` already carries its own
624
+ // `settledStatus`, itself computed the same way when it was built,
625
+ // so this is O(1) per hop rather than a walk of the whole chain.
626
+ settledStatus: outcome.transferredTo.settledStatus,
627
+ transferredTo: outcome.transferredTo
628
+ } : {
541
629
  ...shared,
542
630
  outputs: await this.#resolveWorkflowOutputs(workflow, invocation),
543
631
  status: outcome.status,
544
632
  settledStatus: outcome.status
545
633
  };
634
+ this.#events?.emit({
635
+ type: 'workflow-settled',
636
+ ...invocation.frame,
637
+ status: result.status,
638
+ settledStatus: result.settledStatus,
639
+ outputs: result.outputs
640
+ }, settledAt);
641
+ return result;
546
642
  }
547
643
 
548
644
  /**
@@ -590,7 +686,7 @@ class WorkflowExecutor {
590
686
  workflowId,
591
687
  callStack
592
688
  } = invocation;
593
- return async () => {
689
+ return async attempt => {
594
690
  throwIfAborted(scope.signal, {
595
691
  workflowId,
596
692
  stepId,
@@ -598,7 +694,7 @@ class WorkflowExecutor {
598
694
  });
599
695
  this.#chargeBudget(scope, invocation, stepId);
600
696
  try {
601
- return await runAttempt();
697
+ return await runAttempt(attempt);
602
698
  } catch (error) {
603
699
  throwIfAborted(scope.signal, {
604
700
  workflowId,
@@ -610,6 +706,46 @@ class WorkflowExecutor {
610
706
  };
611
707
  }
612
708
 
709
+ /**
710
+ * Wraps a step-attempt thunk with the events of an attempt: `step-attempt`
711
+ * as it begins, then a `criterion-evaluated` for each criterion it
712
+ * evaluated, success criteria first.
713
+ */
714
+ #observedAttempt(runAttempt, stepFrame) {
715
+ const events = this.#events;
716
+ if (events === undefined) return runAttempt;
717
+ return async attempt => {
718
+ const attemptFrame = {
719
+ ...stepFrame,
720
+ attempt
721
+ };
722
+ events.emit({
723
+ type: 'step-attempt',
724
+ ...attemptFrame
725
+ });
726
+ const outcome = await runAttempt();
727
+ for (const criterion of outcome.successCriteria) {
728
+ events.emit({
729
+ type: 'criterion-evaluated',
730
+ ...attemptFrame,
731
+ kind: 'success',
732
+ criterion,
733
+ location: criterion.location
734
+ });
735
+ }
736
+ for (const criterion of outcome.actionCriteria) {
737
+ events.emit({
738
+ type: 'criterion-evaluated',
739
+ ...attemptFrame,
740
+ kind: 'action',
741
+ criterion,
742
+ location: criterion.location
743
+ });
744
+ }
745
+ return outcome;
746
+ };
747
+ }
748
+
613
749
  /**
614
750
  * Builds the {@link StepRetryRunContext.runReference} callback a `retry`
615
751
  * action's `stepId` / `workflowId` reference is run through.
@@ -653,13 +789,16 @@ class WorkflowExecutor {
653
789
  * reference's *completion*, not its success, and a retry that turns out
654
790
  * futile is bounded by `retryLimit` regardless.
655
791
  */
656
- #retryReference(steps, stepId, invocation, scope, retryReferences) {
792
+ #retryReference(steps, stepFrame, invocation, scope, retryReferences) {
657
793
  const {
658
794
  workflowId,
659
795
  state,
660
796
  callStack
661
797
  } = invocation;
662
- return async (action, outcome) => {
798
+ const {
799
+ stepId
800
+ } = stepFrame;
801
+ return async (action, outcome, attempt) => {
663
802
  throwIfAborted(scope.signal, {
664
803
  workflowId,
665
804
  stepId,
@@ -682,6 +821,17 @@ class WorkflowExecutor {
682
821
  // costs no budget unit.
683
822
  const inputs = await this.#actionInputs(action.parameters, outcome, invocation, stepId);
684
823
  this.#chargeBudget(scope, invocation, stepId);
824
+ const referenceFrame = {
825
+ ...stepFrame,
826
+ attempt,
827
+ kind: 'workflow',
828
+ id: reference
829
+ };
830
+ this.#events?.emit({
831
+ type: 'retry-reference-start',
832
+ ...referenceFrame,
833
+ location: invocation.document.locationOf(action)
834
+ });
685
835
  const result = await this.#runReferencedWorkflow(reference, stepId, invocation, scope, 'retry', inputs);
686
836
  // the result's workflowId is the bare id the reference resolved to —
687
837
  // the key run state is recorded under, whichever document owns it.
@@ -690,12 +840,18 @@ class WorkflowExecutor {
690
840
  inputs: action.hasKey('parameters') ? inputs : state.getWorkflow(refId)?.inputs ?? {},
691
841
  outputs: result.outputs
692
842
  });
843
+ const successful = !this.#settledFailed(result);
693
844
  retryReferences.push({
694
845
  kind: 'workflow',
695
846
  id: reference,
696
- successful: !this.#settledFailed(result),
847
+ successful,
697
848
  subWorkflow: result
698
849
  });
850
+ this.#events?.emit({
851
+ type: 'retry-reference-settled',
852
+ ...referenceFrame,
853
+ successful
854
+ });
699
855
  return;
700
856
  }
701
857
  const refStepId = toValue(action.stepId);
@@ -705,7 +861,23 @@ class WorkflowExecutor {
705
861
  });
706
862
  const refStep = steps[refIndex];
707
863
  const refSubWorkflows = [];
708
- const refOutcome = await this.#chargedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), invocation, scope, refStepId)();
864
+ const referenceFrame = {
865
+ ...stepFrame,
866
+ attempt,
867
+ kind: 'step',
868
+ id: refStepId
869
+ };
870
+ this.#events?.emit({
871
+ type: 'retry-reference-start',
872
+ ...referenceFrame,
873
+ location: invocation.document.locationOf(action)
874
+ });
875
+ // the referenced step's attempt is observed like any other, under its
876
+ // own stepId and with a count of its own.
877
+ const refOutcome = await this.#chargedAttempt(this.#observedAttempt(this.#stepAttempt(refStep, refStepId, invocation, scope, refSubWorkflows), {
878
+ ...stepFrame,
879
+ stepId: refStepId
880
+ }), invocation, scope, refStepId)(1);
709
881
  state.setStepOutputs(refOutcome.stepId, refOutcome.outputs);
710
882
  retryReferences.push({
711
883
  kind: 'step',
@@ -715,6 +887,11 @@ class WorkflowExecutor {
715
887
  subWorkflow: refSubWorkflows[0]
716
888
  } : {})
717
889
  });
890
+ this.#events?.emit({
891
+ type: 'retry-reference-settled',
892
+ ...referenceFrame,
893
+ successful: refOutcome.successful
894
+ });
718
895
  };
719
896
  }
720
897
 
@@ -756,9 +933,23 @@ class WorkflowExecutor {
756
933
  // found halfway down the list would otherwise be raised only after earlier
757
934
  // prerequisites had already fired live requests.
758
935
  const dependencyRefs = await this.#dependencyRefs(workflow, invocation);
936
+ const {
937
+ frame
938
+ } = invocation;
759
939
  const results = [];
760
940
  for (const dependency of dependencyRefs) {
761
941
  const qualifiedId = this.#qualifiedId(dependency.locator);
942
+ const target = {
943
+ reference: dependency.inputsKey,
944
+ workflowId: dependency.locator.workflowId,
945
+ documentURI: dependency.locator.document.uri
946
+ };
947
+ this.#events?.emit({
948
+ type: 'dependency-start',
949
+ ...frame,
950
+ dependency: target,
951
+ location: invocation.document.locationOf(dependency.entry)
952
+ });
762
953
  // a dependency already completed in this run is satisfied, not repeated: a
763
954
  // precondition holds once met, and a diamond (two dependents sharing one
764
955
  // dependency) must not duplicate its live side effects. Every dependent
@@ -781,6 +972,13 @@ class WorkflowExecutor {
781
972
  inputs,
782
973
  outputs: result.outputs
783
974
  });
975
+ this.#events?.emit({
976
+ type: 'dependency-settled',
977
+ ...frame,
978
+ dependency: target,
979
+ memoized: memoized !== undefined,
980
+ settledStatus: result.settledStatus
981
+ });
784
982
  if (this.#settledFailed(result)) return results;
785
983
 
786
984
  // only a dependency whose chain settled non-`failed` is remembered as
@@ -822,23 +1020,25 @@ class WorkflowExecutor {
822
1020
  reason: ExecutionError.MalformedDependsOn
823
1021
  });
824
1022
  }
825
- const references = [...dependsOn].map((entry, index) => {
1023
+ const entries = [...dependsOn].map((entry, index) => {
826
1024
  if (!isStringElement(entry)) {
827
1025
  throw new ExecutionError(`workflow "${workflowId}" has a non-string entry at dependsOn[${index}]`, {
828
1026
  workflowId,
829
1027
  reason: ExecutionError.MalformedDependsOn
830
1028
  });
831
1029
  }
832
- return toValue(entry);
1030
+ return entry;
833
1031
  });
834
1032
  const refs = [];
835
- for (const reference of references) {
1033
+ for (const entry of entries) {
1034
+ const reference = toValue(entry);
836
1035
  const locator = await this.#workflowLocatorNormalizer.normalize(reference, document, {
837
1036
  workflowId
838
1037
  });
839
1038
  refs.push({
840
1039
  locator,
841
- inputsKey: reference
1040
+ inputsKey: reference,
1041
+ entry
842
1042
  });
843
1043
  }
844
1044
  return refs;
@@ -1113,30 +1313,46 @@ class WorkflowExecutor {
1113
1313
  }
1114
1314
 
1115
1315
  /**
1116
- * Extracts and normalizes the workflow a locator names. A workflow its
1117
- * document does not define is the executor-level `workflow-not-found`
1118
- * authoring error, raised here rather than leaking the extractor's
1119
- * `ExtractionError`. Only the root {@link WorkflowExecutor.execute} id
1120
- * reaches this check unvalidated — every reference position goes through
1121
- * the locator normalizer, which already rejects a missing workflow with
1122
- * the referencing context attached — so the error's `workflowId` is the
1123
- * missing id itself.
1316
+ * Extracts the workflow a locator names. A workflow its document does not
1317
+ * define is the executor-level `workflow-not-found` authoring error, raised
1318
+ * here rather than leaking the extractor's `ExtractionError`. Only the root
1319
+ * {@link WorkflowExecutor.execute} id reaches this check unvalidated — every
1320
+ * reference position goes through the locator normalizer, which already
1321
+ * rejects a missing workflow with the referencing context attached — so the
1322
+ * error's `workflowId` is the missing id itself.
1124
1323
  */
1125
- async #resolveWorkflow(locator, scope) {
1126
- const {
1127
- document,
1128
- workflowId
1129
- } = locator;
1130
- const qualifiedId = this.#qualifiedId(locator);
1131
- const cached = scope.workflows.get(qualifiedId);
1132
- if (cached !== undefined) return cached;
1324
+ #extractWorkflow({
1325
+ document,
1326
+ workflowId
1327
+ }) {
1133
1328
  if (!document.workflowIndex.has(workflowId)) {
1134
1329
  throw new ExecutionError(`workflow "${workflowId}" not found in Arazzo document at "${document.uri}"`, {
1135
1330
  workflowId,
1136
1331
  reason: ExecutionError.WorkflowNotFound
1137
1332
  });
1138
1333
  }
1139
- const workflow = await this.#normalizer.normalize(this.#extractor.extract(document, workflowId), document);
1334
+ return this.#extractor.extract(document, workflowId);
1335
+ }
1336
+
1337
+ /**
1338
+ * Normalizes an extracted workflow, once per run for each workflow.
1339
+ */
1340
+ async #resolveWorkflow(locator, extracted, scope, frame) {
1341
+ const qualifiedId = this.#qualifiedId(locator);
1342
+ const cached = scope.workflows.get(qualifiedId);
1343
+ if (cached !== undefined) return cached;
1344
+ const location = locator.document.locationOf(extracted);
1345
+ this.#events?.emit({
1346
+ type: 'workflow-normalize-start',
1347
+ ...frame,
1348
+ location
1349
+ });
1350
+ const workflow = await this.#normalizer.normalize(extracted, locator.document);
1351
+ this.#events?.emit({
1352
+ type: 'workflow-normalize-settled',
1353
+ ...frame,
1354
+ location
1355
+ });
1140
1356
  scope.workflows.set(qualifiedId, workflow);
1141
1357
  return workflow;
1142
1358
  }
package/src/index.cjs CHANGED
@@ -281,6 +281,12 @@ Object.defineProperty(exports, "OutputResolver", {
281
281
  return _OutputResolver.default;
282
282
  }
283
283
  });
284
+ Object.defineProperty(exports, "Redactor", {
285
+ enumerable: true,
286
+ get: function () {
287
+ return _Redactor.default;
288
+ }
289
+ });
284
290
  Object.defineProperty(exports, "RegexCriterionEvaluator", {
285
291
  enumerable: true,
286
292
  get: function () {
@@ -425,6 +431,7 @@ var _OpenAPIOperationExecutor = _interopRequireDefault(require("./executor/OpenA
425
431
  var _SourceDescriptionsLocatorNormalizer = _interopRequireDefault(require("./executor/SourceDescriptionsLocatorNormalizer.cjs"));
426
432
  var _OpenAPIOperationLocatorNormalizer = _interopRequireDefault(require("./executor/OpenAPIOperationLocatorNormalizer.cjs"));
427
433
  var _ArazzoWorkflowLocatorNormalizer = _interopRequireDefault(require("./executor/ArazzoWorkflowLocatorNormalizer.cjs"));
434
+ var _Redactor = _interopRequireDefault(require("./observability/Redactor.cjs"));
428
435
  var _ArazzoRunnerError = _interopRequireDefault(require("./errors/ArazzoRunnerError.cjs"));
429
436
  var _AssemblerError = _interopRequireDefault(require("./errors/AssemblerError.cjs"));
430
437
  var _ClientError = _interopRequireDefault(require("./errors/ClientError.cjs"));
package/src/index.mjs CHANGED
@@ -61,6 +61,8 @@ export { default as OpenAPIOperationExecutor } from "./executor/OpenAPIOperation
61
61
  export { default as SourceDescriptionsLocatorNormalizer } from "./executor/SourceDescriptionsLocatorNormalizer.mjs";
62
62
  export { default as OpenAPIOperationLocatorNormalizer } from "./executor/OpenAPIOperationLocatorNormalizer.mjs";
63
63
  export { default as ArazzoWorkflowLocatorNormalizer } from "./executor/ArazzoWorkflowLocatorNormalizer.mjs";
64
+ /* Observability */
65
+ export { default as Redactor } from "./observability/Redactor.mjs";
64
66
  /* Errors */
65
67
  export { default as ArazzoRunnerError } from "./errors/ArazzoRunnerError.mjs";
66
68
  export { default as AssemblerError } from "./errors/AssemblerError.mjs";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ export {};