sflow
Version:
sflow is a powerful and highly-extensible library designed for processing and manipulating streams of data effortlessly. Inspired by the functional programming paradigm, it provides a rich set of utilities for transforming streams, including chunking, fil
37 lines (35 loc) • 917 B
text/typescript
import { expectTypeOf } from "expect-type";
import Keyv from "keyv";
import { KeyvCachedWith } from "keyv-cached-with";
import { pageFlow } from "./index";
it("works with number", async () => {
await pageFlow(0, (page) => {
expectTypeOf(page).toBeNumber();
const data = [1, 2, 3, 4, 5][page];
return {
data,
next: (!!data && page + 1) || null,
};
})
.map((e) => e)
.done();
});
it("works with cache", async () => {
const cache1d = KeyvCachedWith(new Keyv<unknown>({ ttl: 86400e3 }));
await pageFlow(
0,
cache1d(
async (page: number): Promise<{ data: number; next: number | null }> => {
const data = [1, 2, 3, 4, 5][page];
expectTypeOf(page).toBeNumber();
expectTypeOf(data).toBeNumber();
return {
data,
next: (!!data && page + 1) || null,
};
},
),
)
.map((e) => e)
.done();
});