@arki/money 0.0.0-stage → 0.0.4
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.
- package/LICENSE +21 -0
- package/README.md +238 -2
- package/dist/bag.d.ts +48 -0
- package/dist/bag.d.ts.map +1 -0
- package/dist/bag.js +110 -0
- package/dist/bag.js.map +1 -0
- package/dist/currency.d.ts +64 -0
- package/dist/currency.d.ts.map +1 -0
- package/dist/currency.js +148 -0
- package/dist/currency.js.map +1 -0
- package/dist/data/iso4217.d.ts +9 -0
- package/dist/data/iso4217.d.ts.map +1 -0
- package/dist/data/iso4217.js +11 -0
- package/dist/data/iso4217.js.map +1 -0
- package/dist/drizzle/config.d.ts +27 -0
- package/dist/drizzle/config.d.ts.map +1 -0
- package/dist/drizzle/config.js +16 -0
- package/dist/drizzle/config.js.map +1 -0
- package/dist/drizzle/mysql.d.ts +36 -0
- package/dist/drizzle/mysql.d.ts.map +1 -0
- package/dist/drizzle/mysql.js +45 -0
- package/dist/drizzle/mysql.js.map +1 -0
- package/dist/drizzle/pg.d.ts +38 -0
- package/dist/drizzle/pg.d.ts.map +1 -0
- package/dist/drizzle/pg.js +49 -0
- package/dist/drizzle/pg.js.map +1 -0
- package/dist/drizzle/sqlite.d.ts +38 -0
- package/dist/drizzle/sqlite.d.ts.map +1 -0
- package/dist/drizzle/sqlite.js +45 -0
- package/dist/drizzle/sqlite.js.map +1 -0
- package/dist/drizzle.d.ts +56 -0
- package/dist/drizzle.d.ts.map +1 -0
- package/dist/drizzle.js +77 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/exact.d.ts +20 -0
- package/dist/exact.d.ts.map +1 -0
- package/dist/exact.js +23 -0
- package/dist/exact.js.map +1 -0
- package/dist/exchange.d.ts +84 -0
- package/dist/exchange.d.ts.map +1 -0
- package/dist/exchange.js +215 -0
- package/dist/exchange.js.map +1 -0
- package/dist/format.d.ts +41 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +122 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/columns.d.ts +25 -0
- package/dist/internal/columns.d.ts.map +1 -0
- package/dist/internal/columns.js +47 -0
- package/dist/internal/columns.js.map +1 -0
- package/dist/internal/units.d.ts +66 -0
- package/dist/internal/units.d.ts.map +1 -0
- package/dist/internal/units.js +205 -0
- package/dist/internal/units.js.map +1 -0
- package/dist/money.d.ts +180 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +577 -0
- package/dist/money.js.map +1 -0
- package/dist/parse.d.ts +53 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +222 -0
- package/dist/parse.js.map +1 -0
- package/dist/provider.d.ts +22 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +56 -0
- package/dist/provider.js.map +1 -0
- package/dist/rational.d.ts +67 -0
- package/dist/rational.d.ts.map +1 -0
- package/dist/rational.js +169 -0
- package/dist/rational.js.map +1 -0
- package/dist/stripe.d.ts +37 -0
- package/dist/stripe.d.ts.map +1 -0
- package/dist/stripe.js +75 -0
- package/dist/stripe.js.map +1 -0
- package/dist/zod.d.ts +54 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +96 -0
- package/dist/zod.js.map +1 -0
- package/package.json +137 -4
- package/src/bag.ts +128 -0
- package/src/currency.ts +174 -0
- package/src/data/iso4217.ts +13 -0
- package/src/drizzle/config.ts +39 -0
- package/src/drizzle/mysql.ts +61 -0
- package/src/drizzle/pg.ts +64 -0
- package/src/drizzle/sqlite.ts +61 -0
- package/src/errors.ts +61 -0
- package/src/exact.ts +29 -0
- package/src/exchange.ts +280 -0
- package/src/format.ts +148 -0
- package/src/index.ts +16 -0
- package/src/internal/columns.ts +74 -0
- package/src/internal/units.ts +223 -0
- package/src/money.ts +692 -0
- package/src/parse.ts +278 -0
- package/src/provider.ts +67 -0
- package/src/rational.ts +214 -0
- package/src/stripe.ts +84 -0
- package/src/zod.ts +123 -0
package/dist/currency.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currencies. The ISO 4217 list ships with the package, so a currency's number
|
|
3
|
+
* of decimals is the same on every runtime and device. `Intl` is only used for
|
|
4
|
+
* display (see `@arki/money/format`); it accepts made-up codes such as `ZZZ`
|
|
5
|
+
* and its decimals can differ from ISO, so it never decides arithmetic.
|
|
6
|
+
*
|
|
7
|
+
* `Currency.of('EUR')` returns the same object every time, so comparing two
|
|
8
|
+
* currencies is a pointer check on the hot path.
|
|
9
|
+
*/
|
|
10
|
+
import { InvalidArgumentError } from '@arki/math/errors';
|
|
11
|
+
import { ISO_4217 } from './data/iso4217.js';
|
|
12
|
+
import { CurrencyMismatchError, UnknownCurrencyError } from './errors.js';
|
|
13
|
+
import { MAX_SCALE } from './internal/units.js';
|
|
14
|
+
export { ISO_4217_VERSION } from './data/iso4217.js';
|
|
15
|
+
const BRAND = Symbol('Currency');
|
|
16
|
+
const CUSTOM_CODE = /^[a-z][\w.:-]{0,31}$/i;
|
|
17
|
+
let byCode;
|
|
18
|
+
let byNumeric;
|
|
19
|
+
/** An immutable currency: its code, its ISO numeric code and its number of decimals. */
|
|
20
|
+
export class Currency {
|
|
21
|
+
/** `'EUR'`. */
|
|
22
|
+
code;
|
|
23
|
+
/** Three-digit ISO numeric code as a string, so `'008'` keeps its zeros. `undefined` for most custom currencies. */
|
|
24
|
+
numeric;
|
|
25
|
+
/** Number of decimals: 2 for EUR, 0 for JPY, 3 for KWD. ISO codes without minor units (XAU, XTS) use 0. */
|
|
26
|
+
scale;
|
|
27
|
+
/** `true` for a currency from the shipped ISO 4217 table. */
|
|
28
|
+
iso;
|
|
29
|
+
constructor(code, numeric, scale, iso, brand) {
|
|
30
|
+
if (brand !== BRAND)
|
|
31
|
+
throw new TypeError('Use Currency.of(code) or Currency.custom(definition)');
|
|
32
|
+
this.code = code;
|
|
33
|
+
this.numeric = numeric;
|
|
34
|
+
this.scale = scale;
|
|
35
|
+
this.iso = iso;
|
|
36
|
+
Object.freeze(this);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The ISO 4217 currency with this upper-case code: `Currency.of('EUR')`.
|
|
40
|
+
* Throws `UnknownCurrencyError` for anything not in the table, including `'eur'`.
|
|
41
|
+
*/
|
|
42
|
+
static of(code) {
|
|
43
|
+
const found = Currency.table().get(code);
|
|
44
|
+
if (found === undefined || !hasCode(found, code))
|
|
45
|
+
throw new UnknownCurrencyError(String(code));
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
/** The ISO 4217 currency with this numeric code: `Currency.fromNumeric('978')` or `(978)` → EUR. */
|
|
49
|
+
static fromNumeric(numeric) {
|
|
50
|
+
const key = typeof numeric === 'number' ? String(numeric).padStart(3, '0') : numeric;
|
|
51
|
+
if (byNumeric === undefined) {
|
|
52
|
+
byNumeric = new Map();
|
|
53
|
+
for (const currency of Currency.table().values()) {
|
|
54
|
+
if (currency.numeric !== undefined)
|
|
55
|
+
byNumeric.set(currency.numeric, currency);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const found = byNumeric.get(key);
|
|
59
|
+
if (found === undefined)
|
|
60
|
+
throw new UnknownCurrencyError(key);
|
|
61
|
+
return found;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A currency that is not in ISO 4217: crypto, loyalty points, a withdrawn
|
|
65
|
+
* currency you still hold data in. It is not registered anywhere; keep the
|
|
66
|
+
* object and pass it where you would pass a code. Two custom currencies with
|
|
67
|
+
* the same code and scale are treated as the same currency.
|
|
68
|
+
*/
|
|
69
|
+
static custom(definition) {
|
|
70
|
+
const { code, scale, numeric } = definition;
|
|
71
|
+
if (typeof code !== 'string' || !CUSTOM_CODE.test(code)) {
|
|
72
|
+
throw new InvalidArgumentError(`A currency code is 1–32 letters, digits or ". _ : -", starting with a letter; got ${JSON.stringify(code)}`);
|
|
73
|
+
}
|
|
74
|
+
if (Currency.table().has(code)) {
|
|
75
|
+
throw new InvalidArgumentError(`${code} is an ISO 4217 currency; use Currency.of('${code}')`);
|
|
76
|
+
}
|
|
77
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {
|
|
78
|
+
throw new InvalidArgumentError(`A currency scale is a whole number from 0 to ${MAX_SCALE}, got ${scale}`);
|
|
79
|
+
}
|
|
80
|
+
if (numeric !== undefined && !/^\d{3}$/.test(numeric)) {
|
|
81
|
+
throw new InvalidArgumentError(`A numeric currency code has three digits, got ${JSON.stringify(numeric)}`);
|
|
82
|
+
}
|
|
83
|
+
return new Currency(code, numeric, scale, false, BRAND);
|
|
84
|
+
}
|
|
85
|
+
/** `true` when `code` is in the shipped ISO 4217 table. */
|
|
86
|
+
static isKnown(code) {
|
|
87
|
+
return Currency.table().has(code);
|
|
88
|
+
}
|
|
89
|
+
/** Every ISO 4217 code in the shipped table, sorted. */
|
|
90
|
+
static codes() {
|
|
91
|
+
return [...Currency.table().keys()];
|
|
92
|
+
}
|
|
93
|
+
/** Same code and same scale. */
|
|
94
|
+
eq(other) {
|
|
95
|
+
return this === other || (this.code === other.code && this.scale === other.scale);
|
|
96
|
+
}
|
|
97
|
+
toString() {
|
|
98
|
+
return this.code;
|
|
99
|
+
}
|
|
100
|
+
toJSON() {
|
|
101
|
+
return this.code;
|
|
102
|
+
}
|
|
103
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
104
|
+
return `Currency(${this.code})`;
|
|
105
|
+
}
|
|
106
|
+
[Symbol.for('Deno.customInspect')]() {
|
|
107
|
+
return `Currency(${this.code})`;
|
|
108
|
+
}
|
|
109
|
+
/** Decodes the packed table on first use. */
|
|
110
|
+
static table() {
|
|
111
|
+
if (byCode !== undefined)
|
|
112
|
+
return byCode;
|
|
113
|
+
const table = new Map();
|
|
114
|
+
for (let i = 0; i < ISO_4217.length; i += 7) {
|
|
115
|
+
const code = ISO_4217.slice(i, i + 3);
|
|
116
|
+
const digit = ISO_4217.charAt(i + 6);
|
|
117
|
+
table.set(code, new Currency(code, ISO_4217.slice(i + 3, i + 6), digit === '-' ? 0 : Number(digit), true, BRAND));
|
|
118
|
+
}
|
|
119
|
+
byCode = table;
|
|
120
|
+
return table;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function hasCode(currency, code) {
|
|
124
|
+
return currency.code === code;
|
|
125
|
+
}
|
|
126
|
+
/** Accepts a `Currency` or an ISO code. */
|
|
127
|
+
export function toCurrency(currency) {
|
|
128
|
+
if (currency instanceof Currency)
|
|
129
|
+
return currency;
|
|
130
|
+
if (typeof currency !== 'string')
|
|
131
|
+
throw new TypeError('Expected a currency code or a Currency');
|
|
132
|
+
return Currency.of(currency);
|
|
133
|
+
}
|
|
134
|
+
/** Finds a currency by code among `custom`, then in the ISO table. */
|
|
135
|
+
export function resolveCurrency(code, custom) {
|
|
136
|
+
if (custom !== undefined) {
|
|
137
|
+
for (const currency of custom)
|
|
138
|
+
if (currency.code === code)
|
|
139
|
+
return currency;
|
|
140
|
+
}
|
|
141
|
+
return Currency.of(code);
|
|
142
|
+
}
|
|
143
|
+
/** Throws `CurrencyMismatchError` unless the two are the same currency. */
|
|
144
|
+
export function assertSameCurrency(a, b) {
|
|
145
|
+
if (a !== b && (a.code !== b.code || a.scale !== b.scale))
|
|
146
|
+
throw new CurrencyMismatchError(a.code, b.code);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=currency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,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AAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,MAAM,QAAQ,IAAI,MAAM;YAAE,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI;gBAAE,OAAO,QAAQ,CAAC;IAC7E,CAAC;IACD,OAAO,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,CAAW,EAAE,CAAW;IACzD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,qBAAqB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Publication date of the ISO 4217 list this table was built from. */
|
|
2
|
+
export declare const ISO_4217_VERSION = "2026-09-17";
|
|
3
|
+
/**
|
|
4
|
+
* Every active ISO 4217 currency, 7 characters each: alphabetic code (3),
|
|
5
|
+
* numeric code (3), minor-unit digits (1). '-' marks a code with no minor
|
|
6
|
+
* unit in ISO (gold, the test code, ...); those are treated as 0 digits.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ISO_4217 = "AED7842AFN9712ALL0082AMD0512AOA9732ARS0322AUD0362AWG5332AZN9442BAM9772BBD0522BDT0502BHD0483BIF1080BMD0602BND0962BOB0682BOV9842BRL9862BSD0442BTN0642BWP0722BYN9332BZD0842CAD1242CDF9762CHE9472CHF7562CHW9482CLF9904CLP1520CNY1562COP1702COU9702CRC1882CUP1922CVE1322CZK2032DJF2620DKK2082DOP2142DZD0122EGP8182ERN2322ETB2302EUR9782FJD2422FKP2382GBP8262GEL9812GHS9362GIP2922GMD2702GNF3240GTQ3202GYD3282HKD3442HNL3402HTG3322HUF3482IDR3602ILS3762INR3562IQD3683IRR3642ISK3520JMD3882JOD4003JPY3920KES4042KGS4172KHR1162KMF1740KPW4082KRW4100KWD4143KYD1362KZT3982LAK4182LBP4222LKR1442LRD4302LSL4262LYD4343MAD5042MDL4982MGA9692MKD8072MMK1042MNT4962MOP4462MRU9292MUR4802MVR4622MWK4542MXN4842MXV9792MYR4582MZN9432NAD5162NGN5662NIO5582NOK5782NPR5242NZD5542OMR5123PAB5902PEN6042PGK5982PHP6082PKR5862PLN9852PYG6000QAR6342RON9462RSD9412RUB6432RWF6460SAR6822SBD0902SCR6902SDG9382SEK7522SGD7022SHP6542SLE9252SOS7062SRD9682SSP7282STN9302SVC2222SYP7602SZL7482THB7642TJS9722TMT9342TND7883TOP7762TRY9492TTD7802TWD9012TZS8342UAH9802UGX8000USD8402USN9972UYI9400UYU8582UYW9274UZS8602VED9262VES9282VND7040VUV5480WST8822XAD3962XAF9500XAG961-XAU959-XBA955-XBB956-XBC957-XBD958-XCD9512XCG5322XDR960-XOF9520XPD964-XPF9530XPT962-XSU994-XTS963-XUA965-XXX999-YER8862ZAR7102ZMW9672ZWG9242";
|
|
9
|
+
//# sourceMappingURL=iso4217.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iso4217.d.ts","sourceRoot":"","sources":["../../src/data/iso4217.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,QAAQ,muCAC6sC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generated by scripts/generate-iso4217.mjs. Do not edit by hand.
|
|
2
|
+
// Source: ISO 4217 list one, published by SIX on 2026-09-17. 178 currencies.
|
|
3
|
+
/** Publication date of the ISO 4217 list this table was built from. */
|
|
4
|
+
export const ISO_4217_VERSION = '2026-09-17';
|
|
5
|
+
/**
|
|
6
|
+
* Every active ISO 4217 currency, 7 characters each: alphabetic code (3),
|
|
7
|
+
* numeric code (3), minor-unit digits (1). '-' marks a code with no minor
|
|
8
|
+
* unit in ISO (gold, the test code, ...); those are treated as 0 digits.
|
|
9
|
+
*/
|
|
10
|
+
export const ISO_4217 = 'AED7842AFN9712ALL0082AMD0512AOA9732ARS0322AUD0362AWG5332AZN9442BAM9772BBD0522BDT0502BHD0483BIF1080BMD0602BND0962BOB0682BOV9842BRL9862BSD0442BTN0642BWP0722BYN9332BZD0842CAD1242CDF9762CHE9472CHF7562CHW9482CLF9904CLP1520CNY1562COP1702COU9702CRC1882CUP1922CVE1322CZK2032DJF2620DKK2082DOP2142DZD0122EGP8182ERN2322ETB2302EUR9782FJD2422FKP2382GBP8262GEL9812GHS9362GIP2922GMD2702GNF3240GTQ3202GYD3282HKD3442HNL3402HTG3322HUF3482IDR3602ILS3762INR3562IQD3683IRR3642ISK3520JMD3882JOD4003JPY3920KES4042KGS4172KHR1162KMF1740KPW4082KRW4100KWD4143KYD1362KZT3982LAK4182LBP4222LKR1442LRD4302LSL4262LYD4343MAD5042MDL4982MGA9692MKD8072MMK1042MNT4962MOP4462MRU9292MUR4802MVR4622MWK4542MXN4842MXV9792MYR4582MZN9432NAD5162NGN5662NIO5582NOK5782NPR5242NZD5542OMR5123PAB5902PEN6042PGK5982PHP6082PKR5862PLN9852PYG6000QAR6342RON9462RSD9412RUB6432RWF6460SAR6822SBD0902SCR6902SDG9382SEK7522SGD7022SHP6542SLE9252SOS7062SRD9682SSP7282STN9302SVC2222SYP7602SZL7482THB7642TJS9722TMT9342TND7883TOP7762TRY9492TTD7802TWD9012TZS8342UAH9802UGX8000USD8402USN9972UYI9400UYU8582UYW9274UZS8602VED9262VES9282VND7040VUV5480WST8822XAD3962XAF9500XAG961-XAU959-XBA955-XBB956-XBC957-XBD958-XCD9512XCG5322XDR960-XOF9520XPD964-XPF9530XPT962-XSU994-XTS963-XUA965-XXX999-YER8862ZAR7102ZMW9672ZWG9242';
|
|
11
|
+
//# sourceMappingURL=iso4217.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iso4217.js","sourceRoot":"","sources":["../../src/data/iso4217.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,6EAA6E;AAE7E,uEAAuE;AACvE,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GACnB,guCAAguC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Column options shared by every SQL dialect. */
|
|
2
|
+
import type { Currency, CurrencyLike } from '../currency.js';
|
|
3
|
+
export type MoneyMinorConfig<C extends string> = {
|
|
4
|
+
currency: CurrencyLike<C>;
|
|
5
|
+
/** Decimals the stored integer carries. Defaults to the currency's. */
|
|
6
|
+
scale?: number;
|
|
7
|
+
};
|
|
8
|
+
export type MoneyDecimalConfig<C extends string> = {
|
|
9
|
+
currency: CurrencyLike<C>;
|
|
10
|
+
/** Total digits, as in `numeric(precision, scale)`. Default 19. Ignored by SQLite. */
|
|
11
|
+
precision?: number;
|
|
12
|
+
/** Decimals stored. Defaults to the currency's. */
|
|
13
|
+
scale?: number;
|
|
14
|
+
};
|
|
15
|
+
export type MoneyJsonConfig = {
|
|
16
|
+
/** Custom currencies to resolve by code on read. */
|
|
17
|
+
currencies?: readonly Currency[];
|
|
18
|
+
};
|
|
19
|
+
/** Validates a column config once, when the table is defined. */
|
|
20
|
+
export declare function resolveColumn<C extends string>(config: {
|
|
21
|
+
currency: CurrencyLike<C>;
|
|
22
|
+
scale?: number;
|
|
23
|
+
} | undefined, column: string): {
|
|
24
|
+
currency: Currency<C>;
|
|
25
|
+
scale: number;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/drizzle/config.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAK7D,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,IAAI;IAC/C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1B,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI;IACjD,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1B,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,oDAAoD;IACpD,UAAU,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;CAClC,CAAC;AAEF,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,MAAM,EAAE;IAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EACjE,MAAM,EAAE,MAAM,GACb;IAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAQ1C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Column options shared by every SQL dialect. */
|
|
2
|
+
import { toCurrency } from '../currency.js';
|
|
3
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
4
|
+
import { MAX_SCALE } from '../internal/units.js';
|
|
5
|
+
/** Validates a column config once, when the table is defined. */
|
|
6
|
+
export function resolveColumn(config, column) {
|
|
7
|
+
if (config === undefined)
|
|
8
|
+
throw new InvalidArgumentError(`${column} needs a config with a currency`);
|
|
9
|
+
const currency = toCurrency(config.currency);
|
|
10
|
+
const scale = config.scale ?? currency.scale;
|
|
11
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {
|
|
12
|
+
throw new InvalidArgumentError(`${column}: scale must be a whole number from 0 to ${MAX_SCALE}, got ${scale}`);
|
|
13
|
+
}
|
|
14
|
+
return { currency, scale };
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/drizzle/config.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAGlD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAqBjD,iEAAiE;AACjE,MAAM,UAAU,aAAa,CAC3B,MAAiE,EACjE,MAAc;IAEd,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,IAAI,oBAAoB,CAAC,GAAG,MAAM,iCAAiC,CAAC,CAAC;IACrG,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC;IAC7C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;QAC/D,MAAM,IAAI,oBAAoB,CAAC,GAAG,MAAM,4CAA4C,SAAS,SAAS,KAAK,EAAE,CAAC,CAAC;IACjH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for MySQL and MariaDB that read and write `Money`.
|
|
3
|
+
* Optional: needs `drizzle-orm` 1.x installed.
|
|
4
|
+
*
|
|
5
|
+
* - `moneyMinor(name, { currency })` — a `bigint` column of minor units ↔ `Money<C>`.
|
|
6
|
+
* - `moneyDecimal(name, { currency, precision, scale })` — a `decimal` column ↔ `Money<C>`.
|
|
7
|
+
* - `moneyJson(name)` — a `json` column of `{ amount, currency }` ↔ `Money` in any currency.
|
|
8
|
+
*
|
|
9
|
+
* `mysql2` returns `DECIMAL` as text and `JSON` as parsed objects by default,
|
|
10
|
+
* and the `bigint` column declares a text codec, so no value passes through a
|
|
11
|
+
* float. If a driver still returns a big integer as an unsafe `number`, reading
|
|
12
|
+
* it throws instead of returning a wrong amount.
|
|
13
|
+
*/
|
|
14
|
+
import type { IntegerDriverValue } from '../internal/columns.js';
|
|
15
|
+
import type { Money } from '../money.js';
|
|
16
|
+
import type { MoneyDecimalConfig, MoneyJsonConfig, MoneyMinorConfig } from './config.js';
|
|
17
|
+
export type { MoneyDecimalConfig, MoneyJsonConfig, MoneyMinorConfig } from './config.js';
|
|
18
|
+
/** `bigint` column ↔ `Money<C>` in one fixed currency. */
|
|
19
|
+
export declare function moneyMinor<const C extends string>(name: string, config: MoneyMinorConfig<C>): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
20
|
+
dataType: 'custom';
|
|
21
|
+
data: Money<C>;
|
|
22
|
+
driverParam: IntegerDriverValue;
|
|
23
|
+
}>;
|
|
24
|
+
/** `decimal(precision, scale)` column ↔ `Money<C>` in one fixed currency. */
|
|
25
|
+
export declare function moneyDecimal<const C extends string>(name: string, config: MoneyDecimalConfig<C>): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
26
|
+
dataType: 'custom';
|
|
27
|
+
data: Money<C>;
|
|
28
|
+
driverParam: string | number;
|
|
29
|
+
}>;
|
|
30
|
+
/** `json` column of `{ amount, currency }` ↔ `Money` in any currency. */
|
|
31
|
+
export declare function moneyJson(name: string, config?: MoneyJsonConfig): import("drizzle-orm/mysql-core").MySqlCustomColumnBuilder<{
|
|
32
|
+
dataType: 'custom';
|
|
33
|
+
data: Money<string>;
|
|
34
|
+
driverParam: unknown;
|
|
35
|
+
}>;
|
|
36
|
+
//# sourceMappingURL=mysql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/drizzle/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAWzF,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEzF,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;;;;GAQ3F;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;;GAQ/F;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,eAAoB;;;;GAMnE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for MySQL and MariaDB that read and write `Money`.
|
|
3
|
+
* Optional: needs `drizzle-orm` 1.x installed.
|
|
4
|
+
*
|
|
5
|
+
* - `moneyMinor(name, { currency })` — a `bigint` column of minor units ↔ `Money<C>`.
|
|
6
|
+
* - `moneyDecimal(name, { currency, precision, scale })` — a `decimal` column ↔ `Money<C>`.
|
|
7
|
+
* - `moneyJson(name)` — a `json` column of `{ amount, currency }` ↔ `Money` in any currency.
|
|
8
|
+
*
|
|
9
|
+
* `mysql2` returns `DECIMAL` as text and `JSON` as parsed objects by default,
|
|
10
|
+
* and the `bigint` column declares a text codec, so no value passes through a
|
|
11
|
+
* float. If a driver still returns a big integer as an unsafe `number`, reading
|
|
12
|
+
* it throws instead of returning a wrong amount.
|
|
13
|
+
*/
|
|
14
|
+
import { customType } from 'drizzle-orm/mysql-core';
|
|
15
|
+
import { decimalFromDriver, decimalToDriver, jsonFromDriver, jsonToDriver, minorFromDriver, minorToDriver, } from '../internal/columns.js';
|
|
16
|
+
import { resolveColumn } from './config.js';
|
|
17
|
+
/** `bigint` column ↔ `Money<C>` in one fixed currency. */
|
|
18
|
+
export function moneyMinor(name, config) {
|
|
19
|
+
const { currency, scale } = resolveColumn(config, 'moneyMinor');
|
|
20
|
+
return customType({
|
|
21
|
+
dataType: () => 'bigint',
|
|
22
|
+
codec: 'bigint:string',
|
|
23
|
+
toDriver: value => String(minorToDriver(value, currency, scale)),
|
|
24
|
+
fromDriver: value => minorFromDriver(value, currency, scale),
|
|
25
|
+
})(name, config);
|
|
26
|
+
}
|
|
27
|
+
/** `decimal(precision, scale)` column ↔ `Money<C>` in one fixed currency. */
|
|
28
|
+
export function moneyDecimal(name, config) {
|
|
29
|
+
const { currency, scale } = resolveColumn(config, 'moneyDecimal');
|
|
30
|
+
const precision = config.precision ?? 19;
|
|
31
|
+
return customType({
|
|
32
|
+
dataType: () => `decimal(${precision}, ${scale})`,
|
|
33
|
+
toDriver: value => decimalToDriver(value, currency, scale),
|
|
34
|
+
fromDriver: value => decimalFromDriver(value, currency, scale),
|
|
35
|
+
})(name, config);
|
|
36
|
+
}
|
|
37
|
+
/** `json` column of `{ amount, currency }` ↔ `Money` in any currency. */
|
|
38
|
+
export function moneyJson(name, config = {}) {
|
|
39
|
+
return customType({
|
|
40
|
+
dataType: () => 'json',
|
|
41
|
+
toDriver: jsonToDriver,
|
|
42
|
+
fromDriver: value => jsonFromDriver(value, config.currencies),
|
|
43
|
+
})(name, config);
|
|
44
|
+
}
|
|
45
|
+
//# source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AAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;QAC1D,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;KAC/D,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,MAAM,GAAoB,EAAE;IAClE,OAAO,UAAU,CAAgE;QAC/E,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;QACtB,QAAQ,EAAE,YAAY;QACtB,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;KAC9D,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for Postgres that read and write `Money`. Optional: needs
|
|
3
|
+
* `drizzle-orm` 1.x installed.
|
|
4
|
+
*
|
|
5
|
+
* - `moneyMinor(name, { currency })` — a `bigint` column of minor units for one
|
|
6
|
+
* fixed currency ↔ `Money<C>`. Best for sums in SQL.
|
|
7
|
+
* - `moneyDecimal(name, { currency, precision, scale })` — a `numeric` column ↔
|
|
8
|
+
* `Money<C>`. Readable in SQL tools; holds more decimals than the currency.
|
|
9
|
+
* - `moneyJson(name)` — a `jsonb` column of `{ amount, currency }` ↔ `Money`
|
|
10
|
+
* in any currency. For prices that vary by row.
|
|
11
|
+
*
|
|
12
|
+
* The columns declare text codecs, so every driver (node-postgres,
|
|
13
|
+
* postgres.js, PGlite, Bun SQL) hands back text and no value passes through a
|
|
14
|
+
* float. Writing a `Money` in another currency, or with more decimals than the
|
|
15
|
+
* column holds, throws instead of storing a wrong value.
|
|
16
|
+
*/
|
|
17
|
+
import type { Money } from '../money.js';
|
|
18
|
+
import type { MoneyDecimalConfig, MoneyJsonConfig, MoneyMinorConfig } from './config.js';
|
|
19
|
+
export type { MoneyDecimalConfig, MoneyJsonConfig, MoneyMinorConfig } from './config.js';
|
|
20
|
+
/** `bigint` column ↔ `Money<C>` in one fixed currency. */
|
|
21
|
+
export declare function moneyMinor<const C extends string>(name: string, config: MoneyMinorConfig<C>): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
22
|
+
dataType: 'custom';
|
|
23
|
+
data: Money<C>;
|
|
24
|
+
driverParam: string;
|
|
25
|
+
}>;
|
|
26
|
+
/** `numeric(precision, scale)` column ↔ `Money<C>` in one fixed currency. */
|
|
27
|
+
export declare function moneyDecimal<const C extends string>(name: string, config: MoneyDecimalConfig<C>): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
28
|
+
dataType: 'custom';
|
|
29
|
+
data: Money<C>;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** `jsonb` column of `{ amount, currency }` ↔ `Money` in any currency. */
|
|
33
|
+
export declare function moneyJson(name: string, config?: MoneyJsonConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
34
|
+
dataType: 'custom';
|
|
35
|
+
data: Money<string>;
|
|
36
|
+
driverParam: string;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=pg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/drizzle/pg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAWzF,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEzF,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;;;;GAQ3F;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;;GAS/F;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,eAAoB;;;;GAMnE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for Postgres that read and write `Money`. Optional: needs
|
|
3
|
+
* `drizzle-orm` 1.x installed.
|
|
4
|
+
*
|
|
5
|
+
* - `moneyMinor(name, { currency })` — a `bigint` column of minor units for one
|
|
6
|
+
* fixed currency ↔ `Money<C>`. Best for sums in SQL.
|
|
7
|
+
* - `moneyDecimal(name, { currency, precision, scale })` — a `numeric` column ↔
|
|
8
|
+
* `Money<C>`. Readable in SQL tools; holds more decimals than the currency.
|
|
9
|
+
* - `moneyJson(name)` — a `jsonb` column of `{ amount, currency }` ↔ `Money`
|
|
10
|
+
* in any currency. For prices that vary by row.
|
|
11
|
+
*
|
|
12
|
+
* The columns declare text codecs, so every driver (node-postgres,
|
|
13
|
+
* postgres.js, PGlite, Bun SQL) hands back text and no value passes through a
|
|
14
|
+
* float. Writing a `Money` in another currency, or with more decimals than the
|
|
15
|
+
* column holds, throws instead of storing a wrong value.
|
|
16
|
+
*/
|
|
17
|
+
import { customType } from 'drizzle-orm/pg-core';
|
|
18
|
+
import { decimalFromDriver, decimalToDriver, jsonFromDriver, jsonToDriver, minorFromDriver, minorToDriver, } from '../internal/columns.js';
|
|
19
|
+
import { resolveColumn } from './config.js';
|
|
20
|
+
/** `bigint` column ↔ `Money<C>` in one fixed currency. */
|
|
21
|
+
export function moneyMinor(name, config) {
|
|
22
|
+
const { currency, scale } = resolveColumn(config, 'moneyMinor');
|
|
23
|
+
return customType({
|
|
24
|
+
dataType: () => 'bigint',
|
|
25
|
+
codec: 'bigint:string',
|
|
26
|
+
toDriver: value => String(minorToDriver(value, currency, scale)),
|
|
27
|
+
fromDriver: value => minorFromDriver(value, currency, scale),
|
|
28
|
+
})(name, config);
|
|
29
|
+
}
|
|
30
|
+
/** `numeric(precision, scale)` column ↔ `Money<C>` in one fixed currency. */
|
|
31
|
+
export function moneyDecimal(name, config) {
|
|
32
|
+
const { currency, scale } = resolveColumn(config, 'moneyDecimal');
|
|
33
|
+
const precision = config.precision ?? 19;
|
|
34
|
+
return customType({
|
|
35
|
+
dataType: () => `numeric(${precision}, ${scale})`,
|
|
36
|
+
codec: 'numeric',
|
|
37
|
+
toDriver: value => decimalToDriver(value, currency, scale),
|
|
38
|
+
fromDriver: value => decimalFromDriver(value, currency, scale),
|
|
39
|
+
})(name, config);
|
|
40
|
+
}
|
|
41
|
+
/** `jsonb` column of `{ amount, currency }` ↔ `Money` in any currency. */
|
|
42
|
+
export function moneyJson(name, config = {}) {
|
|
43
|
+
return customType({
|
|
44
|
+
dataType: () => 'jsonb',
|
|
45
|
+
toDriver: jsonToDriver,
|
|
46
|
+
fromDriver: value => jsonFromDriver(value, config.currencies),
|
|
47
|
+
})(name, config);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=pg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.js","sourceRoot":"","sources":["../../src/drizzle/pg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAIjD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,eAAe,EACf,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAyB,IAAY,EAAE,MAA2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AAC,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;KAC9D,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for SQLite (libSQL, Turso, better-sqlite3, Bun SQLite,
|
|
3
|
+
* Cloudflare D1, Expo SQLite) that read and write `Money`. Optional: needs
|
|
4
|
+
* `drizzle-orm` 1.x installed.
|
|
5
|
+
*
|
|
6
|
+
* - `moneyMinor(name, { currency })` — an `integer` column of minor units ↔ `Money<C>`.
|
|
7
|
+
* - `moneyDecimal(name, { currency, scale })` — a `text` column of exact decimal
|
|
8
|
+
* text ↔ `Money<C>`. SQLite has no exact decimal type, so text keeps every digit.
|
|
9
|
+
* - `moneyJson(name)` — a `text` column of `{ amount, currency }` JSON ↔ `Money`.
|
|
10
|
+
*
|
|
11
|
+
* SQLite integers are 64-bit, but most drivers return JavaScript numbers.
|
|
12
|
+
* Amounts up to 2^53 minor units are exact. A bigger stored amount throws on
|
|
13
|
+
* read instead of becoming a wrong value; to read those, switch the driver to
|
|
14
|
+
* big integers (libSQL `intMode: 'bigint'`, better-sqlite3 `safeIntegers()`).
|
|
15
|
+
*/
|
|
16
|
+
import type { IntegerDriverValue } from '../internal/columns.js';
|
|
17
|
+
import type { Money } from '../money.js';
|
|
18
|
+
import type { MoneyDecimalConfig, MoneyJsonConfig, MoneyMinorConfig } from './config.js';
|
|
19
|
+
export type { MoneyDecimalConfig, MoneyJsonConfig, MoneyMinorConfig } from './config.js';
|
|
20
|
+
/** `integer` column ↔ `Money<C>` in one fixed currency. Writes a `bigint` past 2^53. */
|
|
21
|
+
export declare function moneyMinor<const C extends string>(name: string, config: MoneyMinorConfig<C>): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
|
|
22
|
+
dataType: 'custom';
|
|
23
|
+
data: Money<C>;
|
|
24
|
+
driverParam: IntegerDriverValue;
|
|
25
|
+
}>;
|
|
26
|
+
/** `text` column of exact decimal text ↔ `Money<C>` in one fixed currency. */
|
|
27
|
+
export declare function moneyDecimal<const C extends string>(name: string, config: MoneyDecimalConfig<C>): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
|
|
28
|
+
dataType: 'custom';
|
|
29
|
+
data: Money<C>;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** `text` column of `{ amount, currency }` JSON ↔ `Money` in any currency. */
|
|
33
|
+
export declare function moneyJson(name: string, config?: MoneyJsonConfig): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
|
|
34
|
+
dataType: 'custom';
|
|
35
|
+
data: Money<string>;
|
|
36
|
+
driverParam: string;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/drizzle/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAWzF,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEzF,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;;;;GAO3F;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;;GAO/F;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,eAAoB;;;;GAMnE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for SQLite (libSQL, Turso, better-sqlite3, Bun SQLite,
|
|
3
|
+
* Cloudflare D1, Expo SQLite) that read and write `Money`. Optional: needs
|
|
4
|
+
* `drizzle-orm` 1.x installed.
|
|
5
|
+
*
|
|
6
|
+
* - `moneyMinor(name, { currency })` — an `integer` column of minor units ↔ `Money<C>`.
|
|
7
|
+
* - `moneyDecimal(name, { currency, scale })` — a `text` column of exact decimal
|
|
8
|
+
* text ↔ `Money<C>`. SQLite has no exact decimal type, so text keeps every digit.
|
|
9
|
+
* - `moneyJson(name)` — a `text` column of `{ amount, currency }` JSON ↔ `Money`.
|
|
10
|
+
*
|
|
11
|
+
* SQLite integers are 64-bit, but most drivers return JavaScript numbers.
|
|
12
|
+
* Amounts up to 2^53 minor units are exact. A bigger stored amount throws on
|
|
13
|
+
* read instead of becoming a wrong value; to read those, switch the driver to
|
|
14
|
+
* big integers (libSQL `intMode: 'bigint'`, better-sqlite3 `safeIntegers()`).
|
|
15
|
+
*/
|
|
16
|
+
import { customType } from 'drizzle-orm/sqlite-core';
|
|
17
|
+
import { decimalFromDriver, decimalToDriver, jsonFromDriver, jsonToDriver, minorFromDriver, minorToDriver, } from '../internal/columns.js';
|
|
18
|
+
import { resolveColumn } from './config.js';
|
|
19
|
+
/** `integer` column ↔ `Money<C>` in one fixed currency. Writes a `bigint` past 2^53. */
|
|
20
|
+
export function moneyMinor(name, config) {
|
|
21
|
+
const { currency, scale } = resolveColumn(config, 'moneyMinor');
|
|
22
|
+
return customType({
|
|
23
|
+
dataType: () => 'integer',
|
|
24
|
+
toDriver: value => minorToDriver(value, currency, scale),
|
|
25
|
+
fromDriver: value => minorFromDriver(value, currency, scale),
|
|
26
|
+
})(name, config);
|
|
27
|
+
}
|
|
28
|
+
/** `text` column of exact decimal text ↔ `Money<C>` in one fixed currency. */
|
|
29
|
+
export function moneyDecimal(name, config) {
|
|
30
|
+
const { currency, scale } = resolveColumn(config, 'moneyDecimal');
|
|
31
|
+
return customType({
|
|
32
|
+
dataType: () => 'text',
|
|
33
|
+
toDriver: value => decimalToDriver(value, currency, scale),
|
|
34
|
+
fromDriver: value => decimalFromDriver(value, currency, scale),
|
|
35
|
+
})(name, config);
|
|
36
|
+
}
|
|
37
|
+
/** `text` column of `{ amount, currency }` JSON ↔ `Money` in any currency. */
|
|
38
|
+
export function moneyJson(name, config = {}) {
|
|
39
|
+
return customType({
|
|
40
|
+
dataType: () => 'text',
|
|
41
|
+
toDriver: jsonToDriver,
|
|
42
|
+
fromDriver: value => jsonFromDriver(value, config.currencies),
|
|
43
|
+
})(name, config);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/drizzle/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKrD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,eAAe,EACf,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,wFAAwF;AACxF,MAAM,UAAU,UAAU,CAAyB,IAAY,EAAE,MAA2B;IAC1F,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAChE,OAAO,UAAU,CAAkF;QACjG,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;QACzB,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;QACxD,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;KAC7D,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAyB,IAAY,EAAE,MAA6B;IAC9F,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClE,OAAO,UAAU,CAAwE;QACvF,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;QACtB,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;QAC1D,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC;KAC/D,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,MAAM,GAAoB,EAAE;IAClE,OAAO,UAAU,CAA+D;QAC9E,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;QACtB,QAAQ,EAAE,YAAY;QACtB,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC;KAC9D,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle columns for Postgres that read and write `Money`. Optional: needs
|
|
3
|
+
* `drizzle-orm` 1.x installed.
|
|
4
|
+
*
|
|
5
|
+
* - `moneyMinor(name, { currency })` — a `bigint` column of minor units for one
|
|
6
|
+
* fixed currency ↔ `Money<C>`. Best for sums in SQL.
|
|
7
|
+
* - `moneyDecimal(name, { currency, precision, scale })` — a `numeric` column ↔
|
|
8
|
+
* `Money<C>`. Readable in SQL tools; holds more decimals than the currency.
|
|
9
|
+
* - `moneyJson(name)` — a `jsonb` column of `{ amount, currency }` ↔ `Money`
|
|
10
|
+
* in any currency. For prices that vary by row.
|
|
11
|
+
*
|
|
12
|
+
* Every column declares a `:string`-style codec where Drizzle has one, so each
|
|
13
|
+
* driver (node-postgres, postgres.js, PGlite, Bun SQL) hands back text and no
|
|
14
|
+
* value ever passes through a float. Writing a `Money` in another currency, or
|
|
15
|
+
* with more decimals than the column holds, throws instead of storing a wrong
|
|
16
|
+
* value.
|
|
17
|
+
*/
|
|
18
|
+
import type { Currency, CurrencyLike } from './currency.js';
|
|
19
|
+
import type { Money } from './money.js';
|
|
20
|
+
export type MoneyMinorConfig<C extends string> = {
|
|
21
|
+
currency: CurrencyLike<C>;
|
|
22
|
+
/** Decimals the stored integer carries. Defaults to the currency's. */
|
|
23
|
+
scale?: number;
|
|
24
|
+
};
|
|
25
|
+
export type MoneyDecimalConfig<C extends string> = {
|
|
26
|
+
currency: CurrencyLike<C>;
|
|
27
|
+
/** Total digits, as in `numeric(precision, scale)`. Default 19. */
|
|
28
|
+
precision?: number;
|
|
29
|
+
/** Decimals stored. Defaults to the currency's. */
|
|
30
|
+
scale?: number;
|
|
31
|
+
};
|
|
32
|
+
export type MoneyJsonConfig = {
|
|
33
|
+
/** Custom currencies to resolve by code on read. */
|
|
34
|
+
currencies?: readonly Currency[];
|
|
35
|
+
};
|
|
36
|
+
/** Minor units as text, at the column's scale. Throws if the value needs rounding. */
|
|
37
|
+
export declare function moneyToMinorText(value: Money, currency: Currency, scale: number): string;
|
|
38
|
+
/** `bigint` column ↔ `Money<C>` in one fixed currency. */
|
|
39
|
+
export declare function moneyMinor<const C extends string>(name: string, config: MoneyMinorConfig<C>): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
40
|
+
dataType: 'custom';
|
|
41
|
+
data: Money<C>;
|
|
42
|
+
driverParam: string;
|
|
43
|
+
}>;
|
|
44
|
+
/** `numeric(precision, scale)` column ↔ `Money<C>` in one fixed currency. */
|
|
45
|
+
export declare function moneyDecimal<const C extends string>(name: string, config: MoneyDecimalConfig<C>): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
46
|
+
dataType: 'custom';
|
|
47
|
+
data: Money<C>;
|
|
48
|
+
driverParam: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** `jsonb` column of `{ amount, currency }` ↔ `Money` in any currency. */
|
|
51
|
+
export declare function moneyJson(name: string, config?: MoneyJsonConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
52
|
+
dataType: 'custom';
|
|
53
|
+
data: Money<string>;
|
|
54
|
+
driverParam: string;
|
|
55
|
+
}>;
|
|
56
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../src/drizzle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMxC,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,IAAI;IAC/C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1B,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI;IACjD,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC1B,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,oDAAoD;IACpD,UAAU,CAAC,EAAE,SAA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