realitydb 1.5.0 → 1.5.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/dist/index.js +34 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3569,7 +3569,16 @@ function inferColumnStrategy(column, tableForeignKeys, tableName) {
|
|
|
3569
3569
|
return { kind: "company_name" };
|
|
3570
3570
|
}
|
|
3571
3571
|
if (name.includes("amount") || name.includes("price") || name.includes("cost") || name.includes("total")) {
|
|
3572
|
-
|
|
3572
|
+
let min = 100;
|
|
3573
|
+
let max = 1e5;
|
|
3574
|
+
if (column.numericPrecision !== null && column.numericScale !== null) {
|
|
3575
|
+
const columnMax = Math.pow(10, column.numericPrecision - column.numericScale) - Math.pow(10, -column.numericScale);
|
|
3576
|
+
if (max > columnMax)
|
|
3577
|
+
max = columnMax;
|
|
3578
|
+
if (min > max)
|
|
3579
|
+
min = 0;
|
|
3580
|
+
}
|
|
3581
|
+
return { kind: "money", options: { min, max } };
|
|
3573
3582
|
}
|
|
3574
3583
|
if (name.includes("status")) {
|
|
3575
3584
|
return {
|
|
@@ -3612,7 +3621,11 @@ function inferColumnStrategy(column, tableForeignKeys, tableName) {
|
|
|
3612
3621
|
return { kind: "integer", options: { min: 0, max: 1e4 } };
|
|
3613
3622
|
}
|
|
3614
3623
|
if (dataType === "numeric" || dataType === "decimal" || dataType === "float4" || dataType === "float8" || dataType === "float") {
|
|
3615
|
-
|
|
3624
|
+
let max = 1e4;
|
|
3625
|
+
if (column.numericPrecision !== null && column.numericScale !== null) {
|
|
3626
|
+
max = Math.pow(10, column.numericPrecision - column.numericScale) - Math.pow(10, -column.numericScale);
|
|
3627
|
+
}
|
|
3628
|
+
return { kind: "float", options: { min: 0, max } };
|
|
3616
3629
|
}
|
|
3617
3630
|
if (dataType === "bool" || dataType === "boolean") {
|
|
3618
3631
|
return { kind: "boolean", options: { trueWeight: 0.5 } };
|
|
@@ -6501,7 +6514,11 @@ function detectColumn(column, tableForeignKeys, tableName) {
|
|
|
6501
6514
|
return { ...base, detectedKind: "integer", strategy: { kind: "integer", options: { min: 0, max: 1e4 } }, confidence: "medium", reason: "Integer data type (refine range with sample data)" };
|
|
6502
6515
|
}
|
|
6503
6516
|
if (["numeric", "decimal", "float4", "float8", "float", "real", "double precision"].includes(dataType)) {
|
|
6504
|
-
|
|
6517
|
+
let max = 1e4;
|
|
6518
|
+
if (column.numericPrecision !== null && column.numericScale !== null) {
|
|
6519
|
+
max = Math.pow(10, column.numericPrecision - column.numericScale) - Math.pow(10, -column.numericScale);
|
|
6520
|
+
}
|
|
6521
|
+
return { ...base, detectedKind: "float", strategy: { kind: "float", options: { min: 0, max } }, confidence: "medium", reason: "Float data type (refine range with sample data)" };
|
|
6505
6522
|
}
|
|
6506
6523
|
if ((dataType === "varchar" || dataType === "text" || dataType === "char") && column.maxLength !== null && column.maxLength <= 10) {
|
|
6507
6524
|
return { ...base, detectedKind: "text", strategy: { kind: "text", options: { mode: "short" } }, confidence: "low", reason: "Short text column" };
|
|
@@ -11131,6 +11148,8 @@ function normalizeSchema(raw) {
|
|
|
11131
11148
|
hasDefault: col.column_default !== null,
|
|
11132
11149
|
defaultValue: col.column_default,
|
|
11133
11150
|
maxLength: col.character_maximum_length,
|
|
11151
|
+
numericPrecision: col.numeric_precision ?? null,
|
|
11152
|
+
numericScale: col.numeric_scale ?? null,
|
|
11134
11153
|
isPrimaryKey: pk !== null && pk.column_name === col.column_name,
|
|
11135
11154
|
isUnique: pk !== null && pk.column_name === col.column_name || uniqueColumns.has(`${rawTable.table_name}.${col.column_name}`),
|
|
11136
11155
|
ordinalPosition: col.ordinal_position
|
|
@@ -11225,7 +11244,7 @@ async function getTables(pool, schemaName = "public") {
|
|
|
11225
11244
|
async function getColumns(pool, schemaName = "public") {
|
|
11226
11245
|
const result = await pool.query(`SELECT table_name, column_name, data_type, udt_name,
|
|
11227
11246
|
is_nullable, column_default, character_maximum_length,
|
|
11228
|
-
ordinal_position
|
|
11247
|
+
numeric_precision, numeric_scale, ordinal_position
|
|
11229
11248
|
FROM information_schema.columns
|
|
11230
11249
|
WHERE table_schema = $1
|
|
11231
11250
|
ORDER BY table_name, ordinal_position`, [schemaName]);
|
|
@@ -11477,7 +11496,7 @@ function parseColumnDef(def, tableName, ordinal) {
|
|
|
11477
11496
|
const name = colMatch[1];
|
|
11478
11497
|
const rawType = colMatch[2].trim();
|
|
11479
11498
|
const constraints = colMatch[3] ?? "";
|
|
11480
|
-
const { dataType, udtName, maxLength } = normalizeDataType(rawType);
|
|
11499
|
+
const { dataType, udtName, maxLength, numericPrecision, numericScale } = normalizeDataType(rawType);
|
|
11481
11500
|
const isNullable = !/NOT\s+NULL/i.test(constraints);
|
|
11482
11501
|
const isPrimaryKey = /PRIMARY\s+KEY/i.test(constraints);
|
|
11483
11502
|
const isUnique = /UNIQUE/i.test(constraints) || isPrimaryKey;
|
|
@@ -11504,6 +11523,8 @@ function parseColumnDef(def, tableName, ordinal) {
|
|
|
11504
11523
|
hasDefault,
|
|
11505
11524
|
defaultValue,
|
|
11506
11525
|
maxLength,
|
|
11526
|
+
numericPrecision,
|
|
11527
|
+
numericScale,
|
|
11507
11528
|
isPrimaryKey,
|
|
11508
11529
|
isUnique,
|
|
11509
11530
|
ordinalPosition: ordinal
|
|
@@ -11515,6 +11536,9 @@ function normalizeDataType(raw) {
|
|
|
11515
11536
|
const lower = raw.toLowerCase().trim();
|
|
11516
11537
|
const lengthMatch = lower.match(/(?:varchar|character varying|char|character)\s*\((\d+)\)/);
|
|
11517
11538
|
const maxLength = lengthMatch ? parseInt(lengthMatch[1], 10) : null;
|
|
11539
|
+
const numericMatch = lower.match(/(?:numeric|decimal)\s*\((\d+)\s*,\s*(\d+)\)/);
|
|
11540
|
+
const numericPrecision = numericMatch ? parseInt(numericMatch[1], 10) : null;
|
|
11541
|
+
const numericScale = numericMatch ? parseInt(numericMatch[2], 10) : null;
|
|
11518
11542
|
const typeMap = {
|
|
11519
11543
|
serial: { dataType: "integer", udtName: "int4" },
|
|
11520
11544
|
bigserial: { dataType: "bigint", udtName: "int8" },
|
|
@@ -11542,15 +11566,15 @@ function normalizeDataType(raw) {
|
|
|
11542
11566
|
const baseLower = lower.replace(/\s*\([^)]*\)/, "").trim();
|
|
11543
11567
|
const mapped = typeMap[baseLower];
|
|
11544
11568
|
if (mapped) {
|
|
11545
|
-
return { ...mapped, maxLength };
|
|
11569
|
+
return { ...mapped, maxLength, numericPrecision, numericScale };
|
|
11546
11570
|
}
|
|
11547
11571
|
if (baseLower.startsWith("varchar") || baseLower.startsWith("character varying")) {
|
|
11548
|
-
return { dataType: "character varying", udtName: "varchar", maxLength };
|
|
11572
|
+
return { dataType: "character varying", udtName: "varchar", maxLength, numericPrecision, numericScale };
|
|
11549
11573
|
}
|
|
11550
11574
|
if (baseLower.startsWith("char") || baseLower.startsWith("character")) {
|
|
11551
|
-
return { dataType: "character", udtName: "bpchar", maxLength };
|
|
11575
|
+
return { dataType: "character", udtName: "bpchar", maxLength, numericPrecision, numericScale };
|
|
11552
11576
|
}
|
|
11553
|
-
return { dataType: lower, udtName: lower, maxLength };
|
|
11577
|
+
return { dataType: lower, udtName: lower, maxLength, numericPrecision, numericScale };
|
|
11554
11578
|
}
|
|
11555
11579
|
function splitTableBody(body) {
|
|
11556
11580
|
const parts = [];
|
|
@@ -15253,7 +15277,7 @@ async function simulateWebhooksCommand(options) {
|
|
|
15253
15277
|
}
|
|
15254
15278
|
|
|
15255
15279
|
// src/cli.ts
|
|
15256
|
-
var VERSION16 = "1.5.
|
|
15280
|
+
var VERSION16 = "1.5.1";
|
|
15257
15281
|
function run(argv) {
|
|
15258
15282
|
const program2 = new Command();
|
|
15259
15283
|
program2.name("realitydb").description("RealityDB \u2014 Developer Reality Platform").version(VERSION16).option("--config <path>", "Path to config file").option("--ci", "CI mode: JSON output, no prompts, proper exit codes", false).option("--verbose", "Enable verbose output", false);
|