@amboras-dev/money 0.1.0 → 0.3.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 (80) hide show
  1. package/README.md +25 -10
  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-D7tm_t_o.cjs → allocate-AusholrC.cjs} +3 -4
  7. package/dist/{allocate-CdnhvAda.js → allocate-BBRfdaSC.js} +3 -4
  8. package/dist/{amount-DHtvZSSm.cjs → amount-CwFzcxUl.cjs} +29 -12
  9. package/dist/{amount-D7dj76nH.js → amount-DHFOK2Yd.js} +29 -12
  10. package/dist/{arithmetic-C-Q_aI49.js → arithmetic-C97-YafD.js} +4 -5
  11. package/dist/{arithmetic-Bq-8mSal.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-BnA1aLJk.cjs → format-92fzvTXY.cjs} +21 -6
  21. package/dist/{format-BdB7LEIp.js → format-BJC513u4.js} +16 -7
  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 +13 -12
  27. package/dist/index.d.cts +28 -22
  28. package/dist/index.d.ts +28 -22
  29. package/dist/index.js +11 -13
  30. package/dist/input.cjs +7 -10
  31. package/dist/input.d.cts +9 -16
  32. package/dist/input.d.ts +9 -16
  33. package/dist/input.js +7 -10
  34. package/dist/{iso-minor--gQWI1f2.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
  35. package/dist/{iso-minor-CtaiIifs.js → iso-minor-odkY-e6I.js} +2 -3
  36. package/dist/{medusa-OJ2TJOxt.cjs → medusa-CzVK0bth.cjs} +24 -4
  37. package/dist/{medusa-DuQ3-KoD.d.cts → medusa-DofdvIgQ.d.cts} +11 -4
  38. package/dist/{medusa-RwqxaDGq.d.ts → medusa-DrbYmD2Y.d.ts} +11 -4
  39. package/dist/{medusa-CmxCni-G.js → medusa-pKGlImn9.js} +19 -5
  40. package/dist/{money-CbhsT0fB.d.cts → money-BkMeYDEW.d.cts} +19 -9
  41. package/dist/{money-CbhsT0fB.d.ts → money-BkMeYDEW.d.ts} +19 -9
  42. package/dist/{money-CIgELekG.js → money-BxbAw7BP.js} +25 -21
  43. package/dist/{money-D5-vlv0h.cjs → money-DWBjuuEK.cjs} +42 -20
  44. package/dist/{number-text-C82oh6JB.js → number-text-Bj-gZXiF.js} +3 -4
  45. package/dist/{number-text-BpvN6NAo.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-CKVI_c-m.js → percent-CB3Ixjc_.js} +2 -3
  49. package/dist/{percent-Dt8vNIAW.cjs → percent-DABHiSBs.cjs} +2 -3
  50. package/dist/{rate-CmeTGNex.d.ts → rate-BvvZUdSu.d.ts} +1 -3
  51. package/dist/{rate-toyS3EMf.d.cts → rate-CEakW3ia.d.cts} +1 -3
  52. package/dist/{rate-DGPfB_jc.cjs → rate-CEjWTATc.cjs} +3 -4
  53. package/dist/{rate-lLPViBuM.js → rate-D6S2_wgZ.js} +3 -4
  54. package/dist/{reporting-5xby-Zas.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
  55. package/dist/{reporting-DEM97DhQ.d.cts → reporting-jIBILvnr.d.ts} +2 -4
  56. package/dist/{retail-BwcFJcVN.d.ts → retail-B04CjW3b.d.ts} +1 -3
  57. package/dist/{retail-DTk2XAMM.cjs → retail-CYGPU4ea.cjs} +4 -5
  58. package/dist/{retail-Mqd-sPMF.d.cts → retail-CmEyJQOH.d.cts} +1 -3
  59. package/dist/{retail-BsvpNv1F.js → retail-DXgs11ov.js} +4 -5
  60. package/dist/{rounding-oZ832yTD.cjs → rounding-4QKTRbMQ.cjs} +2 -3
  61. package/dist/{rounding-CVAPEfq_.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 +72675 -12
  67. package/dist/testing.d.cts +46 -11
  68. package/dist/testing.d.ts +46 -11
  69. package/dist/testing.js +72674 -13
  70. package/dist/{wire-CI3Sm1iC.js → wire-B4QU8O3W.js} +584 -114
  71. package/dist/wire-CVNicirK.d.ts +428 -0
  72. package/dist/wire-CtNJmWVP.d.cts +428 -0
  73. package/dist/{wire-DQZ6fA3c.cjs → wire-u2tmHY0Y.cjs} +649 -113
  74. package/dist/wire.cjs +12 -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
  79. package/dist/wire-Cd4Q1Jmm.d.ts +0 -269
  80. package/dist/wire-hWuixv3w.d.cts +0 -269
package/dist/sql.js CHANGED
@@ -1,7 +1,7 @@
1
- import { A as storageScale, E as resolveCurrency, Q as describeValue, Z as MoneyError, u as CURRENCIES } from "./money-CIgELekG.js";
2
- import { r as checkRate } from "./rate-lLPViBuM.js";
3
- import { t as priceRoundingParams } from "./retail-BsvpNv1F.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 };