From 61141dca96193a046fd8509a5f2fc84c1f4d4124 Mon Sep 17 00:00:00 2001 From: Stanislav Ignatenkov Date: Wed, 15 Jan 2025 13:25:30 +0000 Subject: [PATCH 1/6] CLL-303: Assert that open, close, high, low, value can safely represent 2 digits after the decimal point. Currently it is between -90071992547409.91 to 90071992547409.91 or ~9 quadrillion. --- src/model/data-validators.ts | 57 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/model/data-validators.ts b/src/model/data-validators.ts index 2babb62149..878333aa1b 100644 --- a/src/model/data-validators.ts +++ b/src/model/data-validators.ts @@ -2,7 +2,7 @@ import { assert } from '../helpers/assertions'; -import { isFulfilledData, SeriesDataItemTypeMap } from './data-consumer'; +import { isFulfilledData, OhlcData, SeriesDataItemTypeMap } from './data-consumer'; import { IHorzScaleBehavior } from './ihorz-scale-behavior'; import { CreatePriceLineOptions } from './price-line-options'; import { SeriesType } from './series-options'; @@ -67,31 +67,21 @@ function checkBarItem( if (!isFulfilledData(barItem)) { return; } - - assert( - typeof barItem.open === 'number', - `${type} series item data value of open must be a number, got=${typeof barItem.open}, value=${ - barItem.open - }` - ); - assert( - typeof barItem.high === 'number', - `${type} series item data value of high must be a number, got=${typeof barItem.high}, value=${ - barItem.high - }` - ); - assert( - typeof barItem.low === 'number', - `${type} series item data value of low must be a number, got=${typeof barItem.low}, value=${ - barItem.low - }` - ); - assert( - typeof barItem.close === 'number', - `${type} series item data value of close must be a number, got=${typeof barItem.close}, value=${ - barItem.close - }` - ); + (['open', 'high', 'low', 'close'] as (keyof OhlcData)[]).forEach((key: keyof OhlcData) => { + assert( + typeof barItem[key] === 'number', + `${type} series item data value of ${key} must be a number, got=${typeof barItem[key]}, value=${ + barItem[key] + }` + ); + + assert( + isSafeValue(barItem[key]), + `${type} series item data value of ${key} must be between ${VALUE_SAFE_RANGE}, got=${typeof barItem[key]}, value=${ + barItem[key] + }` + ); + }); } function checkLineItem( @@ -108,6 +98,13 @@ function checkLineItem( lineItem.value }` ); + + assert( + isSafeValue(lineItem.value), + `${type} series item data value must be between ${VALUE_SAFE_RANGE}, got=${typeof lineItem.value}, value=${ + lineItem.value + }` + ); } function checkCustomItem( @@ -117,3 +114,11 @@ function checkCustomItem( // Nothing to check yet... return; } + +const MIN_SAVE_VALUE = Number.MIN_SAFE_INTEGER / 100; +const MAX_SAVE_VALUE = Number.MAX_SAFE_INTEGER / 100; +const VALUE_SAFE_RANGE = `${MIN_SAVE_VALUE.toPrecision(16)} and ${MAX_SAVE_VALUE.toPrecision(16)}`; + +function isSafeValue(value: number): boolean { + return value >= MIN_SAVE_VALUE && value <= MAX_SAVE_VALUE; +} From d5b77c9f636188bc2c797c195f12f934b22cc2aa Mon Sep 17 00:00:00 2001 From: Stanislav Ignatenkov Date: Wed, 15 Jan 2025 14:54:51 +0000 Subject: [PATCH 2/6] CLL-303: Adjust size limit according to changes made --- .size-limit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.size-limit.js b/.size-limit.js index 84ec9439b0..a48bf92b16 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -79,7 +79,7 @@ export default [ path: 'dist/lightweight-charts.production.mjs', import: '{ createSeriesMarkers }', ignore: ['fancy-canvas'], - limit: '4.08 KB', + limit: '4.123 KB', brotli: true, }, { @@ -119,7 +119,7 @@ export default [ path: 'dist/lightweight-charts.production.mjs', import: '{ CandlestickSeries }', ignore: ['fancy-canvas'], - limit: '2.5 KB', + limit: '2.54 KB', brotli: true, }, { From 5da86d8b027bcde673dbb684745cc3539d15ca23 Mon Sep 17 00:00:00 2001 From: Stanislav Ignatenkov Date: Thu, 16 Jan 2025 14:40:23 +0000 Subject: [PATCH 3/6] CLL-303: fix bundle size increase problem --- .size-limit.js | 4 ++-- package.json | 2 +- src/model/data-validators.ts | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.size-limit.js b/.size-limit.js index a48bf92b16..d5bf281593 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -79,7 +79,7 @@ export default [ path: 'dist/lightweight-charts.production.mjs', import: '{ createSeriesMarkers }', ignore: ['fancy-canvas'], - limit: '4.123 KB', + limit: '4.5 KB', brotli: true, }, { @@ -119,7 +119,7 @@ export default [ path: 'dist/lightweight-charts.production.mjs', import: '{ CandlestickSeries }', ignore: ['fancy-canvas'], - limit: '2.54 KB', + limit: '3.00 KB', brotli: true, }, { diff --git a/package.json b/package.json index 9f97146910..7b89216296 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,7 @@ "build:release": "cross-env BUILD_TAG=release npm run build:prod", "prepare-release": "npm-run-all clean build:release && npm run prepare-package-json-for-release", "prepare-package-json-for-release": "node ./scripts/clean-package-json.js", - "size-limit": "size-limit", + "size-limit": "test ./dist/lightweight-charts.production.mjs -nt ./.git/HEAD || npm run build:prod; size-limit --highlight-less", "verify": "npm-run-all clean -p build:prod check-markdown-links -p lint check-dts-docs tsc-verify test size-limit -p type-tests", "test": "esno --import ./tests/unittests/setup.units.mjs --test './tests/unittests/**/*.spec.ts'", "type-tests": "tsc -b ./src/tsconfig.composite.json && tsc -p ./tests/type-checks/tsconfig.composite.json --noEmit", diff --git a/src/model/data-validators.ts b/src/model/data-validators.ts index 878333aa1b..538d508390 100644 --- a/src/model/data-validators.ts +++ b/src/model/data-validators.ts @@ -77,7 +77,7 @@ function checkBarItem( assert( isSafeValue(barItem[key]), - `${type} series item data value of ${key} must be between ${VALUE_SAFE_RANGE}, got=${typeof barItem[key]}, value=${ + `${type} series item data value of ${key} must be between ${MIN_SAVE_VALUE.toPrecision(16)} and ${MAX_SAVE_VALUE.toPrecision(16)}, got=${typeof barItem[key]}, value=${ barItem[key] }` ); @@ -101,7 +101,7 @@ function checkLineItem( assert( isSafeValue(lineItem.value), - `${type} series item data value must be between ${VALUE_SAFE_RANGE}, got=${typeof lineItem.value}, value=${ + `${type} series item data value must be between ${MIN_SAVE_VALUE.toPrecision(16)} and ${MAX_SAVE_VALUE.toPrecision(16)}, got=${typeof lineItem.value}, value=${ lineItem.value }` ); @@ -117,7 +117,6 @@ function checkCustomItem( const MIN_SAVE_VALUE = Number.MIN_SAFE_INTEGER / 100; const MAX_SAVE_VALUE = Number.MAX_SAFE_INTEGER / 100; -const VALUE_SAFE_RANGE = `${MIN_SAVE_VALUE.toPrecision(16)} and ${MAX_SAVE_VALUE.toPrecision(16)}`; function isSafeValue(value: number): boolean { return value >= MIN_SAVE_VALUE && value <= MAX_SAVE_VALUE; From 057816d443d5594cd576870b5e856a2f5274f8ad Mon Sep 17 00:00:00 2001 From: Stanislav Ignatenkov Date: Thu, 16 Jan 2025 14:52:29 +0000 Subject: [PATCH 4/6] CLL-303: revert size-limit change, use verify instead --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7b89216296..9f97146910 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,7 @@ "build:release": "cross-env BUILD_TAG=release npm run build:prod", "prepare-release": "npm-run-all clean build:release && npm run prepare-package-json-for-release", "prepare-package-json-for-release": "node ./scripts/clean-package-json.js", - "size-limit": "test ./dist/lightweight-charts.production.mjs -nt ./.git/HEAD || npm run build:prod; size-limit --highlight-less", + "size-limit": "size-limit", "verify": "npm-run-all clean -p build:prod check-markdown-links -p lint check-dts-docs tsc-verify test size-limit -p type-tests", "test": "esno --import ./tests/unittests/setup.units.mjs --test './tests/unittests/**/*.spec.ts'", "type-tests": "tsc -b ./src/tsconfig.composite.json && tsc -p ./tests/type-checks/tsconfig.composite.json --noEmit", From c38520e79d3e690cd0a2106016308b15e7f00575 Mon Sep 17 00:00:00 2001 From: signatenkov Date: Thu, 16 Jan 2025 14:55:16 +0000 Subject: [PATCH 5/6] Update src/model/data-validators.ts CLL-303: Fix typo SAVE/SAFE Co-authored-by: Edward Dewhurst --- src/model/data-validators.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model/data-validators.ts b/src/model/data-validators.ts index 538d508390..dc105ede33 100644 --- a/src/model/data-validators.ts +++ b/src/model/data-validators.ts @@ -115,8 +115,8 @@ function checkCustomItem( return; } -const MIN_SAVE_VALUE = Number.MIN_SAFE_INTEGER / 100; -const MAX_SAVE_VALUE = Number.MAX_SAFE_INTEGER / 100; +const MIN_SAFE_VALUE = Number.MIN_SAFE_INTEGER / 100; +const MAX_SAFE_VALUE = Number.MAX_SAFE_INTEGER / 100; function isSafeValue(value: number): boolean { return value >= MIN_SAVE_VALUE && value <= MAX_SAVE_VALUE; From e23d033034b8a3b9940d58bdeffc36e050d42718 Mon Sep 17 00:00:00 2001 From: Stanislav Ignatenkov Date: Thu, 16 Jan 2025 14:56:44 +0000 Subject: [PATCH 6/6] CLL-303: Fix typo SAVE/SAFE --- src/model/data-validators.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/model/data-validators.ts b/src/model/data-validators.ts index dc105ede33..8c026c2a02 100644 --- a/src/model/data-validators.ts +++ b/src/model/data-validators.ts @@ -77,7 +77,7 @@ function checkBarItem( assert( isSafeValue(barItem[key]), - `${type} series item data value of ${key} must be between ${MIN_SAVE_VALUE.toPrecision(16)} and ${MAX_SAVE_VALUE.toPrecision(16)}, got=${typeof barItem[key]}, value=${ + `${type} series item data value of ${key} must be between ${MIN_SAFE_VALUE.toPrecision(16)} and ${MAX_SAFE_VALUE.toPrecision(16)}, got=${typeof barItem[key]}, value=${ barItem[key] }` ); @@ -101,7 +101,7 @@ function checkLineItem( assert( isSafeValue(lineItem.value), - `${type} series item data value must be between ${MIN_SAVE_VALUE.toPrecision(16)} and ${MAX_SAVE_VALUE.toPrecision(16)}, got=${typeof lineItem.value}, value=${ + `${type} series item data value must be between ${MIN_SAFE_VALUE.toPrecision(16)} and ${MAX_SAFE_VALUE.toPrecision(16)}, got=${typeof lineItem.value}, value=${ lineItem.value }` ); @@ -119,5 +119,5 @@ const MIN_SAFE_VALUE = Number.MIN_SAFE_INTEGER / 100; const MAX_SAFE_VALUE = Number.MAX_SAFE_INTEGER / 100; function isSafeValue(value: number): boolean { - return value >= MIN_SAVE_VALUE && value <= MAX_SAVE_VALUE; + return value >= MIN_SAFE_VALUE && value <= MAX_SAFE_VALUE; }