@rotorsoft/act 0.14.0 → 0.15.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
@@ -55,12 +55,12 @@ var ZodEmpty = z.record(z.string(), z.never());
55
55
  var ActorSchema = z.object({
56
56
  id: z.string(),
57
57
  name: z.string()
58
- }).readonly();
58
+ }).loose().readonly();
59
59
  var TargetSchema = z.object({
60
60
  stream: z.string(),
61
61
  actor: ActorSchema,
62
62
  expectedVersion: z.number().optional()
63
- }).readonly();
63
+ }).loose().readonly();
64
64
  var CausationEventSchema = z.object({
65
65
  id: z.number(),
66
66
  name: z.string(),
@@ -726,7 +726,7 @@ var Act = class {
726
726
  * 5. Applies events to create new state
727
727
  * 6. Commits events to the store with optimistic concurrency control
728
728
  *
729
- * @template K - Action name from registered actions
729
+ * @template TKey - Action name from registered actions
730
730
  * @param action - The name of the action to execute
731
731
  * @param target - Target specification with stream ID and actor context
732
732
  * @param payload - Action payload matching the action's schema
@@ -1412,7 +1412,18 @@ function act(states = /* @__PURE__ */ new Map(), registry = {
1412
1412
  },
1413
1413
  withProjection: (proj) => {
1414
1414
  mergeProjection(proj, registry.events);
1415
- return act(states, registry, pendingProjections);
1415
+ return act(
1416
+ states,
1417
+ registry,
1418
+ pendingProjections
1419
+ );
1420
+ },
1421
+ withActor: () => {
1422
+ return act(
1423
+ states,
1424
+ registry,
1425
+ pendingProjections
1426
+ );
1416
1427
  },
1417
1428
  on: (event) => ({
1418
1429
  do: (handler, options) => {
@@ -1449,7 +1460,10 @@ function act(states = /* @__PURE__ */ new Map(), registry = {
1449
1460
  for (const proj of pendingProjections) {
1450
1461
  mergeProjection(proj, registry.events);
1451
1462
  }
1452
- return new Act(registry, states);
1463
+ return new Act(
1464
+ registry,
1465
+ states
1466
+ );
1453
1467
  },
1454
1468
  events: registry.events
1455
1469
  };
@@ -1531,7 +1545,12 @@ function slice(states = /* @__PURE__ */ new Map(), actions = {}, events = {}, pr
1531
1545
  },
1532
1546
  withProjection: (proj) => {
1533
1547
  projections.push(proj);
1534
- return slice(states, actions, events, projections);
1548
+ return slice(
1549
+ states,
1550
+ actions,
1551
+ events,
1552
+ projections
1553
+ );
1535
1554
  },
1536
1555
  on: (event) => ({
1537
1556
  do: (handler, options) => {
@@ -1627,7 +1646,10 @@ function action_builder(state2) {
1627
1646
  const schema = entry[action2];
1628
1647
  if (action2 in state2.actions)
1629
1648
  throw new Error(`Duplicate action "${action2}"`);
1630
- const actions = { ...state2.actions, [action2]: schema };
1649
+ const actions = {
1650
+ ...state2.actions,
1651
+ [action2]: schema
1652
+ };
1631
1653
  const on = { ...state2.on };
1632
1654
  const _given = { ...state2.given };
1633
1655
  function given(rules) {
@@ -1651,7 +1673,10 @@ function action_builder(state2) {
1651
1673
  return { given, emit };
1652
1674
  },
1653
1675
  snap(snap2) {
1654
- return action_builder({ ...state2, snap: snap2 });
1676
+ return action_builder({
1677
+ ...state2,
1678
+ snap: snap2
1679
+ });
1655
1680
  },
1656
1681
  build() {
1657
1682
  return state2;