@rotorsoft/act-tck 1.1.0 → 1.2.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/.tsbuildinfo +1 -1
- package/dist/@types/store-tck.d.ts.map +1 -1
- package/dist/index.cjs +80 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -29
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -189,7 +189,13 @@ var runLoggerTck = (options) => {
|
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
// src/store-tck.ts
|
|
192
|
-
import {
|
|
192
|
+
import {
|
|
193
|
+
act,
|
|
194
|
+
ConcurrencyError,
|
|
195
|
+
InMemoryCache,
|
|
196
|
+
SNAP_EVENT,
|
|
197
|
+
TOMBSTONE_EVENT
|
|
198
|
+
} from "@rotorsoft/act";
|
|
193
199
|
import { afterAll, beforeAll, describe as describe3, expect as expect3, it as it3 } from "vitest";
|
|
194
200
|
var runStoreTck = (options) => {
|
|
195
201
|
describe3(`TCK / Store / ${options.name}`, () => {
|
|
@@ -1509,10 +1515,10 @@ var runStoreTck = (options) => {
|
|
|
1509
1515
|
await store.drop();
|
|
1510
1516
|
await store.seed();
|
|
1511
1517
|
});
|
|
1512
|
-
const asSource = (
|
|
1513
|
-
for (const
|
|
1518
|
+
const asSource = (events) => (async function* () {
|
|
1519
|
+
for (const e of events) yield e;
|
|
1514
1520
|
})();
|
|
1515
|
-
const
|
|
1521
|
+
const event = (originalId, stream, version, name, created, data = {}) => ({
|
|
1516
1522
|
id: originalId,
|
|
1517
1523
|
name,
|
|
1518
1524
|
data,
|
|
@@ -1521,11 +1527,19 @@ var runStoreTck = (options) => {
|
|
|
1521
1527
|
created,
|
|
1522
1528
|
meta: { correlation: "restore-tck", causation: {} }
|
|
1523
1529
|
});
|
|
1530
|
+
const restore = async (source, opts = {}) => {
|
|
1531
|
+
const cache = new InMemoryCache();
|
|
1532
|
+
const app = act().build({ scoped: { store, cache } });
|
|
1533
|
+
try {
|
|
1534
|
+
return await app.restore(source, opts);
|
|
1535
|
+
} finally {
|
|
1536
|
+
await cache.dispose();
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1524
1539
|
it3("returns kept=0 on an empty source", async () => {
|
|
1525
|
-
const result = await
|
|
1540
|
+
const result = await restore(asSource([]));
|
|
1526
1541
|
expect3(result.kept).toBe(0);
|
|
1527
1542
|
expect3(result.duration_ms).toBeGreaterThanOrEqual(0);
|
|
1528
|
-
expect3(result.dry_run).toBe(false);
|
|
1529
1543
|
expect3(result.dropped).toEqual({
|
|
1530
1544
|
closed_streams: 0,
|
|
1531
1545
|
snapshots: 0,
|
|
@@ -1539,12 +1553,12 @@ var runStoreTck = (options) => {
|
|
|
1539
1553
|
const t0 = /* @__PURE__ */ new Date("2020-01-01T00:00:00.000Z");
|
|
1540
1554
|
const t1 = /* @__PURE__ */ new Date("2020-01-02T00:00:00.000Z");
|
|
1541
1555
|
const t2 = /* @__PURE__ */ new Date("2020-01-03T00:00:00.000Z");
|
|
1542
|
-
const
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1556
|
+
const events = [
|
|
1557
|
+
event(1, s, 0, "Incremented", t0, { amount: 1 }),
|
|
1558
|
+
event(2, s, 1, "Incremented", t1, { amount: 2 }),
|
|
1559
|
+
event(3, s, 2, "Decremented", t2, { amount: 1 })
|
|
1546
1560
|
];
|
|
1547
|
-
const result = await
|
|
1561
|
+
const result = await restore(asSource(events));
|
|
1548
1562
|
expect3(result.kept).toBe(3);
|
|
1549
1563
|
const back = [];
|
|
1550
1564
|
await store.query(
|
|
@@ -1590,13 +1604,13 @@ var runStoreTck = (options) => {
|
|
|
1590
1604
|
const a = `restore-multi-a-${uid()}`;
|
|
1591
1605
|
const b = `restore-multi-b-${uid()}`;
|
|
1592
1606
|
const t = /* @__PURE__ */ new Date("2020-06-01T00:00:00.000Z");
|
|
1593
|
-
const
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1607
|
+
const events = [
|
|
1608
|
+
event(1, a, 0, "Incremented", t, { amount: 10 }),
|
|
1609
|
+
event(2, b, 0, "Incremented", t, { amount: 20 }),
|
|
1610
|
+
event(3, a, 1, "Decremented", t, { amount: 5 }),
|
|
1611
|
+
event(4, b, 1, "Incremented", t, { amount: 30 })
|
|
1598
1612
|
];
|
|
1599
|
-
const result = await
|
|
1613
|
+
const result = await restore(asSource(events));
|
|
1600
1614
|
expect3(result.kept).toBe(4);
|
|
1601
1615
|
const aBack = [];
|
|
1602
1616
|
const bBack = [];
|
|
@@ -1615,10 +1629,10 @@ var runStoreTck = (options) => {
|
|
|
1615
1629
|
expect3(aBack.map((e) => e.version)).toEqual([0, 1]);
|
|
1616
1630
|
expect3(bBack.map((e) => e.version)).toEqual([0, 1]);
|
|
1617
1631
|
});
|
|
1618
|
-
it3("
|
|
1632
|
+
it3("preserves Date `created` verbatim", async () => {
|
|
1619
1633
|
const s = `restore-isoc-${uid()}`;
|
|
1620
1634
|
const iso = "2021-07-15T12:34:56.789Z";
|
|
1621
|
-
await
|
|
1635
|
+
await restore(
|
|
1622
1636
|
asSource([
|
|
1623
1637
|
{
|
|
1624
1638
|
id: 1,
|
|
@@ -1626,7 +1640,7 @@ var runStoreTck = (options) => {
|
|
|
1626
1640
|
version: 0,
|
|
1627
1641
|
name: "Incremented",
|
|
1628
1642
|
data: { amount: 1 },
|
|
1629
|
-
created: iso,
|
|
1643
|
+
created: new Date(iso),
|
|
1630
1644
|
meta: { correlation: "restore-tck", causation: {} }
|
|
1631
1645
|
}
|
|
1632
1646
|
])
|
|
@@ -1650,8 +1664,8 @@ var runStoreTck = (options) => {
|
|
|
1650
1664
|
);
|
|
1651
1665
|
const fresh = `restore-fresh-${uid()}`;
|
|
1652
1666
|
const t = /* @__PURE__ */ new Date("2020-01-01T00:00:00.000Z");
|
|
1653
|
-
await
|
|
1654
|
-
asSource([
|
|
1667
|
+
await restore(
|
|
1668
|
+
asSource([event(1, fresh, 0, "Incremented", t, { amount: 99 })])
|
|
1655
1669
|
);
|
|
1656
1670
|
const oldBack = await collect(store, {
|
|
1657
1671
|
stream: old,
|
|
@@ -1676,14 +1690,14 @@ var runStoreTck = (options) => {
|
|
|
1676
1690
|
};
|
|
1677
1691
|
const before = await collectStreams();
|
|
1678
1692
|
expect3(before.includes(sub)).toBe(true);
|
|
1679
|
-
await
|
|
1693
|
+
await restore(asSource([]));
|
|
1680
1694
|
const after = await collectStreams();
|
|
1681
1695
|
expect3(after.includes(sub)).toBe(false);
|
|
1682
1696
|
});
|
|
1683
1697
|
it3("preserves snapshot events through restore", async () => {
|
|
1684
1698
|
const s = `restore-snap-${uid()}`;
|
|
1685
1699
|
const t = /* @__PURE__ */ new Date("2020-04-01T00:00:00.000Z");
|
|
1686
|
-
await
|
|
1700
|
+
await restore(
|
|
1687
1701
|
asSource([
|
|
1688
1702
|
{
|
|
1689
1703
|
id: 1,
|
|
@@ -1707,7 +1721,7 @@ var runStoreTck = (options) => {
|
|
|
1707
1721
|
it3("rewrites causation refs through the old\u2192new id map", async () => {
|
|
1708
1722
|
const s = `restore-caus-${uid()}`;
|
|
1709
1723
|
const t = /* @__PURE__ */ new Date("2020-08-01T00:00:00.000Z");
|
|
1710
|
-
const
|
|
1724
|
+
const events = [
|
|
1711
1725
|
{
|
|
1712
1726
|
id: 5,
|
|
1713
1727
|
stream: s,
|
|
@@ -1746,7 +1760,7 @@ var runStoreTck = (options) => {
|
|
|
1746
1760
|
}
|
|
1747
1761
|
}
|
|
1748
1762
|
];
|
|
1749
|
-
await
|
|
1763
|
+
await restore(asSource(events));
|
|
1750
1764
|
const back = [];
|
|
1751
1765
|
await store.query(
|
|
1752
1766
|
(e) => {
|
|
@@ -1762,7 +1776,7 @@ var runStoreTck = (options) => {
|
|
|
1762
1776
|
it3("leaves causation refs unmapped when the target isn't in the source", async () => {
|
|
1763
1777
|
const s = `restore-orphan-${uid()}`;
|
|
1764
1778
|
const t = /* @__PURE__ */ new Date("2020-09-01T00:00:00.000Z");
|
|
1765
|
-
await
|
|
1779
|
+
await restore(
|
|
1766
1780
|
asSource([
|
|
1767
1781
|
{
|
|
1768
1782
|
id: 1,
|
|
@@ -1797,7 +1811,7 @@ var runStoreTck = (options) => {
|
|
|
1797
1811
|
makeMeta({ stream: original })
|
|
1798
1812
|
);
|
|
1799
1813
|
const explosive = (async function* () {
|
|
1800
|
-
yield
|
|
1814
|
+
yield event(
|
|
1801
1815
|
1,
|
|
1802
1816
|
`restore-explode-${uid()}`,
|
|
1803
1817
|
0,
|
|
@@ -1807,7 +1821,7 @@ var runStoreTck = (options) => {
|
|
|
1807
1821
|
);
|
|
1808
1822
|
throw new Error("boom");
|
|
1809
1823
|
})();
|
|
1810
|
-
await expect3(
|
|
1824
|
+
await expect3(restore(explosive)).rejects.toThrow("boom");
|
|
1811
1825
|
const back = [];
|
|
1812
1826
|
await store.query(
|
|
1813
1827
|
(e) => {
|
|
@@ -1818,6 +1832,50 @@ var runStoreTck = (options) => {
|
|
|
1818
1832
|
expect3(back).toHaveLength(3);
|
|
1819
1833
|
expect3(back.map((e) => e.id)).toEqual(committed.map((c) => c.id));
|
|
1820
1834
|
});
|
|
1835
|
+
it3("drop_snapshots: skips SNAP_EVENT rows and counts them", async () => {
|
|
1836
|
+
const s = `restore-drop-snap-${uid()}`;
|
|
1837
|
+
const t = /* @__PURE__ */ new Date("2020-10-01T00:00:00.000Z");
|
|
1838
|
+
const result = await restore(
|
|
1839
|
+
asSource([
|
|
1840
|
+
event(1, s, 0, "Incremented", t, { amount: 1 }),
|
|
1841
|
+
{
|
|
1842
|
+
id: 2,
|
|
1843
|
+
stream: s,
|
|
1844
|
+
version: 1,
|
|
1845
|
+
name: SNAP_EVENT,
|
|
1846
|
+
data: { count: 1 },
|
|
1847
|
+
created: t,
|
|
1848
|
+
meta: { correlation: "snap", causation: {} }
|
|
1849
|
+
},
|
|
1850
|
+
event(3, s, 2, "Incremented", t, { amount: 2 })
|
|
1851
|
+
]),
|
|
1852
|
+
{ drop_snapshots: true }
|
|
1853
|
+
);
|
|
1854
|
+
expect3(result.kept).toBe(2);
|
|
1855
|
+
expect3(result.dropped.snapshots).toBe(1);
|
|
1856
|
+
const back = await collect(store, {
|
|
1857
|
+
stream: s,
|
|
1858
|
+
stream_exact: true,
|
|
1859
|
+
with_snaps: true
|
|
1860
|
+
});
|
|
1861
|
+
expect3(back).toHaveLength(2);
|
|
1862
|
+
expect3(
|
|
1863
|
+
back.every((e) => e.name !== SNAP_EVENT)
|
|
1864
|
+
).toBe(true);
|
|
1865
|
+
});
|
|
1866
|
+
it3("on_progress fires once per event (caller throttles)", async () => {
|
|
1867
|
+
const calls = [];
|
|
1868
|
+
const s = `restore-progress-${uid()}`;
|
|
1869
|
+
const t = /* @__PURE__ */ new Date("2021-02-01T00:00:00.000Z");
|
|
1870
|
+
await restore(
|
|
1871
|
+
asSource([
|
|
1872
|
+
event(1, s, 0, "Incremented", t, { amount: 1 }),
|
|
1873
|
+
event(2, s, 1, "Incremented", t, { amount: 2 })
|
|
1874
|
+
]),
|
|
1875
|
+
{ on_progress: (p) => calls.push(p.processed) }
|
|
1876
|
+
);
|
|
1877
|
+
expect3(calls).toEqual([1, 2]);
|
|
1878
|
+
});
|
|
1821
1879
|
});
|
|
1822
1880
|
if (caps.notify) {
|
|
1823
1881
|
describe3("notify (capability)", () => {
|