@granular-software/sdk 0.4.82 → 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.
@@ -8706,16 +8706,27 @@ function wrap(fn, name, reference, process2, options = {}) {
8706
8706
  validate(options.contract?.args, args);
8707
8707
  phase = "execution";
8708
8708
  const value = fn.apply(this, args);
8709
+ const observeResult = (result) => {
8710
+ let succeeded = true;
8711
+ try {
8712
+ succeeded = (options.succeeded ?? process2?.succeeded)?.(result) ?? true;
8713
+ } catch {
8714
+ }
8715
+ if (succeeded)
8716
+ emit("completed");
8717
+ else
8718
+ emit("failed", "execution");
8719
+ };
8709
8720
  const complete = (result) => {
8710
8721
  phase = "output";
8711
8722
  validate(options.contract?.result, result);
8712
- emit("completed");
8723
+ observeResult(result);
8713
8724
  return result;
8714
8725
  };
8715
8726
  if (value && typeof value.then === "function") {
8716
8727
  if (options.contract?.result)
8717
8728
  return Promise.resolve(value).then(complete).catch(failed);
8718
- void Promise.resolve(value).then(() => emit("completed"), () => emit("failed", "execution"));
8729
+ void Promise.resolve(value).then(observeResult, () => emit("failed", "execution"));
8719
8730
  return value;
8720
8731
  }
8721
8732
  return complete(value);