Skip to content

Commit 8f321c3

Browse files
authored
feat: update pipe.ts to use unlimited vardic types (#4484)
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 556a270 commit 8f321c3

34 files changed

+908
-231
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dist/
77
dist-test/
88
build/
99
lib*/
10+
coverage/
1011
!demos/storyboard/lib-umd/
1112
types/
1213
types-3.4/

packages/dataflow/.vscode/launch.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"request": "launch",
1919
"runtimeArgs": [
2020
"run-script",
21-
"test-node"
21+
"test-vitest"
2222
],
2323
"runtimeExecutable": "npm",
2424
"skipFiles": [
@@ -29,6 +29,25 @@
2929
"!**/node_modules/**"
3030
],
3131
},
32+
{
33+
"name": "test-node-pipe.spec.ts",
34+
"type": "node",
35+
"request": "launch",
36+
"runtimeArgs": [
37+
"run",
38+
"test-vitest",
39+
"--",
40+
"./tests/pipe.spec.ts"
41+
],
42+
"runtimeExecutable": "npm",
43+
"skipFiles": [
44+
"<node_internals>/**"
45+
],
46+
"outFiles": [
47+
"${workspaceFolder}/**/*.js",
48+
"!**/node_modules/**"
49+
]
50+
},
3251
{
3352
"name": "index.html",
3453
"request": "launch",

packages/dataflow/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
"docs": "typedoc --options tdoptions.json .",
3333
"test-browser": "vitest run --project browser",
3434
"test-node": "vitest run --project node",
35-
"test": "vitest run",
35+
"test-types": "npx --yes tsc --project tsconfig.tests.json --noEmit",
36+
"test-vitest": "vitest run",
37+
"test": "run-s test-types test-vitest",
38+
"bench": "vitest bench",
3639
"coverage": "vitest run --coverage",
3740
"update": "npx --yes npm-check-updates -u -t minor",
3841
"update-major": "npx --yes npm-check-updates -u"

packages/dataflow/src/utils/pipe.ts

Lines changed: 222 additions & 63 deletions
Large diffs are not rendered by default.

packages/dataflow/tests/chain.spec.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

packages/dataflow/tests/concat.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { describe, it, expect } from "vitest";
2-
import { concat } from "@hpcc-js/dataflow";
2+
import { concat } from "../src/index.ts";
33

44
describe("concat", () => {
5-
it("generator", () => {
5+
it("should concatenate arrays when used as curried activity", () => {
66
expect([...concat([])([])]).to.deep.equal([]);
77
expect([...concat([1, 2, 3])([])]).to.deep.equal([1, 2, 3]);
88
expect([...concat<number>([])([1, 2, 3])]).to.deep.equal([1, 2, 3]);
99
expect([...concat([4, 5, 6])([1, 2, 3])]).to.deep.equal([1, 2, 3, 4, 5, 6]);
1010
});
1111

12-
it("scalarActivity", () => {
12+
it("should concatenate arrays when executed immediately", () => {
1313
expect([...concat([], [])]).to.deep.equal([]);
1414
expect([...concat([], [1, 2, 3])]).to.deep.equal([1, 2, 3]);
1515
expect([...concat([1, 2, 3], [])]).to.deep.equal([1, 2, 3]);

packages/dataflow/tests/count.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { describe, it, expect } from "vitest";
2-
import { pipe, filter, count, scalar, sensor } from "@hpcc-js/dataflow";
2+
import { pipe, filter, count, scalar, sensor } from "../src/index.ts";
33
import { population } from "./data.spec.ts";;
44

55
describe("count", () => {
66

7-
it("Population", () => {
7+
it("should track count through pipeline with filters", () => {
88
const s1 = count();
99
const s2 = count();
1010
const p1 = pipe(
@@ -18,7 +18,7 @@ describe("count", () => {
1818
expect(data.length).to.equal(699);
1919
});
2020

21-
it("scalarActivity", () => {
21+
it("should count items when used as scalar activity", () => {
2222
const countActivity = scalar(count());
2323
expect(countActivity([5, 1, 2, -3, 4])).to.equal(5);
2424
});
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { describe, it, expect } from "vitest";
2-
import { deviation, scalar } from "@hpcc-js/dataflow";
2+
import { deviation, scalar } from "../src/index.ts";
33

44
describe("deviation", () => {
5-
it("scalarActivity", () => {
5+
it("should calculate standard deviation when used as scalar activity", () => {
66
const calcDeviation = scalar(deviation());
77
expect(calcDeviation([5, 1, 2, 3, 4])).to.equal(Math.sqrt(2.5));
88
});
99

10-
it("empty array", () => {
10+
it("should return undefined for empty array", () => {
1111
const deviationActivity = scalar(deviation());
1212
expect(deviationActivity([])).to.be.undefined;
1313
});
14+
15+
it("with accessor callback", () => {
16+
const data = [{ value: 5 }, { value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }];
17+
const calcDeviation = scalar(deviation((d: { value: number }) => d.value));
18+
expect(calcDeviation(data)).to.equal(Math.sqrt(2.5));
19+
});
1420
});
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { describe, it, expect } from "vitest";
2-
import { distribution, scalar } from "@hpcc-js/dataflow";
2+
import { distribution, scalar } from "../src/index.ts";
33

44
describe("distribution", () => {
55

6-
it("scalarActivity", () => {
6+
it("should calculate full distribution statistics", () => {
77
const calcDistribution = scalar(distribution());
88
expect(calcDistribution([5, 1, 2, 3, 4])).to.deep.equal({
99
min: 1,
@@ -14,8 +14,20 @@ describe("distribution", () => {
1414
});
1515
});
1616

17-
it("empty array", () => {
17+
it("should return undefined for empty array", () => {
1818
const a1 = scalar(distribution());
1919
expect(a1([])).to.be.undefined;
2020
});
21+
22+
it("with accessor callback", () => {
23+
const data = [{ value: 5 }, { value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }];
24+
const calcDistribution = scalar(distribution((d: { value: number }) => d.value));
25+
expect(calcDistribution(data)).to.deep.equal({
26+
min: 1,
27+
mean: 3,
28+
max: 5,
29+
deviation: Math.sqrt(2.5),
30+
variance: 2.5
31+
});
32+
});
2133
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { describe, it, expect } from "vitest";
2-
import { each } from "@hpcc-js/dataflow";
2+
import { each } from "../src/index.ts";
33
import { population } from "./data.spec.ts";;
44

55
describe("each", () => {
6-
it("generator", () => {
6+
it("should execute callback for each item when used as curried activity", () => {
77
[...each((row, i) => expect(row).to.equal(population[i]))(population)];
88
});
99

10-
it("scalarActivity", () => {
10+
it("should execute callback for each item when executed immediately", () => {
1111
[...each(population, (row, i) => expect(row).to.equal(population[i]))];
1212
});
1313
});

0 commit comments

Comments
 (0)