@amboras-dev/money 0.2.0 → 0.4.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.
Files changed (78) hide show
  1. package/README.md +22 -11
  2. package/dist/ai.cjs +12 -13
  3. package/dist/ai.d.cts +5 -9
  4. package/dist/ai.d.ts +5 -9
  5. package/dist/ai.js +12 -13
  6. package/dist/{allocate-CZRg4TOP.cjs → allocate-AusholrC.cjs} +3 -4
  7. package/dist/{allocate-X7_jAtOj.js → allocate-BBRfdaSC.js} +3 -4
  8. package/dist/{amount-BV0O-aN8.cjs → amount-Bzxw9aD4.cjs} +32 -14
  9. package/dist/{amount-BoYBMgK9.js → amount-off8IMBJ.js} +32 -14
  10. package/dist/{arithmetic-BhNwisjb.js → arithmetic-C97-YafD.js} +4 -5
  11. package/dist/{arithmetic-DjT4Kzgt.cjs → arithmetic-D8A6IeZ0.cjs} +4 -5
  12. package/dist/billing.cjs +5 -8
  13. package/dist/billing.d.cts +1 -9
  14. package/dist/billing.d.ts +1 -9
  15. package/dist/billing.js +5 -8
  16. package/dist/commerce.cjs +15 -23
  17. package/dist/commerce.d.cts +2 -16
  18. package/dist/commerce.d.ts +2 -16
  19. package/dist/commerce.js +15 -23
  20. package/dist/{format-DLhno7eX.cjs → format-92fzvTXY.cjs} +9 -9
  21. package/dist/{format-BdPnijvn.js → format-BJC513u4.js} +9 -9
  22. package/dist/fx.cjs +12 -18
  23. package/dist/fx.d.cts +5 -15
  24. package/dist/fx.d.ts +5 -15
  25. package/dist/fx.js +12 -18
  26. package/dist/index.cjs +10 -12
  27. package/dist/index.d.cts +17 -23
  28. package/dist/index.d.ts +17 -23
  29. package/dist/index.js +10 -12
  30. package/dist/input.cjs +7 -10
  31. package/dist/input.d.cts +16 -22
  32. package/dist/input.d.ts +16 -22
  33. package/dist/input.js +7 -10
  34. package/dist/{iso-minor-wSwJN57T.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
  35. package/dist/{iso-minor-CqkWDxHS.js → iso-minor-odkY-e6I.js} +2 -3
  36. package/dist/{medusa-lRY9xlsf.cjs → medusa-CzVK0bth.cjs} +3 -4
  37. package/dist/{medusa-DBXJXXvF.d.ts → medusa-DofdvIgQ.d.cts} +1 -3
  38. package/dist/{medusa-4K8N1pUc.d.cts → medusa-DrbYmD2Y.d.ts} +1 -3
  39. package/dist/{medusa-DqJY1qpj.js → medusa-pKGlImn9.js} +3 -4
  40. package/dist/{money-B-3aFjNJ.d.cts → money-BkMeYDEW.d.cts} +0 -6
  41. package/dist/{money-B-3aFjNJ.d.ts → money-BkMeYDEW.d.ts} +0 -6
  42. package/dist/{money-WhnGiI00.js → money-BxbAw7BP.js} +7 -15
  43. package/dist/{money-B3wH_Z4S.cjs → money-DWBjuuEK.cjs} +7 -15
  44. package/dist/{number-text-DE-q4jO5.js → number-text-Bj-gZXiF.js} +3 -4
  45. package/dist/{number-text-BWu67jUq.cjs → number-text-CWuVwrlg.cjs} +3 -4
  46. package/dist/{own-oP9DXFWv.cjs → own-C5imDkyB.cjs} +1 -2
  47. package/dist/{own-D7544D3k.js → own-DHxqIYqL.js} +1 -2
  48. package/dist/{percent-D1VB9xXG.js → percent-CB3Ixjc_.js} +2 -3
  49. package/dist/{percent-C0InC2t2.cjs → percent-DABHiSBs.cjs} +2 -3
  50. package/dist/{rate-DBPiYgT1.d.ts → rate-BvvZUdSu.d.ts} +1 -3
  51. package/dist/{rate-tqK8ijG0.d.cts → rate-CEakW3ia.d.cts} +1 -3
  52. package/dist/{rate-CVeMii4a.cjs → rate-CEjWTATc.cjs} +3 -4
  53. package/dist/{rate-DicStBue.js → rate-D6S2_wgZ.js} +3 -4
  54. package/dist/{reporting-tpGJbqYp.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
  55. package/dist/{reporting-CG-ai2sM.d.cts → reporting-jIBILvnr.d.ts} +2 -4
  56. package/dist/{retail-DRUTTQoJ.d.ts → retail-B04CjW3b.d.ts} +1 -3
  57. package/dist/{retail-Cml8YSKg.cjs → retail-CYGPU4ea.cjs} +4 -5
  58. package/dist/{retail-C_BPLvMj.d.cts → retail-CmEyJQOH.d.cts} +1 -3
  59. package/dist/{retail-1mu888J1.js → retail-DXgs11ov.js} +4 -5
  60. package/dist/{rounding-DHBtNCHG.cjs → rounding-4QKTRbMQ.cjs} +2 -3
  61. package/dist/{rounding-g9rvye0k.js → rounding-CA1PVP3b.js} +2 -3
  62. package/dist/sql.cjs +9 -15
  63. package/dist/sql.d.cts +2 -12
  64. package/dist/sql.d.ts +2 -12
  65. package/dist/sql.js +9 -15
  66. package/dist/testing.cjs +39198 -12
  67. package/dist/testing.d.cts +20 -13
  68. package/dist/testing.d.ts +20 -13
  69. package/dist/testing.js +39198 -13
  70. package/dist/{wire-sW0yzqth.js → wire-B4QU8O3W.js} +350 -93
  71. package/dist/{wire-CaUN9Vf_.d.ts → wire-CVNicirK.d.ts} +165 -46
  72. package/dist/{wire-xjYXv4go.d.cts → wire-CtNJmWVP.d.cts} +165 -46
  73. package/dist/{wire-Bhuut8cW.cjs → wire-u2tmHY0Y.cjs} +403 -92
  74. package/dist/wire.cjs +10 -1
  75. package/dist/wire.d.cts +2 -2
  76. package/dist/wire.d.ts +2 -2
  77. package/dist/wire.js +1 -2
  78. package/package.json +4 -3
@@ -1,5 +1,4 @@
1
- import { R as DecimalText } from "./money-B-3aFjNJ.cjs";
2
- //#region src/fx/rate.d.ts
1
+ import { R as DecimalText } from "./money-BkMeYDEW.cjs";
3
2
  /** 1 base unit = numerator / denominator quote units, both in major units. Positive integers. */
4
3
  interface Rate {
5
4
  readonly numerator: bigint;
@@ -59,5 +58,4 @@ declare function invertRate(r: Rate): Rate;
59
58
  declare function crossRate(table: Readonly<Record<string, Rate>>, from: string, to: string, base: string): Rate | null;
60
59
  /** Same value (cross-multiplied), whatever the parts: 2/4 equals 1/2. */
61
60
  declare function rateEquals(a: Rate, b: Rate): boolean;
62
- //#endregion
63
61
  export { RateRow as a, rate as c, rateFromRow as d, rateToDecimal as f, RateFromDecimalOptions as i, rateEquals as l, RATE_REF as n, crossRate as o, rateToNumber as p, Rate as r, invertRate as s, RATE_BOUNDS as t, rateFromDecimal as u };
@@ -1,6 +1,6 @@
1
- const require_money = require("./money-B3wH_Z4S.cjs");
2
- const require_own = require("./own-oP9DXFWv.cjs");
3
- //#region src/fx/rate.ts
1
+ const require_money = require("./money-DWBjuuEK.cjs");
2
+ const require_own = require("./own-C5imDkyB.cjs");
3
+ // src/fx/rate.ts
4
4
  /** Denominator of every locked rate (`store_currency_rate.rate_denominator` default): 7 decimals. */
5
5
  const RATE_REF = 10000000n;
6
6
  /** Inclusive bounds of a locked rate's value: `lockedRateNumerator` (n >= 1 at RATE_REF, value <= 1e9). */
@@ -148,7 +148,6 @@ function rateEquals(a, b) {
148
148
  const y = checkRate(b);
149
149
  return require_money.compareRatio(x.numerator, x.denominator, y.numerator, y.denominator) === 0;
150
150
  }
151
- //#endregion
152
151
  Object.defineProperty(exports, "RATE_BOUNDS", {
153
152
  enumerable: true,
154
153
  get: function() {
@@ -1,6 +1,6 @@
1
- import { $ as describeValue, B as decimalOf, J as compareRatio, Q as MoneyError, Z as ratioToDecimal, dt as roundToScale, lt as parseDecimal, pt as toDecimalText, ut as pow10 } from "./money-WhnGiI00.js";
2
- import { t as hasOwnKey } from "./own-D7544D3k.js";
3
- //#region src/fx/rate.ts
1
+ import { $ as describeValue, B as decimalOf, J as compareRatio, Q as MoneyError, Z as ratioToDecimal, dt as roundToScale, lt as parseDecimal, pt as toDecimalText, ut as pow10 } from "./money-BxbAw7BP.js";
2
+ import { t as hasOwnKey } from "./own-DHxqIYqL.js";
3
+ // src/fx/rate.ts
4
4
  /** Denominator of every locked rate (`store_currency_rate.rate_denominator` default): 7 decimals. */
5
5
  const RATE_REF = 10000000n;
6
6
  /** Inclusive bounds of a locked rate's value: `lockedRateNumerator` (n >= 1 at RATE_REF, value <= 1e9). */
@@ -148,5 +148,4 @@ function rateEquals(a, b) {
148
148
  const y = checkRate(b);
149
149
  return compareRatio(x.numerator, x.denominator, y.numerator, y.denominator) === 0;
150
150
  }
151
- //#endregion
152
151
  export { invertRate as a, rateFromDecimal as c, rateToNumber as d, crossRate as i, rateFromRow as l, RATE_REF as n, rate as o, checkRate as r, rateEquals as s, RATE_BOUNDS as t, rateToDecimal as u };
@@ -1,6 +1,5 @@
1
- import { R as DecimalText, g as CurrencyCode, i as Money } from "./money-B-3aFjNJ.js";
2
- import { a as RateRow } from "./rate-DBPiYgT1.js";
3
- //#region src/fx/reporting.d.ts
1
+ import { R as DecimalText, g as CurrencyCode, i as Money } from "./money-BkMeYDEW.cjs";
2
+ import { a as RateRow } from "./rate-CEakW3ia.cjs";
4
3
  /** `factors[lower code]` takes a stored amount in that currency to a stored amount in `base`. */
5
4
  interface FactorTable {
6
5
  readonly base: CurrencyCode;
@@ -27,5 +26,4 @@ interface ReportingTotal {
27
26
  * Items whose currency has no factor are excluded and reported in `missing`.
28
27
  */
29
28
  declare function toReporting(items: readonly Money[], table: FactorTable): ReportingTotal;
30
- //#endregion
31
29
  export { toReporting as i, ReportingTotal as n, storeFactors as r, FactorTable as t };
@@ -1,6 +1,5 @@
1
- import { R as DecimalText, g as CurrencyCode, i as Money } from "./money-B-3aFjNJ.cjs";
2
- import { a as RateRow } from "./rate-tqK8ijG0.cjs";
3
- //#region src/fx/reporting.d.ts
1
+ import { R as DecimalText, g as CurrencyCode, i as Money } from "./money-BkMeYDEW.js";
2
+ import { a as RateRow } from "./rate-BvvZUdSu.js";
4
3
  /** `factors[lower code]` takes a stored amount in that currency to a stored amount in `base`. */
5
4
  interface FactorTable {
6
5
  readonly base: CurrencyCode;
@@ -27,5 +26,4 @@ interface ReportingTotal {
27
26
  * Items whose currency has no factor are excluded and reported in `missing`.
28
27
  */
29
28
  declare function toReporting(items: readonly Money[], table: FactorTable): ReportingTotal;
30
- //#endregion
31
29
  export { toReporting as i, ReportingTotal as n, storeFactors as r, FactorTable as t };
@@ -1,5 +1,4 @@
1
- import { i as Money } from "./money-B-3aFjNJ.js";
2
- //#region src/fx/retail.d.ts
1
+ import { i as Money } from "./money-BkMeYDEW.js";
3
2
  /**
4
3
  * - `'none'`: Medusa `applyRounding` 'none': a zero-decimal currency is rounded to a whole
5
4
  * unit (half toward +infinity, as `Math.round`: JPY 150050 gives 150100, since there is no
@@ -27,5 +26,4 @@ declare function priceRoundingParams(currency: string): {
27
26
  majorUnit: 100 | 1000;
28
27
  charm: number | null;
29
28
  };
30
- //#endregion
31
29
  export { priceRoundingParams as n, roundRetail as r, RetailRounding as t };
@@ -1,7 +1,7 @@
1
- const require_money = require("./money-B3wH_Z4S.cjs");
2
- const require_rounding = require("./rounding-DHBtNCHG.cjs");
3
- const require_percent = require("./percent-C0InC2t2.cjs");
4
- //#region src/fx/retail.ts
1
+ const require_money = require("./money-DWBjuuEK.cjs");
2
+ const require_rounding = require("./rounding-4QKTRbMQ.cjs");
3
+ const require_percent = require("./percent-DABHiSBs.cjs");
4
+ // src/fx/retail.ts
5
5
  const RETAIL_ROUNDINGS = [
6
6
  "none",
7
7
  "nearest",
@@ -65,7 +65,6 @@ function priceRoundingParams(currency) {
65
65
  charm: info.storageDigits === 0 ? null : Number(charmOf(scale))
66
66
  };
67
67
  }
68
- //#endregion
69
68
  Object.defineProperty(exports, "priceRoundingParams", {
70
69
  enumerable: true,
71
70
  get: function() {
@@ -1,5 +1,4 @@
1
- import { i as Money } from "./money-B-3aFjNJ.cjs";
2
- //#region src/fx/retail.d.ts
1
+ import { i as Money } from "./money-BkMeYDEW.cjs";
3
2
  /**
4
3
  * - `'none'`: Medusa `applyRounding` 'none': a zero-decimal currency is rounded to a whole
5
4
  * unit (half toward +infinity, as `Math.round`: JPY 150050 gives 150100, since there is no
@@ -27,5 +26,4 @@ declare function priceRoundingParams(currency: string): {
27
26
  majorUnit: 100 | 1000;
28
27
  charm: number | null;
29
28
  };
30
- //#endregion
31
29
  export { priceRoundingParams as n, roundRetail as r, RetailRounding as t };
@@ -1,7 +1,7 @@
1
- import { $ as describeValue, E as resolveCurrency, Q as MoneyError, rt as divRound, s as storedDecimal, t as boundedMoney } from "./money-WhnGiI00.js";
2
- import { a as unitSize, t as mulDivToUnit } from "./rounding-g9rvye0k.js";
3
- import { r as percentOfUnits } from "./percent-D1VB9xXG.js";
4
- //#region src/fx/retail.ts
1
+ import { $ as describeValue, E as resolveCurrency, Q as MoneyError, rt as divRound, s as storedDecimal, t as boundedMoney } from "./money-BxbAw7BP.js";
2
+ import { a as unitSize, t as mulDivToUnit } from "./rounding-CA1PVP3b.js";
3
+ import { r as percentOfUnits } from "./percent-CB3Ixjc_.js";
4
+ // src/fx/retail.ts
5
5
  const RETAIL_ROUNDINGS = [
6
6
  "none",
7
7
  "nearest",
@@ -65,5 +65,4 @@ function priceRoundingParams(currency) {
65
65
  charm: info.storageDigits === 0 ? null : Number(charmOf(scale))
66
66
  };
67
67
  }
68
- //#endregion
69
68
  export { retailUnits as n, roundRetail as r, priceRoundingParams as t };
@@ -1,5 +1,5 @@
1
- const require_money = require("./money-B3wH_Z4S.cjs");
2
- //#region src/rounding.ts
1
+ const require_money = require("./money-DWBjuuEK.cjs");
2
+ // src/rounding.ts
3
3
  /** Internal: the size of `unit` in storage units. */
4
4
  function unitSize(info, unit) {
5
5
  if (unit === "storage") return 1n;
@@ -46,7 +46,6 @@ function roundMajor(major, currency, options = {}) {
46
46
  const digits = options.digits === "storage" ? info.storageDigits : info.displayDigits;
47
47
  return Number(require_money.formatDecimal(require_money.roundToScale(value, digits, options.rounding ?? "half-up")));
48
48
  }
49
- //#endregion
50
49
  Object.defineProperty(exports, "mulDivToUnit", {
51
50
  enumerable: true,
52
51
  get: function() {
@@ -1,5 +1,5 @@
1
- import { B as decimalOf, E as resolveCurrency, Q as MoneyError, X as mulDiv, dt as roundToScale, it as formatDecimal, s as storedDecimal, t as boundedMoney, ut as pow10 } from "./money-WhnGiI00.js";
2
- //#region src/rounding.ts
1
+ import { B as decimalOf, E as resolveCurrency, Q as MoneyError, X as mulDiv, dt as roundToScale, it as formatDecimal, s as storedDecimal, t as boundedMoney, ut as pow10 } from "./money-BxbAw7BP.js";
2
+ // src/rounding.ts
3
3
  /** Internal: the size of `unit` in storage units. */
4
4
  function unitSize(info, unit) {
5
5
  if (unit === "storage") return 1n;
@@ -46,5 +46,4 @@ function roundMajor(major, currency, options = {}) {
46
46
  const digits = options.digits === "storage" ? info.storageDigits : info.displayDigits;
47
47
  return Number(formatDecimal(roundToScale(value, digits, options.rounding ?? "half-up")));
48
48
  }
49
- //#endregion
50
49
  export { unitSize as a, roundToUnit as i, roundMajor as n, roundStoredDecimal as r, mulDivToUnit as t };
package/dist/sql.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_money = require("./money-B3wH_Z4S.cjs");
3
- const require_rate = require("./rate-CVeMii4a.cjs");
4
- const require_retail = require("./retail-Cml8YSKg.cjs");
5
- //#region src/sql/guard.ts
2
+ const require_money = require("./money-DWBjuuEK.cjs");
3
+ const require_rate = require("./rate-CEjWTATc.cjs");
4
+ const require_retail = require("./retail-CYGPU4ea.cjs");
5
+ // src/sql/guard.ts
6
6
  const STATEMENT_BREAKERS = /;|--|\/\*|\*\/|\0/;
7
7
  const refuse = (name, value) => new require_money.MoneyError("parse", `${name} must be a SQL expression written in code, got ${require_money.describeValue(value)}`);
8
8
  /** Code-written text, or `parse` when it is blank, could break out of the expression or holds a `?` placeholder. */
@@ -57,8 +57,7 @@ function dialectOf(value) {
57
57
  if (value !== "pg" && value !== "clickhouse") throw new require_money.MoneyError("parse", `Unknown SQL dialect: ${require_money.describeValue(value)}`);
58
58
  return value;
59
59
  }
60
- //#endregion
61
- //#region src/sql/lists.ts
60
+ // src/sql/lists.ts
62
61
  const quoted = (pick) => require_money.CURRENCIES.filter(pick).map((info) => `'${info.code}'`).join(",");
63
62
  /** Storage scale 1000: `'BHD','IQD','JOD','KWD','LYD','OMR','TND'`. */
64
63
  const SCALE_1000_CODES = quoted((info) => info.storageScale === 1e3);
@@ -70,8 +69,7 @@ const DISPLAY_3_CODES = quoted((info) => info.displayDigits === 3);
70
69
  const MEDUSA_0_CODES = quoted((info) => info.medusaDigits === 0);
71
70
  /** Medusa core `decimal_digits` 3 (payment-status epsilon 0.001). */
72
71
  const MEDUSA_3_CODES = quoted((info) => info.medusaDigits === 3);
73
- //#endregion
74
- //#region src/sql/amounts.ts
72
+ // src/sql/amounts.ts
75
73
  const CH_STORED_SCALE = 3;
76
74
  const CH_ROUND_SCALE = 12;
77
75
  /** The storage divisor of the currency in `codeExpr`, keyed by code (never `currency.decimal_digits`). */
@@ -145,8 +143,7 @@ function rawAmountJsonSql(expr) {
145
143
  function normalizeCurrencySql(expr) {
146
144
  return sql`lower(btrim(${expression(expr, "expr")}))`;
147
145
  }
148
- //#endregion
149
- //#region src/sql/clickhouse.ts
146
+ // src/sql/clickhouse.ts
150
147
  /**
151
148
  * The SELECT list and GROUP BY of per-currency purchase revenue in stored units. The event name
152
149
  * is a ClickHouse query parameter (`{revenue_event:String}`, pass `params` as `query_params`),
@@ -165,8 +162,7 @@ function chEventRevenueByCurrencySql(cols = {}) {
165
162
  params: { revenue_event: event }
166
163
  };
167
164
  }
168
- //#endregion
169
- //#region src/sql/ddl.ts
165
+ // src/sql/ddl.ts
170
166
  /** The column type of a stored amount. */
171
167
  const STORAGE_AMOUNT_SQL_TYPE = "BIGINT";
172
168
  /** A column for DDL, which Postgres never parameterises: a fragment with bindings is `parse`. */
@@ -208,8 +204,7 @@ function usdToCreditsSql(expr) {
208
204
  function monthlyEquivalentSql(expr) {
209
205
  return sql`ROUND((${expression(expr, "expr")})::numeric / 12)`;
210
206
  }
211
- //#endregion
212
- //#region src/sql/fx.ts
207
+ // src/sql/fx.ts
213
208
  function factorsJson(table) {
214
209
  require_money.resolveCurrency(table?.base, { allowHistoric: true });
215
210
  return JSON.stringify(table.factors);
@@ -268,7 +263,6 @@ function convertStoredByColumnsSql(amountExpr, cols) {
268
263
  const whole = sql`(FLOOR(${x} / ${major}) * ${major})`;
269
264
  return sql`(CASE WHEN ${retail} = 'none' THEN ${x} WHEN ${x} <= 0 THEN ${x} WHEN ${charm} IS NULL THEN CEIL(${x} / (100 * ${major})) * (100 * ${major}) WHEN ${x} <= ${whole} + ${charm} THEN ${whole} + ${charm} ELSE ${whole} + ${major} + ${charm} END)`;
270
265
  }
271
- //#endregion
272
266
  exports.STORAGE_AMOUNT_SQL_TYPE = STORAGE_AMOUNT_SQL_TYPE;
273
267
  exports.chEventRevenueByCurrencySql = chEventRevenueByCurrencySql;
274
268
  exports.convertStoredByColumnsSql = convertStoredByColumnsSql;
package/dist/sql.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { r as Rate } from "./rate-tqK8ijG0.cjs";
2
- import { t as FactorTable } from "./reporting-CG-ai2sM.cjs";
3
- //#region src/sql/guard.d.ts
1
+ import { r as Rate } from "./rate-CEakW3ia.cjs";
2
+ import { t as FactorTable } from "./reporting-DFNyDBdi.cjs";
4
3
  type SqlBinding = string | number;
5
4
  /** Text with knex `?` placeholders and the values they bind, in order: `knex.raw(f.sql, f.bindings)`. */
6
5
  interface SqlFragment {
@@ -10,8 +9,6 @@ interface SqlFragment {
10
9
  /** An expression argument: SQL text written in code (a column reference), or a builder's SqlFragment. */
11
10
  type SqlExpression = string | SqlFragment;
12
11
  type SqlDialect = 'pg' | 'clickhouse';
13
- //#endregion
14
- //#region src/sql/amounts.d.ts
15
12
  /** The storage divisor of the currency in `codeExpr`, keyed by code (never `currency.decimal_digits`). */
16
13
  export declare function storageDivisorSql(codeExpr: SqlExpression, dialect?: SqlDialect): SqlFragment;
17
14
  /**
@@ -51,8 +48,6 @@ export declare function summaryAmountSql(totalsExpr: SqlExpression, key: string,
51
48
  export declare function rawAmountJsonSql(expr: SqlExpression): SqlFragment;
52
49
  /** A currency code column normalised the way Medusa stores it. */
53
50
  export declare function normalizeCurrencySql(expr: SqlExpression): SqlFragment;
54
- //#endregion
55
- //#region src/sql/clickhouse.d.ts
56
51
  interface EventRevenueColumns {
57
52
  /** Default `'value'` (stored units). */
58
53
  readonly value?: string;
@@ -79,8 +74,6 @@ interface EventRevenueSql {
79
74
  * (verified on 24.8).
80
75
  */
81
76
  export declare function chEventRevenueByCurrencySql(cols?: EventRevenueColumns): EventRevenueSql;
82
- //#endregion
83
- //#region src/sql/ddl.d.ts
84
77
  /** The column type of a stored amount. */
85
78
  export declare const STORAGE_AMOUNT_SQL_TYPE = "BIGINT";
86
79
  /** Lower-case three-letter currency codes only. */
@@ -108,8 +101,6 @@ export declare function storageAmountCheckSql(column: SqlExpression, options?: S
108
101
  export declare function usdToCreditsSql(expr: SqlExpression): SqlFragment;
109
102
  /** A yearly price as its monthly equivalent, half away from zero, the twin of `billing.monthlyEquivalent`. */
110
103
  export declare function monthlyEquivalentSql(expr: SqlExpression): SqlFragment;
111
- //#endregion
112
- //#region src/sql/fx.d.ts
113
104
  /**
114
105
  * A stored amount in the currency of `codeExpr` converted with the bound factor table
115
106
  * (`fx.storeFactors`): `output: 'stored'` rounds half away from zero to a storage unit of the
@@ -143,5 +134,4 @@ interface ConvertColumns {
143
134
  }
144
135
  /** `convertStoredSql` with the factor and rounding read from columns, so one statement converts many currencies. */
145
136
  export declare function convertStoredByColumnsSql(amountExpr: SqlExpression, cols: ConvertColumns): SqlFragment;
146
- //#endregion
147
137
  export type { ConvertColumns, EventRevenueColumns, EventRevenueSql, SqlBinding, SqlDialect, SqlExpression, SqlFragment, StorageAmountCheckOptions };
package/dist/sql.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { r as Rate } from "./rate-DBPiYgT1.js";
2
- import { t as FactorTable } from "./reporting-tpGJbqYp.js";
3
- //#region src/sql/guard.d.ts
1
+ import { r as Rate } from "./rate-BvvZUdSu.js";
2
+ import { t as FactorTable } from "./reporting-jIBILvnr.js";
4
3
  type SqlBinding = string | number;
5
4
  /** Text with knex `?` placeholders and the values they bind, in order: `knex.raw(f.sql, f.bindings)`. */
6
5
  interface SqlFragment {
@@ -10,8 +9,6 @@ interface SqlFragment {
10
9
  /** An expression argument: SQL text written in code (a column reference), or a builder's SqlFragment. */
11
10
  type SqlExpression = string | SqlFragment;
12
11
  type SqlDialect = 'pg' | 'clickhouse';
13
- //#endregion
14
- //#region src/sql/amounts.d.ts
15
12
  /** The storage divisor of the currency in `codeExpr`, keyed by code (never `currency.decimal_digits`). */
16
13
  export declare function storageDivisorSql(codeExpr: SqlExpression, dialect?: SqlDialect): SqlFragment;
17
14
  /**
@@ -51,8 +48,6 @@ export declare function summaryAmountSql(totalsExpr: SqlExpression, key: string,
51
48
  export declare function rawAmountJsonSql(expr: SqlExpression): SqlFragment;
52
49
  /** A currency code column normalised the way Medusa stores it. */
53
50
  export declare function normalizeCurrencySql(expr: SqlExpression): SqlFragment;
54
- //#endregion
55
- //#region src/sql/clickhouse.d.ts
56
51
  interface EventRevenueColumns {
57
52
  /** Default `'value'` (stored units). */
58
53
  readonly value?: string;
@@ -79,8 +74,6 @@ interface EventRevenueSql {
79
74
  * (verified on 24.8).
80
75
  */
81
76
  export declare function chEventRevenueByCurrencySql(cols?: EventRevenueColumns): EventRevenueSql;
82
- //#endregion
83
- //#region src/sql/ddl.d.ts
84
77
  /** The column type of a stored amount. */
85
78
  export declare const STORAGE_AMOUNT_SQL_TYPE = "BIGINT";
86
79
  /** Lower-case three-letter currency codes only. */
@@ -108,8 +101,6 @@ export declare function storageAmountCheckSql(column: SqlExpression, options?: S
108
101
  export declare function usdToCreditsSql(expr: SqlExpression): SqlFragment;
109
102
  /** A yearly price as its monthly equivalent, half away from zero, the twin of `billing.monthlyEquivalent`. */
110
103
  export declare function monthlyEquivalentSql(expr: SqlExpression): SqlFragment;
111
- //#endregion
112
- //#region src/sql/fx.d.ts
113
104
  /**
114
105
  * A stored amount in the currency of `codeExpr` converted with the bound factor table
115
106
  * (`fx.storeFactors`): `output: 'stored'` rounds half away from zero to a storage unit of the
@@ -143,5 +134,4 @@ interface ConvertColumns {
143
134
  }
144
135
  /** `convertStoredSql` with the factor and rounding read from columns, so one statement converts many currencies. */
145
136
  export declare function convertStoredByColumnsSql(amountExpr: SqlExpression, cols: ConvertColumns): SqlFragment;
146
- //#endregion
147
137
  export type { ConvertColumns, EventRevenueColumns, EventRevenueSql, SqlBinding, SqlDialect, SqlExpression, SqlFragment, StorageAmountCheckOptions };
package/dist/sql.js CHANGED
@@ -1,7 +1,7 @@
1
- import { $ as describeValue, A as storageScale, E as resolveCurrency, Q as MoneyError, u as CURRENCIES } from "./money-WhnGiI00.js";
2
- import { r as checkRate } from "./rate-DicStBue.js";
3
- import { t as priceRoundingParams } from "./retail-1mu888J1.js";
4
- //#region src/sql/guard.ts
1
+ import { $ as describeValue, A as storageScale, E as resolveCurrency, Q as MoneyError, u as CURRENCIES } from "./money-BxbAw7BP.js";
2
+ import { r as checkRate } from "./rate-D6S2_wgZ.js";
3
+ import { t as priceRoundingParams } from "./retail-DXgs11ov.js";
4
+ // src/sql/guard.ts
5
5
  const STATEMENT_BREAKERS = /;|--|\/\*|\*\/|\0/;
6
6
  const refuse = (name, value) => new MoneyError("parse", `${name} must be a SQL expression written in code, got ${describeValue(value)}`);
7
7
  /** Code-written text, or `parse` when it is blank, could break out of the expression or holds a `?` placeholder. */
@@ -56,8 +56,7 @@ function dialectOf(value) {
56
56
  if (value !== "pg" && value !== "clickhouse") throw new MoneyError("parse", `Unknown SQL dialect: ${describeValue(value)}`);
57
57
  return value;
58
58
  }
59
- //#endregion
60
- //#region src/sql/lists.ts
59
+ // src/sql/lists.ts
61
60
  const quoted = (pick) => CURRENCIES.filter(pick).map((info) => `'${info.code}'`).join(",");
62
61
  /** Storage scale 1000: `'BHD','IQD','JOD','KWD','LYD','OMR','TND'`. */
63
62
  const SCALE_1000_CODES = quoted((info) => info.storageScale === 1e3);
@@ -69,8 +68,7 @@ const DISPLAY_3_CODES = quoted((info) => info.displayDigits === 3);
69
68
  const MEDUSA_0_CODES = quoted((info) => info.medusaDigits === 0);
70
69
  /** Medusa core `decimal_digits` 3 (payment-status epsilon 0.001). */
71
70
  const MEDUSA_3_CODES = quoted((info) => info.medusaDigits === 3);
72
- //#endregion
73
- //#region src/sql/amounts.ts
71
+ // src/sql/amounts.ts
74
72
  const CH_STORED_SCALE = 3;
75
73
  const CH_ROUND_SCALE = 12;
76
74
  /** The storage divisor of the currency in `codeExpr`, keyed by code (never `currency.decimal_digits`). */
@@ -144,8 +142,7 @@ function rawAmountJsonSql(expr) {
144
142
  function normalizeCurrencySql(expr) {
145
143
  return sql`lower(btrim(${expression(expr, "expr")}))`;
146
144
  }
147
- //#endregion
148
- //#region src/sql/clickhouse.ts
145
+ // src/sql/clickhouse.ts
149
146
  /**
150
147
  * The SELECT list and GROUP BY of per-currency purchase revenue in stored units. The event name
151
148
  * is a ClickHouse query parameter (`{revenue_event:String}`, pass `params` as `query_params`),
@@ -164,8 +161,7 @@ function chEventRevenueByCurrencySql(cols = {}) {
164
161
  params: { revenue_event: event }
165
162
  };
166
163
  }
167
- //#endregion
168
- //#region src/sql/ddl.ts
164
+ // src/sql/ddl.ts
169
165
  /** The column type of a stored amount. */
170
166
  const STORAGE_AMOUNT_SQL_TYPE = "BIGINT";
171
167
  /** A column for DDL, which Postgres never parameterises: a fragment with bindings is `parse`. */
@@ -207,8 +203,7 @@ function usdToCreditsSql(expr) {
207
203
  function monthlyEquivalentSql(expr) {
208
204
  return sql`ROUND((${expression(expr, "expr")})::numeric / 12)`;
209
205
  }
210
- //#endregion
211
- //#region src/sql/fx.ts
206
+ // src/sql/fx.ts
212
207
  function factorsJson(table) {
213
208
  resolveCurrency(table?.base, { allowHistoric: true });
214
209
  return JSON.stringify(table.factors);
@@ -267,5 +262,4 @@ function convertStoredByColumnsSql(amountExpr, cols) {
267
262
  const whole = sql`(FLOOR(${x} / ${major}) * ${major})`;
268
263
  return sql`(CASE WHEN ${retail} = 'none' THEN ${x} WHEN ${x} <= 0 THEN ${x} WHEN ${charm} IS NULL THEN CEIL(${x} / (100 * ${major})) * (100 * ${major}) WHEN ${x} <= ${whole} + ${charm} THEN ${whole} + ${charm} ELSE ${whole} + ${major} + ${charm} END)`;
269
264
  }
270
- //#endregion
271
265
  export { STORAGE_AMOUNT_SQL_TYPE, chEventRevenueByCurrencySql, convertStoredByColumnsSql, convertStoredSql, currencyCodeCheckSql, medusaEpsilonSql, monthlyEquivalentSql, normalizeCurrencySql, parseDecimalSql, rawAmountJsonSql, reportingCompleteSql, roundMajorSql, storageAmountCheckSql, storageDivisorSql, storedToMajorSql, summaryAmountSql, toReportingSql, usdToCreditsSql, withinEpsilonSql };