@rotorsoft/act 1.35.0 → 1.35.1

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.
package/dist/index.js CHANGED
@@ -1648,12 +1648,30 @@ var subscribe = (streams, correlated_at, correlator) => store().subscribe(stream
1648
1648
 
1649
1649
  // src/internal/event-sourcing.ts
1650
1650
  import { patch } from "@rotorsoft/act-patch";
1651
- import { prettifyError } from "zod";
1651
+ import { prettifyError, ZodError } from "zod";
1652
1652
  var bare_patch = (_me, state2, partial) => patch(state2, partial);
1653
- var check_invariants = (target, state2, schema) => {
1654
- const result = schema.safeParse(state2);
1655
- if (!result.success)
1656
- throw new ValidationError(target, state2, prettifyError(result.error));
1653
+ var value_at = (value, path) => path.reduce(
1654
+ (at, key) => at?.[key],
1655
+ value
1656
+ );
1657
+ var check_invariants = (target, state2, schema, pii_aware) => {
1658
+ let result;
1659
+ try {
1660
+ result = schema.safeParse(state2);
1661
+ } catch (error) {
1662
+ throw new ValidationError(target, state2, error);
1663
+ }
1664
+ if (result.success) return;
1665
+ const issues = pii_aware ? result.error.issues.filter((issue) => {
1666
+ const value = value_at(state2, issue.path);
1667
+ return value !== REDACTED && value !== SHREDDED;
1668
+ }) : result.error.issues;
1669
+ if (issues.length)
1670
+ throw new ValidationError(
1671
+ target,
1672
+ state2,
1673
+ prettifyError(new ZodError(issues))
1674
+ );
1657
1675
  };
1658
1676
  var DEFAULT_BATCH = 500;
1659
1677
  var cache_put = (stream, entry) => cache().set(stream, entry).catch(
@@ -1973,7 +1991,12 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1973
1991
  patches++;
1974
1992
  return { state: state2, patch: patch2, patches };
1975
1993
  });
1976
- check_invariants(`${me.name}.${action2}`, state2, me.state);
1994
+ check_invariants(
1995
+ `${me.name}.${action2}`,
1996
+ state2,
1997
+ me.state,
1998
+ me.pii_aware
1999
+ );
1977
2000
  let committed;
1978
2001
  try {
1979
2002
  committed = await store().commit(