@rotorsoft/act 1.32.12 → 1.32.14

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.
Files changed (39) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/@types/act.d.ts +1 -40
  3. package/dist/@types/act.d.ts.map +1 -1
  4. package/dist/@types/adapters/in-memory-store.d.ts +8 -0
  5. package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
  6. package/dist/@types/builders/builder-utils.d.ts.map +1 -1
  7. package/dist/@types/builders/event-builder.d.ts +1 -11
  8. package/dist/@types/builders/event-builder.d.ts.map +1 -1
  9. package/dist/@types/builders/projection-builder.d.ts.map +1 -1
  10. package/dist/@types/internal/autoclose-reaction.d.ts +1 -1
  11. package/dist/@types/internal/autoclose-reaction.d.ts.map +1 -1
  12. package/dist/@types/internal/close-cycle.d.ts +0 -8
  13. package/dist/@types/internal/close-cycle.d.ts.map +1 -1
  14. package/dist/@types/internal/config.d.ts +25 -4
  15. package/dist/@types/internal/config.d.ts.map +1 -1
  16. package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
  17. package/dist/@types/internal/index.d.ts +5 -6
  18. package/dist/@types/internal/index.d.ts.map +1 -1
  19. package/dist/@types/internal/sensitive.d.ts +0 -26
  20. package/dist/@types/internal/sensitive.d.ts.map +1 -1
  21. package/dist/@types/internal/walk-streams.d.ts +0 -2
  22. package/dist/@types/internal/walk-streams.d.ts.map +1 -1
  23. package/dist/@types/scoped.d.ts +0 -10
  24. package/dist/@types/scoped.d.ts.map +1 -1
  25. package/dist/{chunk-BI3UNNVA.js → chunk-FVJFR7GH.js} +1 -1
  26. package/dist/{chunk-BI3UNNVA.js.map → chunk-FVJFR7GH.js.map} +1 -1
  27. package/dist/{chunk-UVFP2BQ3.js → chunk-JPPO3LZ3.js} +36 -59
  28. package/dist/chunk-JPPO3LZ3.js.map +1 -0
  29. package/dist/index.cjs +192 -207
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.js +160 -152
  32. package/dist/index.js.map +1 -1
  33. package/dist/test/index.cjs +34 -57
  34. package/dist/test/index.cjs.map +1 -1
  35. package/dist/test/index.js +2 -2
  36. package/dist/types/index.cjs.map +1 -1
  37. package/dist/types/index.js +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-UVFP2BQ3.js.map +0 -1
@@ -749,17 +749,34 @@ var InMemoryStore = class {
749
749
  this._streams = /* @__PURE__ */ new Map();
750
750
  }
751
751
  in_query(query, e) {
752
- if (query.stream) {
753
- if (query.stream_exact) {
754
- if (e.stream !== query.stream) return false;
755
- } else if (!RegExp(query.stream).test(e.stream)) return false;
756
- }
752
+ if (query.stream && !this._stream_matches(query.stream, query, e.stream))
753
+ return false;
757
754
  if (query.names && !query.names.includes(e.name)) return false;
758
755
  if (query.correlation && e.meta?.correlation !== query.correlation)
759
756
  return false;
760
757
  if (e.name === SNAP_EVENT && !query.with_snaps) return false;
758
+ if (query.created_after && e.created <= query.created_after) return false;
759
+ if (query.created_before && e.created >= query.created_before) return false;
761
760
  return true;
762
761
  }
762
+ _stream_matches(pattern, query, stream) {
763
+ return query.stream_exact ? stream === pattern : RegExp(pattern).test(stream);
764
+ }
765
+ /**
766
+ * Index of the latest snapshot of the queried stream, or -1. `with_snaps`
767
+ * on an exact single stream resumes there, so earlier events aren't read.
768
+ * The orchestrator asks only for unbounded current-state loads, so the
769
+ * floor applies whenever asked; an explicit `after` wins over it.
770
+ */
771
+ _snap_floor(query) {
772
+ if (!query?.with_snaps || !query.stream_exact || query.stream === void 0 || query.after !== void 0)
773
+ return -1;
774
+ for (let j = this._events.length - 1; j >= 0; j--) {
775
+ const e = this._events[j];
776
+ if (e.stream === query.stream && e.name === SNAP_EVENT) return j;
777
+ }
778
+ return -1;
779
+ }
763
780
  /**
764
781
  * Query events in the store, optionally filtered by query options.
765
782
  * @param callback - Function to call for each event.
@@ -768,59 +785,19 @@ var InMemoryStore = class {
768
785
  */
769
786
  async query(callback, query) {
770
787
  await sleep();
788
+ const floor = this._snap_floor(query);
789
+ const lo = floor >= 0 ? floor : this._first_index_after(query?.after ?? -1);
790
+ const hi = query?.before !== void 0 ? this._first_index_after(query.before - 1) : this._events.length;
791
+ const with_pii = query?.with_pii !== false;
771
792
  let count = 0;
772
- let floor_index = -1;
773
- if (query?.with_snaps && query.stream_exact && query.stream !== void 0 && query.after === void 0) {
774
- for (let j = this._events.length - 1; j >= 0; j--) {
775
- const e = this._events[j];
776
- if (e.stream === query.stream && e.name === SNAP_EVENT) {
777
- floor_index = j;
778
- break;
779
- }
780
- }
781
- }
782
- if (query?.backward) {
783
- const floor_id = floor_index >= 0 ? this._events[floor_index].id : -1;
784
- let i = (query?.before !== void 0 ? this._first_index_after(query.before - 1) : this._events.length) - 1;
785
- while (i >= 0) {
786
- const e = this._events[i--];
787
- if (query && !this.in_query(query, e)) continue;
788
- if (query?.created_before && e.created >= query.created_before)
789
- continue;
790
- if (query.after !== void 0 && e.id <= query.after) break;
791
- if (floor_id >= 0 && e.id < floor_id) break;
792
- if (query.created_after && e.created <= query.created_after) continue;
793
- await Promise.resolve(
794
- callback(
795
- this._with_pii(
796
- e,
797
- query?.with_pii !== false
798
- )
799
- )
800
- );
801
- count++;
802
- if (query?.limit && count >= query.limit) break;
803
- }
804
- } else {
805
- let i = floor_index >= 0 ? floor_index : this._first_index_after(query?.after ?? -1);
806
- while (i < this._events.length) {
807
- const e = this._events[i++];
808
- if (query && !this.in_query(query, e)) continue;
809
- if (query?.created_after && e.created <= query.created_after) continue;
810
- if (query?.before !== void 0 && e.id >= query.before) break;
811
- if (query?.created_before && e.created >= query.created_before)
812
- continue;
813
- await Promise.resolve(
814
- callback(
815
- this._with_pii(
816
- e,
817
- query?.with_pii !== false
818
- )
819
- )
820
- );
821
- count++;
822
- if (query?.limit && count >= query.limit) break;
823
- }
793
+ for (let k = 0; k < hi - lo; k++) {
794
+ const e = this._events[query?.backward ? hi - 1 - k : lo + k];
795
+ if (query && !this.in_query(query, e)) continue;
796
+ await Promise.resolve(
797
+ callback(this._with_pii(e, with_pii))
798
+ );
799
+ count++;
800
+ if (query?.limit && count >= query.limit) break;
824
801
  }
825
802
  return count;
826
803
  }