@rotorsoft/act-tck 1.15.1 → 1.17.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.cjs CHANGED
@@ -591,6 +591,52 @@ var runStoreTck = (options) => {
591
591
  });
592
592
  (0, import_vitest6.expect)(limited).toHaveLength(2);
593
593
  });
594
+ (0, import_vitest6.it)("with_snaps resumes from the latest snapshot per stream", async () => {
595
+ const s = `q-snap-${uid()}`;
596
+ await store.commit(
597
+ s,
598
+ [inc(1), inc(1)],
599
+ make_meta({ stream: s })
600
+ );
601
+ const [snap] = await store.commit(
602
+ s,
603
+ [{ name: import_act.SNAP_EVENT, data: { count: 2 } }],
604
+ make_meta({ stream: s })
605
+ );
606
+ await store.commit(
607
+ s,
608
+ [inc(1), inc(1), inc(1)],
609
+ make_meta({ stream: s })
610
+ );
611
+ const from_snap = await collect(store, {
612
+ stream: s,
613
+ stream_exact: true,
614
+ with_snaps: true
615
+ });
616
+ (0, import_vitest6.expect)(from_snap).toHaveLength(4);
617
+ (0, import_vitest6.expect)(from_snap[0].name).toBe(import_act.SNAP_EVENT);
618
+ const domain = await collect(store, { stream: s, stream_exact: true });
619
+ (0, import_vitest6.expect)(domain).toHaveLength(5);
620
+ const after_snap = await collect(store, {
621
+ stream: s,
622
+ stream_exact: true,
623
+ with_snaps: true,
624
+ after: snap.id
625
+ });
626
+ (0, import_vitest6.expect)(after_snap).toHaveLength(3);
627
+ const s2 = `q-nosnap-${uid()}`;
628
+ await store.commit(
629
+ s2,
630
+ [inc(1), inc(1)],
631
+ make_meta({ stream: s2 })
632
+ );
633
+ const full = await collect(store, {
634
+ stream: s2,
635
+ stream_exact: true,
636
+ with_snaps: true
637
+ });
638
+ (0, import_vitest6.expect)(full).toHaveLength(2);
639
+ });
594
640
  (0, import_vitest6.it)("supports backward traversal", async () => {
595
641
  const s = `q-back-${uid()}`;
596
642
  const committed = await store.commit(
@@ -643,13 +689,14 @@ var runStoreTck = (options) => {
643
689
  });
644
690
  (0, import_vitest6.it)("created_after/created_before filter by timestamp", async () => {
645
691
  const s = `q-ts-${uid()}`;
646
- const before = new Date(Date.now() - 6e4);
647
- const future = new Date(Date.now() + 6e4);
648
- await store.commit(
692
+ const committed = await store.commit(
649
693
  s,
650
694
  [inc(1)],
651
695
  make_meta({ stream: s })
652
696
  );
697
+ const ts = committed[0].created.getTime();
698
+ const before = new Date(ts - 6e4);
699
+ const future = new Date(ts + 6e4);
653
700
  const in_window = await collect(store, {
654
701
  stream: s,
655
702
  stream_exact: true,
@@ -700,8 +747,12 @@ var runStoreTck = (options) => {
700
747
  });
701
748
  (0, import_vitest6.it)("backward traversal honors created_before by skipping newer events", async () => {
702
749
  const s = `q-back-ts-${uid()}`;
703
- await store.commit(s, [inc(1)], make_meta());
704
- const past = new Date(Date.now() - 6e4);
750
+ const committed = await store.commit(
751
+ s,
752
+ [inc(1)],
753
+ make_meta()
754
+ );
755
+ const past = new Date(committed[0].created.getTime() - 6e4);
705
756
  const got = await collect(store, {
706
757
  stream: s,
707
758
  stream_exact: true,
@@ -1902,7 +1953,88 @@ var runStoreTck = (options) => {
1902
1953
  (0, import_vitest6.expect)(t.get(s)?.count).toBeUndefined();
1903
1954
  (0, import_vitest6.expect)(t.get(s)?.names).toBeUndefined();
1904
1955
  });
1956
+ (0, import_vitest6.it)("paginates with limit + after (keyset), ordered by stream name", async () => {
1957
+ const tag = uid();
1958
+ const streams = [
1959
+ `qsp-${tag}-a`,
1960
+ `qsp-${tag}-b`,
1961
+ `qsp-${tag}-c`,
1962
+ `qsp-${tag}-d`
1963
+ ];
1964
+ for (const s of streams) {
1965
+ await store.commit(
1966
+ s,
1967
+ [inc(1)],
1968
+ make_meta({ stream: s })
1969
+ );
1970
+ }
1971
+ const page1 = await store.query_stats(
1972
+ { stream: `qsp-${tag}-.*` },
1973
+ { limit: 2 }
1974
+ );
1975
+ const k1 = [...page1.keys()];
1976
+ (0, import_vitest6.expect)(k1).toEqual([`qsp-${tag}-a`, `qsp-${tag}-b`]);
1977
+ const page2 = await store.query_stats(
1978
+ { stream: `qsp-${tag}-.*` },
1979
+ { limit: 2, after: k1.at(-1) }
1980
+ );
1981
+ const k2 = [...page2.keys()];
1982
+ (0, import_vitest6.expect)(k2).toEqual([`qsp-${tag}-c`, `qsp-${tag}-d`]);
1983
+ const page3 = await store.query_stats(
1984
+ { stream: `qsp-${tag}-.*` },
1985
+ { limit: 2, after: k2.at(-1) }
1986
+ );
1987
+ (0, import_vitest6.expect)(page3.size).toBe(0);
1988
+ const all = await store.query_stats({
1989
+ stream: `qsp-${tag}-.*`
1990
+ });
1991
+ (0, import_vitest6.expect)([...all.keys()].sort()).toEqual([...streams].sort());
1992
+ });
1905
1993
  });
1994
+ import_vitest6.describe.skipIf(!caps.source_matches)(
1995
+ "query_streams source_matches (capability)",
1996
+ () => {
1997
+ (0, import_vitest6.it)("returns only subscriptions whose source pattern matches a name", async () => {
1998
+ const tag = uid();
1999
+ const subConcreteA = `sm-${tag}-sub-a`;
2000
+ const subConcreteB = `sm-${tag}-sub-b`;
2001
+ const subRegex = `sm-${tag}-sub-regex`;
2002
+ const subNoSource = `sm-${tag}-sub-nosource`;
2003
+ const srcA = `sm-${tag}-order-1`;
2004
+ const srcB = `sm-${tag}-order-2`;
2005
+ const srcRegex = `^sm-${tag}-order-`;
2006
+ await store.subscribe([
2007
+ { stream: subConcreteA, source: srcA },
2008
+ { stream: subConcreteB, source: srcB },
2009
+ { stream: subRegex, source: srcRegex },
2010
+ // No source = no source constraint = matches every name.
2011
+ { stream: subNoSource }
2012
+ ]);
2013
+ const matched = [];
2014
+ await store.query_streams((p) => matched.push(p.stream), {
2015
+ stream: `sm-${tag}-sub-.*`,
2016
+ source_matches: [srcA]
2017
+ });
2018
+ (0, import_vitest6.expect)(matched.sort()).toEqual(
2019
+ [subConcreteA, subRegex, subNoSource].sort()
2020
+ );
2021
+ const none = [];
2022
+ await store.query_streams((p) => none.push(p.stream), {
2023
+ stream: `sm-${tag}-sub-.*`,
2024
+ source_matches: [`sm-${tag}-unrelated`]
2025
+ });
2026
+ (0, import_vitest6.expect)(none).toEqual([subNoSource]);
2027
+ const both = [];
2028
+ await store.query_streams((p) => both.push(p.stream), {
2029
+ stream: `sm-${tag}-sub-.*`,
2030
+ source_matches: [srcA, srcB]
2031
+ });
2032
+ (0, import_vitest6.expect)(both.sort()).toEqual(
2033
+ [subConcreteA, subConcreteB, subRegex, subNoSource].sort()
2034
+ );
2035
+ });
2036
+ }
2037
+ );
1906
2038
  (0, import_vitest6.describe)("query_streams anchor contract", () => {
1907
2039
  (0, import_vitest6.it)("plain regex without anchors is a substring match", async () => {
1908
2040
  const tag = uid();