@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.js CHANGED
@@ -546,6 +546,52 @@ var runStoreTck = (options) => {
546
546
  });
547
547
  expect5(limited).toHaveLength(2);
548
548
  });
549
+ it4("with_snaps resumes from the latest snapshot per stream", async () => {
550
+ const s = `q-snap-${uid()}`;
551
+ await store.commit(
552
+ s,
553
+ [inc(1), inc(1)],
554
+ make_meta({ stream: s })
555
+ );
556
+ const [snap] = await store.commit(
557
+ s,
558
+ [{ name: SNAP_EVENT, data: { count: 2 } }],
559
+ make_meta({ stream: s })
560
+ );
561
+ await store.commit(
562
+ s,
563
+ [inc(1), inc(1), inc(1)],
564
+ make_meta({ stream: s })
565
+ );
566
+ const from_snap = await collect(store, {
567
+ stream: s,
568
+ stream_exact: true,
569
+ with_snaps: true
570
+ });
571
+ expect5(from_snap).toHaveLength(4);
572
+ expect5(from_snap[0].name).toBe(SNAP_EVENT);
573
+ const domain = await collect(store, { stream: s, stream_exact: true });
574
+ expect5(domain).toHaveLength(5);
575
+ const after_snap = await collect(store, {
576
+ stream: s,
577
+ stream_exact: true,
578
+ with_snaps: true,
579
+ after: snap.id
580
+ });
581
+ expect5(after_snap).toHaveLength(3);
582
+ const s2 = `q-nosnap-${uid()}`;
583
+ await store.commit(
584
+ s2,
585
+ [inc(1), inc(1)],
586
+ make_meta({ stream: s2 })
587
+ );
588
+ const full = await collect(store, {
589
+ stream: s2,
590
+ stream_exact: true,
591
+ with_snaps: true
592
+ });
593
+ expect5(full).toHaveLength(2);
594
+ });
549
595
  it4("supports backward traversal", async () => {
550
596
  const s = `q-back-${uid()}`;
551
597
  const committed = await store.commit(
@@ -598,13 +644,14 @@ var runStoreTck = (options) => {
598
644
  });
599
645
  it4("created_after/created_before filter by timestamp", async () => {
600
646
  const s = `q-ts-${uid()}`;
601
- const before = new Date(Date.now() - 6e4);
602
- const future = new Date(Date.now() + 6e4);
603
- await store.commit(
647
+ const committed = await store.commit(
604
648
  s,
605
649
  [inc(1)],
606
650
  make_meta({ stream: s })
607
651
  );
652
+ const ts = committed[0].created.getTime();
653
+ const before = new Date(ts - 6e4);
654
+ const future = new Date(ts + 6e4);
608
655
  const in_window = await collect(store, {
609
656
  stream: s,
610
657
  stream_exact: true,
@@ -655,8 +702,12 @@ var runStoreTck = (options) => {
655
702
  });
656
703
  it4("backward traversal honors created_before by skipping newer events", async () => {
657
704
  const s = `q-back-ts-${uid()}`;
658
- await store.commit(s, [inc(1)], make_meta());
659
- const past = new Date(Date.now() - 6e4);
705
+ const committed = await store.commit(
706
+ s,
707
+ [inc(1)],
708
+ make_meta()
709
+ );
710
+ const past = new Date(committed[0].created.getTime() - 6e4);
660
711
  const got = await collect(store, {
661
712
  stream: s,
662
713
  stream_exact: true,
@@ -1857,7 +1908,88 @@ var runStoreTck = (options) => {
1857
1908
  expect5(t.get(s)?.count).toBeUndefined();
1858
1909
  expect5(t.get(s)?.names).toBeUndefined();
1859
1910
  });
1911
+ it4("paginates with limit + after (keyset), ordered by stream name", async () => {
1912
+ const tag = uid();
1913
+ const streams = [
1914
+ `qsp-${tag}-a`,
1915
+ `qsp-${tag}-b`,
1916
+ `qsp-${tag}-c`,
1917
+ `qsp-${tag}-d`
1918
+ ];
1919
+ for (const s of streams) {
1920
+ await store.commit(
1921
+ s,
1922
+ [inc(1)],
1923
+ make_meta({ stream: s })
1924
+ );
1925
+ }
1926
+ const page1 = await store.query_stats(
1927
+ { stream: `qsp-${tag}-.*` },
1928
+ { limit: 2 }
1929
+ );
1930
+ const k1 = [...page1.keys()];
1931
+ expect5(k1).toEqual([`qsp-${tag}-a`, `qsp-${tag}-b`]);
1932
+ const page2 = await store.query_stats(
1933
+ { stream: `qsp-${tag}-.*` },
1934
+ { limit: 2, after: k1.at(-1) }
1935
+ );
1936
+ const k2 = [...page2.keys()];
1937
+ expect5(k2).toEqual([`qsp-${tag}-c`, `qsp-${tag}-d`]);
1938
+ const page3 = await store.query_stats(
1939
+ { stream: `qsp-${tag}-.*` },
1940
+ { limit: 2, after: k2.at(-1) }
1941
+ );
1942
+ expect5(page3.size).toBe(0);
1943
+ const all = await store.query_stats({
1944
+ stream: `qsp-${tag}-.*`
1945
+ });
1946
+ expect5([...all.keys()].sort()).toEqual([...streams].sort());
1947
+ });
1860
1948
  });
1949
+ describe5.skipIf(!caps.source_matches)(
1950
+ "query_streams source_matches (capability)",
1951
+ () => {
1952
+ it4("returns only subscriptions whose source pattern matches a name", async () => {
1953
+ const tag = uid();
1954
+ const subConcreteA = `sm-${tag}-sub-a`;
1955
+ const subConcreteB = `sm-${tag}-sub-b`;
1956
+ const subRegex = `sm-${tag}-sub-regex`;
1957
+ const subNoSource = `sm-${tag}-sub-nosource`;
1958
+ const srcA = `sm-${tag}-order-1`;
1959
+ const srcB = `sm-${tag}-order-2`;
1960
+ const srcRegex = `^sm-${tag}-order-`;
1961
+ await store.subscribe([
1962
+ { stream: subConcreteA, source: srcA },
1963
+ { stream: subConcreteB, source: srcB },
1964
+ { stream: subRegex, source: srcRegex },
1965
+ // No source = no source constraint = matches every name.
1966
+ { stream: subNoSource }
1967
+ ]);
1968
+ const matched = [];
1969
+ await store.query_streams((p) => matched.push(p.stream), {
1970
+ stream: `sm-${tag}-sub-.*`,
1971
+ source_matches: [srcA]
1972
+ });
1973
+ expect5(matched.sort()).toEqual(
1974
+ [subConcreteA, subRegex, subNoSource].sort()
1975
+ );
1976
+ const none = [];
1977
+ await store.query_streams((p) => none.push(p.stream), {
1978
+ stream: `sm-${tag}-sub-.*`,
1979
+ source_matches: [`sm-${tag}-unrelated`]
1980
+ });
1981
+ expect5(none).toEqual([subNoSource]);
1982
+ const both = [];
1983
+ await store.query_streams((p) => both.push(p.stream), {
1984
+ stream: `sm-${tag}-sub-.*`,
1985
+ source_matches: [srcA, srcB]
1986
+ });
1987
+ expect5(both.sort()).toEqual(
1988
+ [subConcreteA, subConcreteB, subRegex, subNoSource].sort()
1989
+ );
1990
+ });
1991
+ }
1992
+ );
1861
1993
  describe5("query_streams anchor contract", () => {
1862
1994
  it4("plain regex without anchors is a substring match", async () => {
1863
1995
  const tag = uid();