@rotorsoft/act 0.17.1 → 0.19.0

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
@@ -139,40 +139,6 @@ var config = () => {
139
139
  };
140
140
 
141
141
  // src/utils.ts
142
- var UNMERGEABLES = [
143
- RegExp,
144
- Date,
145
- Array,
146
- Map,
147
- Set,
148
- WeakMap,
149
- WeakSet,
150
- ArrayBuffer,
151
- SharedArrayBuffer,
152
- DataView,
153
- Int8Array,
154
- Uint8Array,
155
- Uint8ClampedArray,
156
- Int16Array,
157
- Uint16Array,
158
- Int32Array,
159
- Uint32Array,
160
- Float32Array,
161
- Float64Array
162
- ];
163
- var is_mergeable = (value) => !!value && typeof value === "object" && !UNMERGEABLES.some((t) => value instanceof t);
164
- var patch = (original, patches) => {
165
- const copy = {};
166
- Object.keys({ ...original, ...patches }).forEach((key) => {
167
- const patched_value = patches[key];
168
- const original_value = original[key];
169
- const patched = patches && key in patches;
170
- const deleted = patched && (typeof patched_value === "undefined" || patched_value === null);
171
- const value = patched && !deleted ? patched_value : original_value;
172
- !deleted && (copy[key] = is_mergeable(value) ? patch(original_value || {}, patched_value || {}) : value);
173
- });
174
- return copy;
175
- };
176
142
  var validate = (target, payload, schema) => {
177
143
  try {
178
144
  return schema ? schema.parse(payload) : payload;
@@ -569,6 +535,7 @@ import { randomUUID as randomUUID2 } from "crypto";
569
535
  import EventEmitter from "events";
570
536
 
571
537
  // src/event-sourcing.ts
538
+ import { patch } from "@rotorsoft/act-patch";
572
539
  import { randomUUID } from "crypto";
573
540
  async function snap(snapshot) {
574
541
  try {
@@ -673,9 +640,10 @@ async function action(me, action2, target, payload, reactingTo, skipValidation =
673
640
  );
674
641
  let { state: state2, patches } = snapshot;
675
642
  const snapshots = committed.map((event) => {
676
- state2 = patch(state2, me.patch[event.name](event, state2));
643
+ const p = me.patch[event.name](event, state2);
644
+ state2 = patch(state2, p);
677
645
  patches++;
678
- return { event, state: state2, patches, snaps: snapshot.snaps };
646
+ return { event, state: state2, patches, snaps: snapshot.snaps, patch: p };
679
647
  });
680
648
  const last = snapshots.at(-1);
681
649
  me.snap && me.snap(last) && void snap(last);
@@ -1752,7 +1720,6 @@ export {
1752
1720
  disposeAndExit,
1753
1721
  extend,
1754
1722
  logger,
1755
- patch,
1756
1723
  port,
1757
1724
  projection,
1758
1725
  sleep,