dsqlbase 0.2.0 → 0.2.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.
- package/CHANGELOG.md +10 -0
- package/dist/schema/columns/numeric.d.ts +43 -2
- package/dist/schema/columns/numeric.d.ts.map +1 -1
- package/dist/schema/columns/numeric.js +42 -12
- package/dist/schema/columns/numeric.js.map +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# dsqlbase
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b19e326: `numeric()` takes a `mode`: `"number"` (the default, unchanged), `"string"` for the exact decimal text, or a decimal class such as decimal.js's `Decimal`, `Big` or `BigNumber`, whose instances reads return. Values past a double's precision now read back exactly. In `"string"` and class modes a write also accepts a `string` or `number`, and a string that is not a decimal number is refused; precision and scale are checked in every mode. Filters take the read type. New exported types: `NumericMode`, `NumericOptions`, `DecimalLike`, `DecimalConstructor`, `NumericValueType`, `NumericInputType`.
|
|
8
|
+
|
|
9
|
+
Docs: docs/guide/schema.md, docs/guide/querying.md, docs/internals/codec-boundary.md, docs/decisions/0016-numeric-modes.md
|
|
10
|
+
|
|
11
|
+
- @dsqlbase/core@0.2.1
|
|
12
|
+
|
|
3
13
|
## 0.2.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -1,10 +1,50 @@
|
|
|
1
1
|
import { ColumnConfig, ColumnDefinition } from "@dsqlbase/core";
|
|
2
|
+
/**
|
|
3
|
+
* An exact decimal value from a library such as decimal.js, big.js or bignumber.js. Its
|
|
4
|
+
* `toString()` must print the value in a form Postgres reads as `numeric` — plain or exponent
|
|
5
|
+
* notation.
|
|
6
|
+
*/
|
|
7
|
+
export type DecimalLike = {
|
|
8
|
+
toString(): string;
|
|
9
|
+
toJSON(): string;
|
|
10
|
+
};
|
|
11
|
+
/** A class that builds a {@link DecimalLike} from the database's decimal text. */
|
|
12
|
+
export type DecimalConstructor<T extends DecimalLike = DecimalLike> = new (value: string) => T;
|
|
13
|
+
/**
|
|
14
|
+
* How a `numeric` value is presented: a JavaScript `number` (may lose precision), the exact
|
|
15
|
+
* decimal text, or an instance of a decimal class.
|
|
16
|
+
*/
|
|
17
|
+
export type NumericMode = "number" | "string" | DecimalConstructor;
|
|
2
18
|
export type NumericOptions = {
|
|
3
19
|
/** Total significant digits, 1–1000. @default 18 */
|
|
4
20
|
precision?: number;
|
|
5
21
|
/** Digits after the decimal point, 0–`precision`. @default 6, or 0 when `precision` is given */
|
|
6
22
|
scale?: number;
|
|
23
|
+
/**
|
|
24
|
+
* How values are read:
|
|
25
|
+
* - `"number"`: a JavaScript `number`. Values past ~15 significant digits lose precision.
|
|
26
|
+
* - `"string"`: the exact decimal text, e.g. `"12.500000"`.
|
|
27
|
+
* - a decimal class (`Decimal` from decimal.js, `Big`, `BigNumber`, …): an instance of it,
|
|
28
|
+
* built from the exact decimal text.
|
|
29
|
+
*
|
|
30
|
+
* In `"string"` and class modes a write also accepts a `number` or a decimal string.
|
|
31
|
+
*
|
|
32
|
+
* @default "number"
|
|
33
|
+
*/
|
|
34
|
+
mode?: NumericMode;
|
|
7
35
|
};
|
|
36
|
+
/** What a read of a `numeric` column with options `O` returns. */
|
|
37
|
+
export type NumericValueType<O> = O extends {
|
|
38
|
+
mode: "string";
|
|
39
|
+
} ? string : O extends {
|
|
40
|
+
mode: DecimalConstructor<infer T>;
|
|
41
|
+
} ? T : number;
|
|
42
|
+
/** What a write to a `numeric` column with options `O` accepts. */
|
|
43
|
+
export type NumericInputType<O> = O extends {
|
|
44
|
+
mode: "string";
|
|
45
|
+
} ? string | number : O extends {
|
|
46
|
+
mode: DecimalConstructor<infer T>;
|
|
47
|
+
} ? T | string | number : number;
|
|
8
48
|
/**
|
|
9
49
|
* DSQL's own precision and scale for a `numeric` declared without them, stated explicitly so
|
|
10
50
|
* Postgres and PGlite store the same type.
|
|
@@ -20,9 +60,10 @@ export declare const DEFAULT_NUMERIC_SCALE = 6;
|
|
|
20
60
|
* it would refuse — throws a {@link ColumnValidationError} instead.
|
|
21
61
|
*
|
|
22
62
|
* @param name Column name in database
|
|
23
|
-
* @param options Precision and scale; `{ precision }` alone means a scale of 0, as `numeric(p)
|
|
63
|
+
* @param options Precision and scale; `{ precision }` alone means a scale of 0, as `numeric(p)`.
|
|
64
|
+
* `mode` picks how values are read; see {@link NumericOptions.mode}.
|
|
24
65
|
* @returns Serializable column definition for a numeric column.
|
|
25
66
|
*/
|
|
26
|
-
export declare function numeric<const TName extends string>(name: TName, options?:
|
|
67
|
+
export declare function numeric<const TName extends string, const TOptions extends NumericOptions = NumericOptions>(name: TName, options?: TOptions): ColumnDefinition<TName, ColumnConfig<NumericValueType<TOptions>, string, "number", NumericInputType<TOptions>>>;
|
|
27
68
|
export { numeric as decimal };
|
|
28
69
|
//# sourceMappingURL=numeric.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numeric.d.ts","sourceRoot":"","sources":["../../../src/schema/columns/numeric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGhE,MAAM,MAAM,cAAc,GAAG;IAC3B,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gGAAgG;IAChG,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"numeric.d.ts","sourceRoot":"","sources":["../../../src/schema/columns/numeric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGhE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,IAAI,MAAM,CAAC;IACnB,MA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CD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -15,12 +15,14 @@ export const DEFAULT_NUMERIC_SCALE = 6;
|
|
|
15
15
|
* it would refuse — throws a {@link ColumnValidationError} instead.
|
|
16
16
|
*
|
|
17
17
|
* @param name Column name in database
|
|
18
|
-
* @param options Precision and scale; `{ precision }` alone means a scale of 0, as `numeric(p)
|
|
18
|
+
* @param options Precision and scale; `{ precision }` alone means a scale of 0, as `numeric(p)`.
|
|
19
|
+
* `mode` picks how values are read; see {@link NumericOptions.mode}.
|
|
19
20
|
* @returns Serializable column definition for a numeric column.
|
|
20
21
|
*/
|
|
21
22
|
export function numeric(name, options = {}) {
|
|
22
23
|
const precision = options.precision ?? DEFAULT_NUMERIC_PRECISION;
|
|
23
24
|
const scale = options.scale ?? (options.precision === undefined ? DEFAULT_NUMERIC_SCALE : 0);
|
|
25
|
+
const mode = options.mode ?? "number";
|
|
24
26
|
if (!Number.isInteger(precision) || precision < 1 || precision > 1000) {
|
|
25
27
|
throw new Error(`Column "${name}": numeric precision must be an integer from 1 to 1000.`);
|
|
26
28
|
}
|
|
@@ -28,21 +30,42 @@ export function numeric(name, options = {}) {
|
|
|
28
30
|
throw new Error(`Column "${name}": numeric scale must be an integer from 0 to ${precision}.`);
|
|
29
31
|
}
|
|
30
32
|
const dataType = `numeric(${precision},${scale})`;
|
|
33
|
+
const decode = (text) => {
|
|
34
|
+
if (mode === "number")
|
|
35
|
+
return parseFloat(text);
|
|
36
|
+
if (mode === "string")
|
|
37
|
+
return text;
|
|
38
|
+
return new mode(text);
|
|
39
|
+
};
|
|
40
|
+
/** A write value in the column's read form: a decimal string or number converted, if needed. */
|
|
41
|
+
const toValue = (value) => {
|
|
42
|
+
if (mode === "number")
|
|
43
|
+
return value;
|
|
44
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
45
|
+
const text = String(value);
|
|
46
|
+
if (!isNumericText(text)) {
|
|
47
|
+
throw refusal(name, `${JSON.stringify(value)} is not a decimal number`);
|
|
48
|
+
}
|
|
49
|
+
return mode === "string" ? text : new mode(text);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
31
53
|
return new ColumnDefinition(name, {
|
|
32
54
|
dataType,
|
|
33
55
|
runtimeType: "number",
|
|
34
56
|
codec: {
|
|
35
|
-
encode: (value) => value
|
|
36
|
-
decode: (value) =>
|
|
57
|
+
encode: (value) => String(value),
|
|
58
|
+
decode: (value) => decode(value),
|
|
37
59
|
},
|
|
38
60
|
validator: {
|
|
39
|
-
write: (
|
|
40
|
-
const
|
|
61
|
+
write: (input) => {
|
|
62
|
+
const value = toValue(input);
|
|
63
|
+
const digits = decimalDigits(String(value));
|
|
41
64
|
if (digits && digits.fraction > scale) {
|
|
42
|
-
throw refusal(name, `${value} has ${digits.fraction} decimal places; ${dataType} would round it`);
|
|
65
|
+
throw refusal(name, `${String(value)} has ${digits.fraction} decimal places; ${dataType} would round it`);
|
|
43
66
|
}
|
|
44
67
|
if (digits && digits.integer > precision - scale) {
|
|
45
|
-
throw refusal(name, `${value} has ${digits.integer} integer digits; ${dataType} allows at most ${precision - scale}`);
|
|
68
|
+
throw refusal(name, `${String(value)} has ${digits.integer} integer digits; ${dataType} allows at most ${precision - scale}`);
|
|
46
69
|
}
|
|
47
70
|
return value;
|
|
48
71
|
},
|
|
@@ -51,14 +74,21 @@ export function numeric(name, options = {}) {
|
|
|
51
74
|
});
|
|
52
75
|
}
|
|
53
76
|
const refusal = (column, message) => new ColumnValidationError("invalid", column, "write", [{ message }]);
|
|
77
|
+
const DECIMAL_TEXT = /^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;
|
|
78
|
+
const SPECIAL_TEXT = /^([+-]?infinity|nan)$/i;
|
|
79
|
+
/** Whether Postgres reads `text` as a `numeric`: a decimal, exponent notation, `NaN`, `Infinity`. */
|
|
80
|
+
function isNumericText(text) {
|
|
81
|
+
return DECIMAL_TEXT.test(text) || SPECIAL_TEXT.test(text);
|
|
82
|
+
}
|
|
54
83
|
/**
|
|
55
|
-
* How many integer and decimal digits a
|
|
56
|
-
* `1e-7` has 7 decimals. `null` for a value with no digits to count (`NaN`,
|
|
84
|
+
* How many integer and decimal digits a decimal text is written with, exponent notation
|
|
85
|
+
* expanded — `1e-7` has 7 decimals. `null` for a value with no digits to count (`NaN`,
|
|
86
|
+
* `Infinity`).
|
|
57
87
|
*/
|
|
58
|
-
function decimalDigits(
|
|
59
|
-
if (!
|
|
88
|
+
function decimalDigits(text) {
|
|
89
|
+
if (!DECIMAL_TEXT.test(text))
|
|
60
90
|
return null;
|
|
61
|
-
const [mantissa = "0", exponentText = "0"] =
|
|
91
|
+
const [mantissa = "0", exponentText = "0"] = text.replace(/^[+-]/, "").toLowerCase().split("e");
|
|
62
92
|
const [whole = "", decimals = ""] = mantissa.split(".");
|
|
63
93
|
const exponent = Number(exponentText);
|
|
64
94
|
const digits = whole + decimals;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numeric.js","sourceRoot":"","sources":["../../../src/schema/columns/numeric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAStE;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAA6B,IAAW,EAAE,UAA0B,EAAE;IAC3F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,yBAAyB,CAAC;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7F,IAAI,CAAC,MAAM,CAAC,SAAS,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W,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM;QAC9C,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,CAAC","sourcesContent":["import { ColumnConfig, ColumnDefinition } from \"@dsqlbase/core\";\nimport { ColumnValidationError } from \"../utils/column-validation.js\";\n\nexport type NumericOptions = {\n /** Total significant digits, 1–1000. @default 18 */\n precision?: number;\n /** Digits after the decimal point, 0–`precision`. @default 6, or 0 when `precision` is given */\n scale?: number;\n};\n\n/**\n * DSQL's own precision and scale for a `numeric` declared without them, stated explicitly so\n * Postgres and PGlite store the same type.\n */\nexport const DEFAULT_NUMERIC_PRECISION = 18;\nexport const DEFAULT_NUMERIC_SCALE = 6;\n\n/**\n * Defines a `numeric(precision, scale)` (exact decimal) column in the database schema.\n *\n * Without options the column is `numeric(18,6)`, which is what DSQL makes of a bare `numeric`:\n * at most 12 integer digits and 6 decimals. A write that would not fit — more decimals than the\n * scale, which the database would round, or more integer digits than `precision - scale`, which\n * it would refuse — throws a {@link ColumnValidationError} instead.\n *\n * @param name Column name in database\n * @param options Precision and scale; `{ precision }` alone means a scale of 0, as `numeric(p)`\n * @returns Serializable column definition for a numeric column.\n */\nexport function numeric<const TName extends string>(name: TName, options: NumericOptions = {}) {\n const precision = options.precision ?? DEFAULT_NUMERIC_PRECISION;\n const scale = options.scale ?? (options.precision === undefined ? DEFAULT_NUMERIC_SCALE : 0);\n\n if (!Number.isInteger(precision) || precision < 1 || precision > 1000) {\n throw new Error(`Column \"${name}\": numeric precision must be an integer from 1 to 1000.`);\n }\n\n if (!Number.isInteger(scale) || scale < 0 || scale > precision) {\n throw new Error(`Column \"${name}\": numeric scale must be an integer from 0 to ${precision}.`);\n }\n\n const dataType = `numeric(${precision},${scale})`;\n\n return new ColumnDefinition<TName, ColumnConfig<number, string, \"number\">>(name, {\n dataType,\n runtimeType: \"number\",\n codec: {\n encode: (value) => value.toString(),\n decode: (value) => parseFloat(value),\n },\n validator: {\n write: (value) => {\n const digits = decimalDigits(value);\n\n if (digits && digits.fraction > scale) {\n throw refusal(\n name,\n `${value} has ${digits.fraction} decimal places; ${dataType} would round it`\n );\n }\n\n if (digits && digits.integer > precision - scale) {\n throw refusal(\n name,\n `${value} has ${digits.integer} integer digits; ${dataType} allows at most ${precision - scale}`\n );\n }\n\n return value;\n },\n read: (value) => value,\n },\n });\n}\n\nconst refusal = (column: string, message: string) =>\n new ColumnValidationError(\"invalid\", column, \"write\", [{ message }]);\n\n/**\n * How many integer and decimal digits a number is written with, exponent notation expanded —\n * `1e-7` has 7 decimals. `null` for a value with no digits to count (`NaN`, `Infinity`).\n */\nfunction decimalDigits(value: number): { integer: number; fraction: number } | null {\n if (!Number.isFinite(value)) return null;\n\n const [mantissa = \"0\", exponentText = \"0\"] = Math.abs(value).toString().split(\"e\");\n const [whole = \"\", decimals = \"\"] = mantissa.split(\".\");\n const exponent = Number(exponentText);\n const digits = whole + decimals;\n // Where the decimal point falls in `digits` once the exponent is applied.\n const point = whole.length + exponent;\n\n const integerPart = point > 0 ? digits.slice(0, point).padEnd(point, \"0\") : \"\";\n const fractionPart = point >= 0 ? digits.slice(point) : \"0\".repeat(-point) + digits;\n\n return {\n integer: integerPart.replace(/^0+/, \"\").length,\n fraction: fractionPart.replace(/0+$/, \"\").length,\n };\n}\n\nexport { numeric as decimal };\n"]}
|
|
1
|
+
{"version":3,"file":"numeric.js","sourceRoot":"","sources":["../../../src/schema/columns/numeric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAsDtE;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC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,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/E,MAAM,YAAY,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;IAEpF,OAAO;QACL,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM;QAC9C,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,CAAC","sourcesContent":["import { ColumnConfig, ColumnDefinition } from \"@dsqlbase/core\";\nimport { ColumnValidationError } from \"../utils/column-validation.js\";\n\n/**\n * An exact decimal value from a library such as decimal.js, big.js or bignumber.js. Its\n * `toString()` must print the value in a form Postgres reads as `numeric` — plain or exponent\n * notation.\n */\nexport type DecimalLike = {\n toString(): string;\n toJSON(): string;\n};\n\n/** A class that builds a {@link DecimalLike} from the database's decimal text. */\nexport type DecimalConstructor<T extends DecimalLike = DecimalLike> = new (value: string) => T;\n\n/**\n * How a `numeric` value is presented: a JavaScript `number` (may lose precision), the exact\n * decimal text, or an instance of a decimal class.\n */\nexport type NumericMode = \"number\" | \"string\" | DecimalConstructor;\n\nexport type NumericOptions = {\n /** Total significant digits, 1–1000. @default 18 */\n precision?: number;\n /** Digits after the decimal point, 0–`precision`. @default 6, or 0 when `precision` is given */\n scale?: number;\n /**\n * How values are read:\n * - `\"number\"`: a JavaScript `number`. Values past ~15 significant digits lose precision.\n * - `\"string\"`: the exact decimal text, e.g. `\"12.500000\"`.\n * - a decimal class (`Decimal` from decimal.js, `Big`, `BigNumber`, …): an instance of it,\n * built from the exact decimal text.\n *\n * In `\"string\"` and class modes a write also accepts a `number` or a decimal string.\n *\n * @default \"number\"\n */\n mode?: NumericMode;\n};\n\n/** What a read of a `numeric` column with options `O` returns. */\nexport type NumericValueType<O> = O extends { mode: \"string\" }\n ? string\n : O extends { mode: DecimalConstructor<infer T> }\n ? T\n : number;\n\n/** What a write to a `numeric` column with options `O` accepts. */\nexport type NumericInputType<O> = O extends { mode: \"string\" }\n ? string | number\n : O extends { mode: DecimalConstructor<infer T> }\n ? T | string | number\n : number;\n\n/**\n * DSQL's own precision and scale for a `numeric` declared without them, stated explicitly so\n * Postgres and PGlite store the same type.\n */\nexport const DEFAULT_NUMERIC_PRECISION = 18;\nexport const DEFAULT_NUMERIC_SCALE = 6;\n\n/**\n * Defines a `numeric(precision, scale)` (exact decimal) column in the database schema.\n *\n * Without options the column is `numeric(18,6)`, which is what DSQL makes of a bare `numeric`:\n * at most 12 integer digits and 6 decimals. A write that would not fit — more decimals than the\n * scale, which the database would round, or more integer digits than `precision - scale`, which\n * it would refuse — throws a {@link ColumnValidationError} instead.\n *\n * @param name Column name in database\n * @param options Precision and scale; `{ precision }` alone means a scale of 0, as `numeric(p)`.\n * `mode` picks how values are read; see {@link NumericOptions.mode}.\n * @returns Serializable column definition for a numeric column.\n */\nexport function numeric<\n const TName extends string,\n const TOptions extends NumericOptions = NumericOptions,\n>(name: TName, options: TOptions = {} as TOptions) {\n type TValue = NumericValueType<TOptions>;\n type TInput = NumericInputType<TOptions>;\n\n const precision = options.precision ?? DEFAULT_NUMERIC_PRECISION;\n const scale = options.scale ?? (options.precision === undefined ? DEFAULT_NUMERIC_SCALE : 0);\n const mode = options.mode ?? \"number\";\n\n if (!Number.isInteger(precision) || precision < 1 || precision > 1000) {\n throw new Error(`Column \"${name}\": numeric precision must be an integer from 1 to 1000.`);\n }\n\n if (!Number.isInteger(scale) || scale < 0 || scale > precision) {\n throw new Error(`Column \"${name}\": numeric scale must be an integer from 0 to ${precision}.`);\n }\n\n const dataType = `numeric(${precision},${scale})`;\n\n const decode = (text: string): unknown => {\n if (mode === \"number\") return parseFloat(text);\n if (mode === \"string\") return text;\n return new mode(text);\n };\n\n /** A write value in the column's read form: a decimal string or number converted, if needed. */\n const toValue = (value: unknown): unknown => {\n if (mode === \"number\") return value;\n\n if (typeof value === \"number\" || typeof value === \"string\") {\n const text = String(value);\n\n if (!isNumericText(text)) {\n throw refusal(name, `${JSON.stringify(value)} is not a decimal number`);\n }\n\n return mode === \"string\" ? text : new mode(text);\n }\n\n return value;\n };\n\n return new ColumnDefinition<TName, ColumnConfig<TValue, string, \"number\", TInput>>(name, {\n dataType,\n runtimeType: \"number\",\n codec: {\n encode: (value) => String(value),\n decode: (value) => decode(value) as TValue,\n },\n validator: {\n write: (input) => {\n const value = toValue(input);\n const digits = decimalDigits(String(value));\n\n if (digits && digits.fraction > scale) {\n throw refusal(\n name,\n `${String(value)} has ${digits.fraction} decimal places; ${dataType} would round it`\n );\n }\n\n if (digits && digits.integer > precision - scale) {\n throw refusal(\n name,\n `${String(value)} has ${digits.integer} integer digits; ${dataType} allows at most ${precision - scale}`\n );\n }\n\n return value as TValue;\n },\n read: (value) => value,\n },\n });\n}\n\nconst refusal = (column: string, message: string) =>\n new ColumnValidationError(\"invalid\", column, \"write\", [{ message }]);\n\nconst DECIMAL_TEXT = /^[+-]?(\\d+\\.?\\d*|\\.\\d+)(e[+-]?\\d+)?$/i;\nconst SPECIAL_TEXT = /^([+-]?infinity|nan)$/i;\n\n/** Whether Postgres reads `text` as a `numeric`: a decimal, exponent notation, `NaN`, `Infinity`. */\nfunction isNumericText(text: string): boolean {\n return DECIMAL_TEXT.test(text) || SPECIAL_TEXT.test(text);\n}\n\n/**\n * How many integer and decimal digits a decimal text is written with, exponent notation\n * expanded — `1e-7` has 7 decimals. `null` for a value with no digits to count (`NaN`,\n * `Infinity`).\n */\nfunction decimalDigits(text: string): { integer: number; fraction: number } | null {\n if (!DECIMAL_TEXT.test(text)) return null;\n\n const [mantissa = \"0\", exponentText = \"0\"] = text.replace(/^[+-]/, \"\").toLowerCase().split(\"e\");\n const [whole = \"\", decimals = \"\"] = mantissa.split(\".\");\n const exponent = Number(exponentText);\n const digits = whole + decimals;\n // Where the decimal point falls in `digits` once the exponent is applied.\n const point = whole.length + exponent;\n\n const integerPart = point > 0 ? digits.slice(0, point).padEnd(point, \"0\") : \"\";\n const fractionPart = point >= 0 ? digits.slice(point) : \"0\".repeat(-point) + digits;\n\n return {\n integer: integerPart.replace(/^0+/, \"\").length,\n fraction: fractionPart.replace(/0+$/, \"\").length,\n };\n}\n\nexport { numeric as decimal };\n"]}
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { interval, duration, type IntervalColumnOptions, type IntervalValueType,
|
|
|
12
12
|
export { json, jsonb, JsonColumnDefinition, type JsonSchemaFor, type JsonShape, type WithSchema, } from "./columns/json.js";
|
|
13
13
|
export { record } from "./columns/record.js";
|
|
14
14
|
export { decimal, numeric } from "./columns/numeric.js";
|
|
15
|
+
export type { DecimalConstructor, DecimalLike, NumericInputType, NumericMode, NumericOptions, NumericValueType, } from "./columns/numeric.js";
|
|
15
16
|
export { real, float4 } from "./columns/real.js";
|
|
16
17
|
export { smallint, int2 } from "./columns/smallint.js";
|
|
17
18
|
export { text } from "./columns/text.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI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AO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AASxD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI,EAA0B,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,SAAS,EACT,QAAQ,EACR,yBAAyB,GAG1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { array } from \"./columns/array.js\";\nexport { bigint, int8 } from \"./columns/bigint.js\";\nexport { boolean, bool } from \"./columns/boolean.js\";\nexport { bytea } from \"./columns/bytea.js\";\nexport { char } from \"./columns/char.js\";\nexport { date, type DateValueType, type DateColumnOptions } from \"./columns/date.js\";\nexport { double, float8 } from \"./columns/double.js\";\nexport {\n identity,\n IdentityColumnDefinition,\n type IdentityColumnOptions,\n type IdentityConfig,\n} from \"./columns/identity.js\";\nexport { guid, GuidColumnDefinition, type Guid } from \"./columns/guid.js\";\nexport { int, int4 } from \"./columns/int.js\";\nexport {\n interval,\n duration,\n type IntervalColumnOptions,\n type IntervalValueType,\n} from \"./columns/interval.js\";\nexport {\n json,\n jsonb,\n JsonColumnDefinition,\n type JsonSchemaFor,\n type JsonShape,\n type WithSchema,\n} from \"./columns/json.js\";\nexport { record } from \"./columns/record.js\";\nexport { decimal, numeric } from \"./columns/numeric.js\";\nexport type {\n DecimalConstructor,\n DecimalLike,\n NumericInputType,\n NumericMode,\n NumericOptions,\n NumericValueType,\n} from \"./columns/numeric.js\";\nexport { real, float4 } from \"./columns/real.js\";\nexport { smallint, int2 } from \"./columns/smallint.js\";\nexport { text } from \"./columns/text.js\";\nexport { time, type TimeColumnOptions } from \"./columns/time.js\";\nexport {\n timestamp,\n datetime,\n TimestampColumnDefinition,\n type DateTimeColumnOptions,\n type TimestampColumnConfig,\n} from \"./columns/timestamp.js\";\nexport { uuid, UUIDColumnDefinition } from \"./columns/uuid.js\";\nexport { varchar } from \"./columns/varchar.js\";\n\nexport { domain, $enum } from \"./domain.js\";\nexport { embedded } from \"./embedded.js\";\nexport { namespace, schema } from \"./namespace.js\";\nexport { sequence } from \"./sequence.js\";\nexport { table } from \"./table.js\";\nexport { tenantScope } from \"./tenant.js\";\nexport { union } from \"./union.js\";\n\nexport { relations, belongsTo, hasMany, hasOne } from \"./relations.js\";\n\nexport { type Duration } from \"./utils/duration.js\";\nexport { type GlobalId, type GlobalIdErrorCode } from \"./utils/global-id.js\";\nexport type { StandardSchemaV1 } from \"./utils/standard-schema.js\";\nexport { type DateTimeMode } from \"./utils/date.js\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsqlbase",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Query client and schema definition for distributed SQL databases",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"prepack": "node -e \"require('fs').copyFileSync('../../LICENSE','LICENSE')\""
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@dsqlbase/core": "^0.2.
|
|
71
|
+
"@dsqlbase/core": "^0.2.1"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@electric-sql/pglite": "^0.4.5",
|