@stll/calculations 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +6 -5
  2. package/package.json +6 -5
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { panic } from "better-result";
1
2
  import { MoneyTotals, cents } from "@stll/money";
2
3
  //#region src/index.ts
3
4
  /**
@@ -81,7 +82,7 @@ const runCalculation = ({ kind, values, scopeValues }) => {
81
82
  kind,
82
83
  reason: "no-scope"
83
84
  } : percentOfTotal(kind, values, scopeValues);
84
- default: return kind;
85
+ default: return panic(`Unhandled kind: ${String(kind)}`);
85
86
  }
86
87
  };
87
88
  const countEmpty = (values) => values.filter((value) => value.type === "empty").length;
@@ -96,7 +97,7 @@ const uniqueKey = (value) => {
96
97
  case "number": return `n:${value.value}`;
97
98
  case "money": return `m:${value.currency}:${value.amountCents}`;
98
99
  case "text": return `t:${value.value}`;
99
- default: return value;
100
+ default: return panic(`Unhandled value: ${String(value)}`);
100
101
  }
101
102
  };
102
103
  const countUnique = (values) => {
@@ -131,7 +132,7 @@ const classify = (values) => {
131
132
  else buckets.set(value.currency, [value.amountCents]);
132
133
  break;
133
134
  }
134
- default: return value;
135
+ default: return panic(`Unhandled value: ${String(value)}`);
135
136
  }
136
137
  if (numbers.length > 0 && buckets.size > 0) return {
137
138
  type: "unsupported",
@@ -192,7 +193,7 @@ const reduceNumeric = (kind, values) => {
192
193
  totals: totals.entries()
193
194
  };
194
195
  }
195
- default: return classified;
196
+ default: return panic(`Unhandled classified: ${String(classified)}`);
196
197
  }
197
198
  };
198
199
  /**
@@ -256,7 +257,7 @@ const singleTotal = (values) => {
256
257
  unit: currency
257
258
  };
258
259
  }
259
- default: return classified;
260
+ default: return panic(`Unhandled classified: ${String(classified)}`);
260
261
  }
261
262
  };
262
263
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/calculations",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Typed, unit-safe reducers for workspace column calculations.",
5
5
  "keywords": [
6
6
  "calculations",
@@ -39,20 +39,21 @@
39
39
  "build": "tsdown",
40
40
  "pack:dry-run": "bun pm pack --dry-run",
41
41
  "test": "bun test src",
42
- "test:property": "bun test $(grep -rlF 'fc.assert' src)",
42
+ "test:property": "bun test --preload @stll/property-testing/preload $(grep -rlF 'fc.assert' src)",
43
43
  "typecheck": "bun ../../packages/scripts/src/tsc-native.ts --noEmit",
44
44
  "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --deny-warnings --type-aware packages/calculations",
45
45
  "lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/calculations",
46
- "format": "oxfmt .",
46
+ "format": "bun ../../scripts/run-oxfmt.ts .",
47
47
  "prepack": "bun run build"
48
48
  },
49
49
  "dependencies": {
50
- "@stll/money": "^0.1.0"
50
+ "@stll/money": "^0.2.0",
51
+ "better-result": "3.0.0"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@stll/property-testing": "0.0.0",
54
55
  "@stll/typescript-config": "0.0.0",
55
- "@types/bun": "1.3.14",
56
+ "bun-types": "1.4.2",
56
57
  "fast-check": "^4.9.0",
57
58
  "tsdown": "0.22.14"
58
59
  },