@rotorsoft/act 1.23.2 → 1.23.4

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
@@ -20,7 +20,7 @@ import {
20
20
  sleep,
21
21
  store,
22
22
  validate
23
- } from "./chunk-4HYYZOEH.js";
23
+ } from "./chunk-ZG7IC6N6.js";
24
24
  import {
25
25
  ActorSchema,
26
26
  CausationEventSchema,
@@ -600,7 +600,7 @@ var InMemoryStream = class {
600
600
  * @param error Blocked error message.
601
601
  */
602
602
  block(lease, error) {
603
- if (this._leased_by === lease.by) {
603
+ if (this._leased_by === lease.by && !this._blocked) {
604
604
  this._blocked = true;
605
605
  this._error = error;
606
606
  this._deferred_at = void 0;
@@ -750,7 +750,7 @@ var InMemoryStore = class {
750
750
  if (query?.created_before && e.created >= query.created_before)
751
751
  continue;
752
752
  if (query.after !== void 0 && e.id <= query.after) break;
753
- if (query.created_after && e.created <= query.created_after) break;
753
+ if (query.created_after && e.created <= query.created_after) continue;
754
754
  await Promise.resolve(
755
755
  callback(this._with_pii(e))
756
756
  );
@@ -759,7 +759,7 @@ var InMemoryStore = class {
759
759
  }
760
760
  } else {
761
761
  let i = this._first_index_after(query?.after ?? -1);
762
- if (query?.with_snaps && query.stream_exact && query.stream !== void 0 && query.after === void 0) {
762
+ if (query?.with_snaps && query.stream_exact && query.stream !== void 0 && query.after === void 0 && query.created_before === void 0 && query.created_after === void 0) {
763
763
  for (let j = this._events.length - 1; j >= 0; j--) {
764
764
  const e = this._events[j];
765
765
  if (e.stream === query.stream && e.name === SNAP_EVENT) {
@@ -773,7 +773,8 @@ var InMemoryStore = class {
773
773
  if (query && !this.in_query(query, e)) continue;
774
774
  if (query?.created_after && e.created <= query.created_after) continue;
775
775
  if (query?.before !== void 0 && e.id >= query.before) break;
776
- if (query?.created_before && e.created >= query.created_before) break;
776
+ if (query?.created_before && e.created >= query.created_before)
777
+ continue;
777
778
  await Promise.resolve(
778
779
  callback(this._with_pii(e))
779
780
  );
@@ -1325,17 +1326,28 @@ var InMemoryStore = class {
1325
1326
  const prev_stream_versions = this._stream_versions;
1326
1327
  const prev_max_event_id_by_stream = this._max_event_id_by_stream;
1327
1328
  const prev_max_non_snap_event_id = this._max_non_snap_event_id;
1329
+ const prev_pii = this._pii;
1328
1330
  this._events = [];
1329
1331
  this._next_id = 0;
1330
1332
  this._streams = /* @__PURE__ */ new Map();
1331
1333
  this._stream_versions = /* @__PURE__ */ new Map();
1332
1334
  this._max_event_id_by_stream = /* @__PURE__ */ new Map();
1333
1335
  this._max_non_snap_event_id = -1;
1336
+ this._pii = /* @__PURE__ */ new Map();
1334
1337
  try {
1335
1338
  await driver(async (event) => {
1336
1339
  const id = this._next_id++;
1337
- const committed = { ...event, id };
1340
+ const { pii, ...rest } = event;
1341
+ const committed = { ...rest, id };
1338
1342
  this._events.push(committed);
1343
+ if (pii != null) {
1344
+ let per_stream = this._pii.get(event.stream);
1345
+ if (!per_stream) {
1346
+ per_stream = /* @__PURE__ */ new Map();
1347
+ this._pii.set(event.stream, per_stream);
1348
+ }
1349
+ per_stream.set(id, structuredClone(pii));
1350
+ }
1339
1351
  this._stream_versions.set(event.stream, event.version);
1340
1352
  if (event.name !== SNAP_EVENT) {
1341
1353
  this._max_event_id_by_stream.set(event.stream, id);
@@ -1350,6 +1362,7 @@ var InMemoryStore = class {
1350
1362
  this._stream_versions = prev_stream_versions;
1351
1363
  this._max_event_id_by_stream = prev_max_event_id_by_stream;
1352
1364
  this._max_non_snap_event_id = prev_max_non_snap_event_id;
1365
+ this._pii = prev_pii;
1353
1366
  throw err;
1354
1367
  }
1355
1368
  }