diff --git a/src/lib/helpers/faker.ts b/src/lib/helpers/faker.ts index eff9452b95..b31eb3964b 100644 --- a/src/lib/helpers/faker.ts +++ b/src/lib/helpers/faker.ts @@ -2,6 +2,7 @@ import { faker } from '@faker-js/faker'; import type { Columns } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/store'; import { ID, type Models } from '@appwrite.io/console'; import { sdk } from '$lib/stores/sdk'; +import { isWithinSafeRange } from '$lib/helpers/numbers'; export async function generateColumns( project: Models.Project, @@ -167,19 +168,18 @@ function generateSingleValue(column: Columns): string | number | boolean | null case 'integer': { const intAttr = column as Models.ColumnInteger; - const min = intAttr.min ?? 0; - const max = intAttr.max ?? 10000; + const min = !isWithinSafeRange(intAttr.min) ? 0 : intAttr.min; + const max = !isWithinSafeRange(intAttr.max) ? 100 : intAttr.max; return faker.number.int({ min, max }); } - case 'float': { + case 'double': { const floatAttr = column as Models.ColumnFloat; - const min = floatAttr.min ?? 0; - const max = floatAttr.max ?? 1000000; - const precision = 2; - return parseFloat( - faker.number.float({ min, max, fractionDigits: precision }).toFixed(precision) - ); + const min = !isWithinSafeRange(floatAttr.min) ? 0 : floatAttr.min; + const max = !isWithinSafeRange(floatAttr.max) ? 100 : floatAttr.max; + const precision = 4; + + return faker.number.float({ min, max, fractionDigits: precision }); } case 'boolean': { diff --git a/src/lib/helpers/numbers.ts b/src/lib/helpers/numbers.ts index 073b831908..ce1c0a0bbc 100644 --- a/src/lib/helpers/numbers.ts +++ b/src/lib/helpers/numbers.ts @@ -32,3 +32,7 @@ export function formatCurrency(number: number, locale = 'en-US', currency = 'USD }); return formatter.format(number); } + +export function isWithinSafeRange(val: number) { + return Math.abs(val) < Number.MAX_SAFE_INTEGER; +}