@rotorsoft/act-tck 1.15.0 → 1.16.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
@@ -598,13 +598,14 @@ var runStoreTck = (options) => {
598
598
  });
599
599
  it4("created_after/created_before filter by timestamp", async () => {
600
600
  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(
601
+ const committed = await store.commit(
604
602
  s,
605
603
  [inc(1)],
606
604
  make_meta({ stream: s })
607
605
  );
606
+ const ts = committed[0].created.getTime();
607
+ const before = new Date(ts - 6e4);
608
+ const future = new Date(ts + 6e4);
608
609
  const in_window = await collect(store, {
609
610
  stream: s,
610
611
  stream_exact: true,
@@ -655,8 +656,12 @@ var runStoreTck = (options) => {
655
656
  });
656
657
  it4("backward traversal honors created_before by skipping newer events", async () => {
657
658
  const s = `q-back-ts-${uid()}`;
658
- await store.commit(s, [inc(1)], make_meta());
659
- const past = new Date(Date.now() - 6e4);
659
+ const committed = await store.commit(
660
+ s,
661
+ [inc(1)],
662
+ make_meta()
663
+ );
664
+ const past = new Date(committed[0].created.getTime() - 6e4);
660
665
  const got = await collect(store, {
661
666
  stream: s,
662
667
  stream_exact: true,
@@ -1857,7 +1862,88 @@ var runStoreTck = (options) => {
1857
1862
  expect5(t.get(s)?.count).toBeUndefined();
1858
1863
  expect5(t.get(s)?.names).toBeUndefined();
1859
1864
  });
1865
+ it4("paginates with limit + after (keyset), ordered by stream name", async () => {
1866
+ const tag = uid();
1867
+ const streams = [
1868
+ `qsp-${tag}-a`,
1869
+ `qsp-${tag}-b`,
1870
+ `qsp-${tag}-c`,
1871
+ `qsp-${tag}-d`
1872
+ ];
1873
+ for (const s of streams) {
1874
+ await store.commit(
1875
+ s,
1876
+ [inc(1)],
1877
+ make_meta({ stream: s })
1878
+ );
1879
+ }
1880
+ const page1 = await store.query_stats(
1881
+ { stream: `qsp-${tag}-.*` },
1882
+ { limit: 2 }
1883
+ );
1884
+ const k1 = [...page1.keys()];
1885
+ expect5(k1).toEqual([`qsp-${tag}-a`, `qsp-${tag}-b`]);
1886
+ const page2 = await store.query_stats(
1887
+ { stream: `qsp-${tag}-.*` },
1888
+ { limit: 2, after: k1.at(-1) }
1889
+ );
1890
+ const k2 = [...page2.keys()];
1891
+ expect5(k2).toEqual([`qsp-${tag}-c`, `qsp-${tag}-d`]);
1892
+ const page3 = await store.query_stats(
1893
+ { stream: `qsp-${tag}-.*` },
1894
+ { limit: 2, after: k2.at(-1) }
1895
+ );
1896
+ expect5(page3.size).toBe(0);
1897
+ const all = await store.query_stats({
1898
+ stream: `qsp-${tag}-.*`
1899
+ });
1900
+ expect5([...all.keys()].sort()).toEqual([...streams].sort());
1901
+ });
1860
1902
  });
1903
+ describe5.skipIf(!caps.source_matches)(
1904
+ "query_streams source_matches (capability)",
1905
+ () => {
1906
+ it4("returns only subscriptions whose source pattern matches a name", async () => {
1907
+ const tag = uid();
1908
+ const subConcreteA = `sm-${tag}-sub-a`;
1909
+ const subConcreteB = `sm-${tag}-sub-b`;
1910
+ const subRegex = `sm-${tag}-sub-regex`;
1911
+ const subNoSource = `sm-${tag}-sub-nosource`;
1912
+ const srcA = `sm-${tag}-order-1`;
1913
+ const srcB = `sm-${tag}-order-2`;
1914
+ const srcRegex = `^sm-${tag}-order-`;
1915
+ await store.subscribe([
1916
+ { stream: subConcreteA, source: srcA },
1917
+ { stream: subConcreteB, source: srcB },
1918
+ { stream: subRegex, source: srcRegex },
1919
+ // No source = no source constraint = matches every name.
1920
+ { stream: subNoSource }
1921
+ ]);
1922
+ const matched = [];
1923
+ await store.query_streams((p) => matched.push(p.stream), {
1924
+ stream: `sm-${tag}-sub-.*`,
1925
+ source_matches: [srcA]
1926
+ });
1927
+ expect5(matched.sort()).toEqual(
1928
+ [subConcreteA, subRegex, subNoSource].sort()
1929
+ );
1930
+ const none = [];
1931
+ await store.query_streams((p) => none.push(p.stream), {
1932
+ stream: `sm-${tag}-sub-.*`,
1933
+ source_matches: [`sm-${tag}-unrelated`]
1934
+ });
1935
+ expect5(none).toEqual([subNoSource]);
1936
+ const both = [];
1937
+ await store.query_streams((p) => both.push(p.stream), {
1938
+ stream: `sm-${tag}-sub-.*`,
1939
+ source_matches: [srcA, srcB]
1940
+ });
1941
+ expect5(both.sort()).toEqual(
1942
+ [subConcreteA, subConcreteB, subRegex, subNoSource].sort()
1943
+ );
1944
+ });
1945
+ }
1946
+ );
1861
1947
  describe5("query_streams anchor contract", () => {
1862
1948
  it4("plain regex without anchors is a substring match", async () => {
1863
1949
  const tag = uid();