@granular-software/sdk 0.4.83 → 0.4.84

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.
@@ -8732,16 +8732,27 @@ function wrap(fn, name, reference, process2, options = {}) {
8732
8732
  validate(options.contract?.args, args);
8733
8733
  phase = "execution";
8734
8734
  const value = fn.apply(this, args);
8735
+ const observeResult = (result) => {
8736
+ let succeeded = true;
8737
+ try {
8738
+ succeeded = (options.succeeded ?? process2?.succeeded)?.(result) ?? true;
8739
+ } catch {
8740
+ }
8741
+ if (succeeded)
8742
+ emit("completed");
8743
+ else
8744
+ emit("failed", "execution");
8745
+ };
8735
8746
  const complete = (result) => {
8736
8747
  phase = "output";
8737
8748
  validate(options.contract?.result, result);
8738
- emit("completed");
8749
+ observeResult(result);
8739
8750
  return result;
8740
8751
  };
8741
8752
  if (value && typeof value.then === "function") {
8742
8753
  if (options.contract?.result)
8743
8754
  return Promise.resolve(value).then(complete).catch(failed);
8744
- void Promise.resolve(value).then(() => emit("completed"), () => emit("failed", "execution"));
8755
+ void Promise.resolve(value).then(observeResult, () => emit("failed", "execution"));
8745
8756
  return value;
8746
8757
  }
8747
8758
  return complete(value);